Ubuntu – Multiple instances of Postgres after Ubuntu upgrade

postgresqlUbuntu

Just upgraded Ubuntu to latest version but now I have two instance of Postgres.

8.4 and 9.1

The problem is that I do not know on what port the second one is running ?

How can I detect on what port is running….

IF i run cristi@cristi-hp:/usr/share/postgresql-common$ sudo -u postgres psql
psql (8.4.8)
Type "help" for help.

how can I use psql for 9.1 ?

both appear to run:
cristi@cristi-hp:/usr/share/postgresql-common$ sudo /etc/init.d/postgresql start
[sudo] password for cristi:
* Starting PostgreSQL 8.4 database server [ OK ]
* Starting PostgreSQL 9.1 database server

Thanks…

Best Answer

Ubuntu being a Debian-based system has the ability to run multiple instances of Postgres as you are seeing. Generally unless configured otherwise the first instance started will have the default Postgres port and each subsequent instance will take the next higher port if it is available. These ports can be defined in the config files under /etc/postgresql/<version>/<cluster>/ so that they don't change should you need to but I'd actually need to. In fact a cursory look at the /etc/init.d/postgresql would also show you that you can set environment variables through /etc/postgresql/<version>/<cluster>/environment.

The package managers were even nice enough to include /usr/share/doc/postgresql-common/README.Debian.gz which has a section that quickly explains how the cluster management is handled including the pg_lsclusters command which will give you the Postgres version and port number along with other nice details about each configured cluster.

To answer question in comment regarding stopping an instance... You can edit the start.conf file under /etc/postgresql/<version>/<cluster>/ and change it from auto to disabled or manual. To quote the default start.conf file itself...

# Automatic startup configuration
# auto: automatically start/stop the cluster in the init script
# manual: do not start/stop in init scripts, but allow manual startup with
#         pg_ctlcluster
# disabled: do not allow manual startup with pg_ctlcluster (this can be easily
#           circumvented and is only meant to be a small protection for
#           accidents).