Running different versions of PostgreSQL locally can be useful for both production and development purposes.There are several ways you could achieve this; by using Docker,by specifying the absolute path for the specific version you want to run,and by using pg_wrapper
to enable easier switching between different versions of PostgreSQL.
We are going to see how we can use the three methods to achieve this:
Using absolute paths in your terminal
First, we need to have the different versions of PostgreSQL installed. When you run a command like,
pg_config --version
, the PostgreSQL version that pops up is the first where the PATH is set first. To run the second version of PostgreSQL,we need to specify the absolute path of its installation. There is an easy way to determine where the installation of either of the PostgreSQL versions is, by finding it in the terminal.
In the terminal, we run
su -
to change user to root, then we find it by
sudo find / -name pg_config
.
The command return the pg_config
absolute paths in which there is a bin directory, for instance, /usr/local/pgsql/bin/pg_config/pg_config
.
When we run the absolute path above with the --version
parameter
like this /usr/local/pgsql/bin/pg_config/pg_config --version
, we get the version of the PostgreSQL in that path.
We can then set the path for our PostgreSQL version in this way: export PATH=$PATH:/usr/local/pgsql/bin
to make initdb postgres
to create postgres
cluster and later createdb sampledb
to create sampledb
in the postgres
cluster.
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)