\n
$ sudo dnf update -y<\/p>\n<\/div><\/div>\n\n\n\n <\/figure>\n\n\n\nTo install PostgreSQL 16, which is the latest PostgreSQL version at the time of writing this guide, you need to add the PostgreSQL repository for RHEL 9 as shown.<\/p>\n\n\n\n
\n
$ sudo dnf install https:\/\/download.postgresql.org\/pub\/repos\/yum\/reporpms\/EL-9-x86_64\/pgdg-redhat-repo-latest.noarch.rpm -y<\/p>\n<\/div><\/div>\n\n\n\n <\/figure>\n\n\n\nNext, disable the built-in PostgreSQL module.<\/p>\n\n\n\n
\n
$ sudo dnf -qy module disable postgresql<\/p>\n<\/div><\/div>\n\n\n\n <\/figure>\n\n\n\nStep 2: Install PostgreSQL 16 on RHEL 9<\/h2>\n\n\n\n Once the PostgreSQL repository has been added, proceed and install PostgreSQL by running the following DNF command:<\/p>\n\n\n\n
\n
$ sudo dnf install postgresql16-server -y<\/p>\n<\/div><\/div>\n\n\n\n
The command installs the PostgreSQL server alongside other packages and dependencies. <\/p>\n\n\n\n <\/figure>\n\n\n\nOnce installed, be sure to initialize the database as shown.<\/p>\n\n\n\n
\n
$ sudo \/usr\/pgsql-16\/bin\/postgresql-16-setup initdb<\/p>\n<\/div><\/div>\n\n\n\n <\/figure>\n\n\n\nStep 3: How to Manage the PostgreSQL Service<\/h2>\n\n\n\n So far, we have managed to install PostgreSQL 16 on RHEL 9. In this section, we explore how to manage the service.<\/p>\n\n\n\n
To set the PostgreSQL service to auto-start every time upon booting, run the command:<\/p>\n\n\n\n
\n
$ sudo systemctl enable postgresql-16 <\/p>\n<\/div><\/div>\n\n\n\n
By default, PostgreSQL does not start automatically. To start it, run the command:<\/p>\n\n\n\n
\n
$ sudo systemctl start postgresql-16<\/p>\n<\/div><\/div>\n\n\n\n <\/figure>\n\n\n\nTo verify that the service is running, execute the command:<\/p>\n\n\n\n
\n
$ sudo systemctl status postgresql-16<\/p>\n<\/div><\/div>\n\n\n\n
The following output confirms that PostgreSQL is up and running.<\/p>\n\n\n\n <\/figure>\n\n\n\nTo restart the database server, run the command:<\/p>\n\n\n\n
\n
$ sudo systemctl restart postgresql-16<\/p>\n<\/div><\/div>\n\n\n\n
You can also reload the database server without stopping the service.<\/p>\n\n\n\n
\n
$ sudo systemctl reload postgresql-16<\/p>\n<\/div><\/div>\n\n\n\n
To check the version of PostgreSQL on your server, run the following command: <\/p>\n\n\n\n
\n
$ psql -V<\/p>\n<\/div><\/div>\n\n\n\n
The output confirms that we are running PostgreSQL 16.0. <\/p>\n\n\n\n <\/figure>\n\n\n\n