We currently have a PostgreSQL 11 Server which is about to be upgraded to version 15. There is a test box running Fedora 37. I'd like to try out several scripts on top of these different versions and for that purpose, so I tried to install both versions 11 and 15 and dnf did the job.
Where should I put postgresql.conf and pg_hba.conf to be able to specify the settings for different versions (instances). I anyway must define different listening port. I'm struggling to find instructions on internet.
Is this possible at all? Generelly, this is like running two DB Server instances on same box, but in my case, the versions are different.
Regards all!
This is very simple. If you use the PGDG packages from the PostgreSQL site, you can install the software for different PostgreSQL versions side by side. You have to create data directories for both instances using the initdb executable from the respective version. Configuration files like postgresql.conf and pg_hba.conf will be in the respective data directories. All you have to do is to configure both instances to use a different port, otherwise you cannot start both at the same time.
Thanks to several answers and comments to my question and also some further investigation, the setup finally works as desired.
Before taking any action, the situation was as following:
This is the procedure applied to get desired setup:
(as root): dnf remove postgres*
(as root): dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/F-37-x86_64/pgdg-fedora-repo-latest.noarch.rpm
(as root): dnf install postgresql11-server
And here, it came with error message: "...matches were filtered out by modular filtering for argument...". I'll cut it short, it got solved by following command (I don't know why exactly, but it worked):
(as root): dnf module reset postgresql*
This time, this worked:
(as root): dnf install postgresql11-server postgresql15-server
initdb -D <folder> but I ended up in a trouble in one of following steps. This is the way it worked on my server:(as root): /usr/bin/postgresql-11-setup initdb
(as root): /usr/bin/postgresql-15-setup initdb
postgresql.conf files, example with vim editor.(as root): vim /var/lib/pgsql/11/data/postgresql.conf
(as root): vim /var/lib/pgsql/15/data/postgresql.conf
If you're not sure where the files are, you can find them like this: find / -iname 'postgresql.conf'. I added "listen to all" and changed port. The port is mandatory to be changed, otherwise, second instance trying to address same port will fail to start.
listen_addresses = '*'
port = 54311
Make sure to remove comment prefix "#". For PG11, I used 54311 as shown, for PG15 I used 54315. Just make sure these are different and don't collide with other standard ports.
(as root): systemctl enable postgresql-11
(as root): systemctl start postgresql-11
(as root): systemctl status postgresql-11
(as root): systemctl enable postgresql-15
(as root): systemctl start postgresql-15
(as root): systemctl status postgresql-15
(as root): firewall-cmd --permanent --add-port=54311/tcp
(as root): firewall-cmd --permanent --add-port=54315/tcp
(as root): systemctl restart firewalld.service
(as root): su postgres
(as postgres): psql -p 54311
(psql):
(psql): alter user postgres with password '<pwd_for_postgresql>';
(psql): create user myusername with password '<pwd>';
(psql): create database educ_db owner=myusername;
You need to repeat this, but connect to the other port -p 54315.
Don't forget to allow acces in the pg_hba.conf file. Here is an example for version 11:
(as root): vim /var/lib/pgsql/11/data/pg_hba.conf
# My Use-Case Setup -------------------------------------------------
host educ_db myusername all md5
# -------------------------------------------------------------------
Don't forget to restart the PG server(s) or just reboot at all. Have fun!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With