40 cards
View
Posted about 2 years ago. Visible to the public.

controlling multiple PostgreSQL installations on Debian/Ubuntu

This applies only to distribusions based on Debian

If you have multiple Postgres Versions installed on a server and want to start/stop/restore/.. them separately you need to use pg_ctlcluster

Copy
Usage: /usr/bin/pg_ctlcluster <version> <cluster> <action>

For e.g.

Copy
/usr/bin/pg_ctlcluster 9.5 main start

Details

<version>

The Version of PostgreSQL to manage. Must be installed. ;)

<cluster>

The cluster to use. This is nothing more than a working data directory of PostgreSQL stored in the correct location. Usually you find this in /var/lib/postgresql/$VERSION/$CLUSTERNAME

<action>

start | stop | restart | reload

Available versions and clusters, Serverstatus

Copy
~# pg_lsclusters Ver Cluster Port Status Owner Data directory Log file 9.3 main 5433 down postgres /var/lib/postgresql/9.3/main /var/log/postgresql/postgresql-9.3-main.log 9.5 main 5432 down postgres /var/lib/postgresql/9.5/main /var/log/postgresql/postgresql-9.5-main.log 9.6 main 5434 down postgres /var/lib/postgresql/9.6/main /var/log/postgresql/postgresql-9.6-main.log

Creating or deleting clusters

create

This will run initdb and create an new cluster

Copy
# pg_createcluster --locale $LOCALE --start <version> <cluster> pg_createcluster --locale de_DE.UTF-8 --start 9.5 main

delete

Copy
# pg_dropcluster --stop <version> <cluster> pg_dropcluster --stop 9.5 main

Managing the default version and cluster with the ~/.postgresqlrc

You can place the file ~/.postgresqlrc in the home directory of the postgres user do decide which PostgreSQL version is used by default. Even the binaries like pg_dump are chosen depending on the version configured in this file.

Copy
# VERSION CLUSTERNAME DATABASE 9.6 main postgres

Owner of this card:

Avatar
Claus-Theodor Riegg
Last edit:
over 1 year ago
by Claus-Theodor Riegg
This website uses cookies to improve usability and analyze traffic.
Accept or learn more