This post will show you how to install PostgreSQL 16 on RHEL 9 system step by step.
PostgreSQL is an open-source, multi-platform, robust and highly extensible database server based on the SQL language. It provides the features like data integrity, build applications and create fault-tolerant environments.
Prerequisites
- Minimal Installed RHEL 9
- At least 2GB RAM and 2 CPU
- Sudo User with admin rights
- Red Hat Subscription or locally configured Repository
- Stable Internet Connectivity (In case of Red Hat subscription)
Without any further delay, let’s jump into PostgreSQL 16 installation steps.
1) Enable PostgreSQL 16 Package Repository
PostgreSQL 15 is not available in the default package repositories of RHEL 9. So, let’s first enable its DNF/yum package repository using following dnf command.
$ sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm -y
2) Install PostgreSQL 16 on RHEL 9
In step 1, we have already configured PostgreSQL 16 package repository, so to install it, run the beneath dnf command.
$ sudo dnf install postgresql15-server -y
Once postgresql and it’s dependencies are installed, verify its version using following psql command.
$ psql -V psql (PostgreSQL) 16.1 $
Above command’s output shows PostgreSQL 16.1 is installed on the system. Now, let initialize its database in the next step.
3) Initialize PostgreSQL 16 Database (initdb)
To initialize PostgreSQL 16 initdb database, run
$ sudo /usr/pgsql-16/bin/postgresql-16-setup initdb
Output,
4) Start PostgreSQL 16 Service
Run the following systemctl commands to start and enable postgresql 16 service.
$ sudo systemctl start postgresql-16 $ sudo systemctl enable postgresql-16
To verify its service status, run
$ sudo systemctl status postgresql-16
Above output shows that postgresql service is up and running.
5) Securing PostgreSQL 16 Database
By default, postgresql database is not secure, one can easily switch to postgres user without any password and start using psql as shown below:
Now, to secure database, set password to postgres user using passwd command.
$ sudo passwd postgres $ su - postgres $ psql -c "ALTER USER postgres WITH PASSWORD 'xxxxxxxxxxx';"
Output of above commands,
Now. Let’s try to switch to postgres user and connect to database. This time it should prompt you to enter password first,
$ su - postgres Password: $ psql
Perfect, above output confirms that postgres user and database is secure now.
That’s all from this post, please do post your queries and feedback on below comments section.
Also Read: How to Install PostgreSQL On Ubuntu 22.04 Step-by-Step