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

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

For e.g.

/usr/bin/pg_ctlcluster 9.5 main start



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


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


start | stop | restart | reload

Available versions and clusters, Serverstatus

~# 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


This will run initdb and create an new cluster

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


# 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.

9.6 main postgres
Claus-Theodor Riegg almost 4 years ago
This website uses short-lived cookies to improve usability.
Accept or learn more