skip to Main Content

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!

2

Answers


  1. Chosen as BEST ANSWER

    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:

    • Operating System: Fedora 37 Server (command line only)
    • PostgreSQL Server 14 installed as "available version" out of Fedora 37 Repos

    This is the procedure applied to get desired setup:

    1. Remove PostgreSQL Server 14
    (as root): dnf remove postgres*
    
    1. Add latest PG repository for Fedora 37
    (as root): dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/F-37-x86_64/pgdg-fedora-repo-latest.noarch.rpm
    
    1. Install PostgreSQL 11 and 15
    (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 
    
    1. Initialize the Databases In this step, I tried recommended option with 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
    
    1. Amend configuration in your 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.

    1. Enable and start the servers
    (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
    
    1. Let's not forget the firewall
    (as root): firewall-cmd --permanent --add-port=54311/tcp
    (as root): firewall-cmd --permanent --add-port=54315/tcp
    (as root): systemctl restart firewalld.service
    
    1. Setup user(s) and database(s)... The servers should be up-and-running now. But you have no users and created database. This is not really the part of setting up the server, but I'll give examples for newbies.
    (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!


  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search