I have PostgreSQL 8.4 and 9.0 running on the same server (Ubuntu Lucid).

I installed them both via apt-get (8.4 with the default package sources, and 9.0 after adding the ppa from https://launchpad.net/~pitti/+archive/postgresql).

When I run a command like "createdb" from the command line or start up the "psql" shell, PostgreSQL version 8.4 is used by default on my system.

So, how do I force these commands to use PostgreSQL 9.0 instead of 8.4?


Assuming Ubuntu does the same thing as Debian, then your two PostGreSQL instances will be running on different ports.

You can easily check the config files to see which version is on which port:

$ grep -H '^port' /etc/postgresql/*/main/postgresql.conf
/etc/postgresql/8.4/main/postgresql.conf:port = 5432
/etc/postgresql/8.3/main/postgresql.conf:port = 5433

Most of the PostGreSQL commands take the "-p ####" or "--port=####" option, so you can use that to select the version you want.


Use --cluster option e.g. (assuming that both clusters are named as default main):

psql --cluster 8.4/main
psql --cluster 9.0/main

Generic schemas are:

--cluster version/name      # for local connections
--cluster version/host:port # for TCP/IP connections

To list all installed clusters (name, port, status, data directory etc.) use pg_lsclusters command.

Check man pg_wrapper for more information.

  • This is brilliant how come this is not in the psql doc? – MarHoff Jan 23 '17 at 9:08
  • 1
    @MarHoff: The pg_wrapper is Debian's extension. Essentially, it wraps psql (that is, psql is symbolic link to pg_wrapper script) command with several new options to facilitate handling of multiple clusters. – Grzegorz Szpetkowski Jan 23 '17 at 9:22
  • Thank you! I use pg_ctlcluster 11 main restart to restart specific psql – Prabowo Murti Oct 8 '20 at 7:30

You can use dpkg -L <packagename> to see what files a particular package owns. Run it with the postgresql 9 package and see where the createdb command for that version was stored.

Most postgresql commands would work cross-version with appropriate selection of the database by port or path, but this of course does not apply to start scripts and creation commands.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.