How to manage different versions of PostgreSQL servers on the same host?
Well, after some more effort, I get the answers myself:
- Ubuntu and Debian offer a
pg_ctlcluster
as well as a serialpg_xxxcluster
commands to manage multiple versions/instances of PostgreSQL on the same host. To find out the version and cluster name, just dopg_lscluster
, which outputs like9.4 main 5432 online postgres /var/lib/postgresql/9.4/main /var/log/postgresql/postgresql-9.4-main.log 9.5 main 5433 online postgres /var/lib/postgresql/9.5/main /var/log/postgresql/postgresql-9.5-main.log
For example, to stop 9.4, you usepg_ctlcluster stop 9.4 main
. BTW, to disable autostart 9.4,edit /etc/postgresql/9.4/main/start.conf
psql
need a--port, -p
option to know which instance to connect, even for peer auth by Unix Socket, since all versions have the sameunix_socket_directories
. For example,psql -p 5433 dbname
can connect by Unix Socket to version 9.5 running with port 5433, while defaultpsql dbname
connects to default port 5432, which belongs to my old 9.4 version.
That's it!