65 cards
Posted over 5 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

With systemd you can start/stop the services via:

Copy
systemctl <action> postgresql@<version>-<cluster>.service

For e.g.

Copy
systemctl start postgresql@10-main.service

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 and a configurationof PostgreSQL stored in the correct location. Usually you find the datadir in /var/lib/postgresql/$VERSION/$CLUSTERNAME and the config in /etc/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 en_US.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

Connecting to clusters

The usual commands support the --cluster parameter which you can use to connect to the correct cluster. For e.g.

Copy
psql --cluster 11/main

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for unsupported versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2).

Owner of this card:

Avatar
Claus-Theodor Riegg
Last edit:
12 months ago
by Marius Schuller
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
This website uses short-lived cookies to improve usability.
Accept or learn more