When configuring and initializing the files, ensure the location is set to a different directory each time. Let's say I would like pgsql 13 and 15 installed. For the code block below, I have configured pgsql 13 to be installed in a directory called pgsql-13
.
git clone https://github.com/postgres/postgres.git
cd postgres
git checkout REL_13_STABLE
./configure --prefix=/usr/local/pgsql-13
make
sudo mkdir /usr/local/pgsql-13
sudo chown {your username} /usr/local/pgsql-13
make install
export PATH=/usr/local/pgsql-13/bin/:$PATH
export PGDATA=/usr/local/pgsql-13/bin/data
For pgsql 15 I would like to install it in a different directory called pgsql-15
.
git checkout REL_15_STABLE
./configure --prefix=/usr/local/pgsql-15
make
sudo mkdir /usr/local/pgsql-15
sudo chown {your username} /usr/local/pgsql-15
make install
export PATH=/usr/local/pgsql-15/bin/:$PATH
export PGDATA=/usr/local/pgsql-15/bin/data
The next step would be to initialize the database and change the port number for one of the databases (only if you want to be able to run both servers at the same time).
cd /usr/local/pgsql-13
bin/initdb {your database name}
vim {your database name}/postgresql.conf
After running vim
, navigate to around line 64 where you can see the port set #port = 5432
. Delete the hashtag #
and change the port number to something else such as 5431. Save and exit the editor to start the server and create the database using:
bin/pg_ctl -D {your database name} -l logfile start
bin/createdb --port=5431 {your database name}
bin/psql --port=5431 {your database name}
Likewise for the other version (port number will be 5432 by default if you did not manually change it):
cd /usr/local/pgsql-15
bin/initdb {your database name}
bin/pg_ctl -D {your database name} -l logfile start
bin/createdb --port=5432 {your database name}
bin/psql --port=5432 {your database name}
If you're not running both servers at the same time, you don't have to change the port numbers for either versions, but make sure the other server is stopped before running the other one using bin/pg_ctl -D {your database name} -l logfile stop
.