pgbouncer
Node.js wrapper for pgbouncer. All methods are asynchronous, using Q promises.
Basic usage
PgBouncer = require 'pgbouncer' # create a new PgBouncer instance # pointing to the location of the pgbouncer.ini file pgb = configFile: '/etc/pgbouncer.ini'
Reading the INI file
pgbread then # [pgbouncer] section # config.pgbouncer.listen_port: 5434 # config.pgbouncer.listen_addr: '127.0.0.1' # config.pgbouncer.auth_type: 'any' # [databases] section # config.databases.mydb1: 'postgresql://localhost/db1' # config.databases.mydb2: 'postgresql://localhost/db2'
Updating the INI file
config = pgbouncer: listen_port: 5434 listen_addr: '127.0.0.1' auth_type: 'any' databases: mydb1: 'postgresql://localhost/db1' mydb2: 'postgresql://localhost/db2' pgbwriteconfig then -> consolelog'done'
Updating the database list only
If you don't need to change the [pgbouncer]
section, you can also update the [databases]
list only.
databases: mydb1: 'postgresql://localhost/db1' mydb2: 'postgresql://localhost/db2' pgbwriteDatabasesdatabases then -> consolelog'done'
Reloading the config
After updating the INI file, you need to manually trigger a reload
command to update the live routing.
pbgreload then -> consolelog'done'
Getting the current routing status
You can get the current routing status from the pgbouncer show databases
command:
pbgstatus then # databases[0].name # databases[0].host # databases[0].port # databases[0].database # databases[0].force_user # databases[0].pool_size
Executing other commands
You can also execute any valid pgbouncer command:
pgbexecute'show users' then consolelogresultsrows
Please check pgbouncer documentation for a list of commands.