I have 2 different versions of PostgreSQL installed on my system (Ubuntu Lucid):
- /var/lib/postgresql/8.4
- /var/lib/postgresql/9.0
By default, when I run a PostgreSQL command such as createdb or psql, the 9.0 version is used.
How do I configure my system to use the 8.4 version by default instead?
The various PostgreSQL command line tools will talk to the server listening on the default port (5432) by default.
You can determine which port each server is listening on by looking for the
port
variable in the/etc/postgresql/$VERSION/main/postgresql.conf
file for the relevant server.To get the command line tools to talk to the other server by default, you have two options:
First, you could switch the ports the two servers are listening on by editing the previously mentioned configuration files and then restarting both servers (you'll probably want to stop each one before starting either).
Alternatively, you can set the
PGPORT
environment variable to the port number of the desired default server. That should affect all applications using the PostgreSQL client library.To list the contents of each database cluster use
psql -l -p PORT_NUMBER
. To migrate data see section "24.4. Migration Between Releases" in the PostgreSQL documentation.Deleting old versions of PostgreSQL saves wear and tear on laptops & SSDs, through reduction of disk writes.
If you want to get rid of a version so the other one becomes default...
As James/Bryce correctly point out, the two versions will run on different ports.
However the command line utilities will also be run as one version or the other. For example
pg_dump --version
might give you an unexpected result.You can configure this in a file called
~/.postgresqlrc
First you need to know the cluster names, to find this, run the following command:
This will output the clusters available eg on my system I'm running 9.6 and 13:
Then create the file
~/.postgresqlrc
and put the following to control the default version used:Change
13
to the version you want to run as default, in the case of this question that will be8.4
or9.0
.