How to manage different versions of PostgreSQL servers on the same host?

Well, after some more effort, I get the answers myself:

  1. Ubuntu and Debian offer a pg_ctlcluster as well as a serial pg_xxxcluster commands to manage multiple versions/instances of PostgreSQL on the same host. To find out the version and cluster name, just do pg_lscluster, which outputs like 9.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 use pg_ctlcluster stop 9.4 main. BTW, to disable autostart 9.4, edit /etc/postgresql/9.4/main/start.conf
  2. psql need a --port, -p option to know which instance to connect, even for peer auth by Unix Socket, since all versions have the same unix_socket_directories. For example, psql -p 5433 dbname can connect by Unix Socket to version 9.5 running with port 5433, while default psql dbname connects to default port 5432, which belongs to my old 9.4 version.

That's it!

Tags:

Postgresql