Installing PostgreSQL 17 on Rocky/Alma/RHEL Linux 10
Installing PostgreSQL 17 on Rocky/Alma/RHEL Linux 10
We will be installing PostgreSQL 17 on Rocky Linux 10 in this tutorial. It should also work on Alma Linux 10 and Red Hat Enterprise Linux 10.
Install PostgreSQL
The first task is to install PostgreSQL from the official repos. This will ensure you get updates pretty much instantly as they are released.
SSH into your server and run the commands on this page:
https://www.postgresql.org/download/linux/redhat/
On the page you can select which version of PostgreSQL you want to install along with architecture (x86_64 is for CPUs made by Intel and AMD and aarch64 is for CPUs made by Apple and other ARM based systems). I highly recommend installing the latest version of PostgreSQL available unless you have a very good reason to install an older version.
Once you have run the commands over SSH shown below the menus you'll have PostgreSQL installed.
Allow PostgreSQL Through the Firewall
We will use firewall-cmd to open a port for PostgreSQL so it can be accessed by remote machines. The default port for PostgreSQL is 5432 so we will use that.
sudo firewall-cmd --add-port=5432/tcp --permanent
sudo firewall-cmd --reload
sudo firewall-cmd --list-all
Configure PostgreSQL
Now we have a base install we need to configure PostgreSQL to allow outside connections.
All these files need to be edited via either sudo or root.
Open /var/lib/pgsql/17/data/postgresql.conf.
Change the line:
listen_addresses = 'localhost'
to:
listen_addresses = '*'
This will allow PostgreSQL to listen on any address. If you want PostgreSQL to
only listen on a specific IP address then add it here instead of the *.
Once that is done open:
/var/lib/pgsql/17/data/pg_hba.conf
and you'll see a bunch of comments explaining the config file.
Basically this file sets which IP addresses can connect to PostgreSQL and the authentication method used.
You need to add a line saying which IP address can connect like this:
host all all 127.0.0.1/32 trust
host all all 10.0.0.0/8 trust
host all all 192.168.0.0/24 trust
these three lines will mean that only the same machine or machines on the same local network can access access the PostgreSQL server and all of them are trusted so don't need to authenticate.
If you want to allow machines that are no on the local network you'll need to add their IP address to the file and set the correct authentication method.
Change postgres user password
You need to change the postgres user password so you can login to the server:
sudo -u postgres psql
\password postgres
enter password
enter password again
\q
Make sure you set a strong password as the postgres user is the equivalent
of the root user in Linux and thus can do anything.
Conclusion
You should now have PostgreSQL installed and ready to access.
You should install psql on all client machines you want to access the PostgreSQL server so that you can interact with the database remotely.