Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get PGBouncer auto start on reboot on Linux?

On Ubuntu 12.04 (precise) in a Windows Azure VM I have postgres and pgbouncer running on the same machine. Everything is setup and works however when the VM is rebooted pgbouncer doesn't automatically startup.

  1. How do I make it so that it starts on reboot?
  2. Does Postgres need to be running before PGBouncer? If so how is this accomplished? I'm assuming PGBouncer would still run just any sql connections wouldn't connect if Postgres wasn't running or is this assumption wrong?

The commands I run to get it started are the below. Note: I need to be 'postgres' user in order to start the service otherwise it fails. Also detailed answer preferrend. Linux isn't my normal OS.

sudo su postgres
pgbouncer -d -v /etc/pgbouncer/pgbouncer.ini

If helpful, this is how pgbouncer was installed:

sudo apt-get install postgresql-9.3 pgbouncer

Note: I can interact with pgbouncer service (force-reload, status, start, stop) however only after I first run the pgbouncer -d -v /etc/pgbouncer/pgbouncer.ini command.

like image 823
thames Avatar asked Nov 27 '13 17:11

thames


People also ask

What is PG bouncer?

PgBouncer is a light-weight connection pool manager for Greenplum and PostgreSQL. PgBouncer maintains a pool for connections for each database and user combination. PgBouncer either creates a new database connection for a client or reuses an existing connection for the same user and database.

What is pool size in Pgbouncer?

The defaults are set at 100 and 20, respectively. PgBouncer has a formula for determining the pool size and the number of clients that you should set, but the default is usually more than enough.


1 Answers

Edit /etc/default/pgbouncer and set

START=1

Then start pgbouncer using the init script:

/etc/init.d/pgbouncer start

The init script will automatically start pgbouncer on boot. But you need to make that START=1 setting.

like image 59
Peter Eisentraut Avatar answered Sep 28 '22 19:09

Peter Eisentraut