PostgreSQL is a free, open-source, secure, and robust relational database management system. It is specifically designed for high-performance, mission-critical applications. PostgreSQL supports SQL and JSON querying and is mainly used for many web and mobile and analytics applications. It is compatible with various platforms using all major languages and middleware. When writing this article, PostgreSQL 14 is the latest version. This version significantly improves the indexing and lookup system that benefits large databases.

This post will show you how to install and secure PostgreSQL on Oracle Linux 10.

Step 1 – Add PostgreSQL 18 Repository

By default, the latest version of PostgreSQL is not included in the Oracle Linux default repository. So you will need to add the third-party repository for PostgreSQL.

Install the PostgreSQL repository with the following command.

dnf update -y
dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

Once the repo is created, you can proceed to the next step.

Step 2 – Install PostgreSQL 18 on Oracle Linux 10

Now, update your repository using the following command:

dnf update -y

Next, install the latest version of PostgreSQL by running the following command:

dnf install postgresql18 postgresql18-server

Next, initialize the PostgreSQL database with the following command:

/usr/pgsql-18/bin/postgresql-18-setup initdb

Sample output:

Initializing database ... OK

Next, start the PostgreSQL service and enable it to start at system reboot with the following command:

systemctl start postgresql-18
systemctl enable postgresql-18

You can check the status of PostgreSQL with the following command:

systemctl status postgresql-18

You should get the following output:

ā— postgresql-18.service - PostgreSQL 18 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-18.service; disabled; preset: disabled)
Active: active (running) since Fri 2025-12-05 06:40:31 EST; 28s ago
Invocation: c30e51f4a3784766bb0e0acb92d05d16
Docs: https://www.postgresql.org/docs/18/static/
Process: 64277 ExecStartPre=/usr/pgsql-18/bin/postgresql-18-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Main PID: 64283 (postgres)
Tasks: 10 (limit: 24812)
Memory: 22M (peak: 22.5M)
CPU: 55ms
CGroup: /system.slice/postgresql-18.service
ā”œā”€64283 /usr/pgsql-18/bin/postgres -D /var/lib/pgsql/18/data/
ā”œā”€64284 "postgres: logger "
ā”œā”€64285 "postgres: io worker 0"
ā”œā”€64286 "postgres: io worker 2"
ā”œā”€64287 "postgres: io worker 1"
ā”œā”€64288 "postgres: checkpointer "
ā”œā”€64289 "postgres: background writer "
ā”œā”€64291 "postgres: walwriter "
ā”œā”€64292 "postgres: autovacuum launcher "
└─64293 "postgres: logical replication launcher "

By default, PostgreSQL listens on port 5432. You can check it with the following command:

ss -antpl | grep 5432

You will get the following output:

LISTEN 0      128        127.0.0.1:5432      0.0.0.0:*    users:(("postmaster",pid=2090,fd=7))
LISTEN 0      128            [::1]:5432         [::]:*    users:(("postmaster",pid=2090,fd=6))

Also Read

How to Secure PostgreSQL Server in Linux

Step 3 – Set a Password for the Postgres User

By default, the Postgres user’s password is not set, so it is recommended to set a password for security reasons.

To set a password, log in to PostgreSQL with the following command:

su - postgres

Next, set a secure password with the following command:

psql -c "alter user postgres with password 'securepassword'"

Next, exit from the PostgreSQL shell using the following command:

exit

Step 4 – Change PostgreSQL Authentication Method

By default, PostgreSQL is configured to use the peer method to connect to PostgreSQL locally, but this method is not recommended for the production environment. It is recommended to change the authentication method from peer to scram-sha-256.

You can change it by editing the PostgreSQL main configuration file:

nano /var/lib/pgsql/18/data/pg_hba.conf

Find the following line:

local   all             all                                     peer

And replace it with the next line:

local   all             all                                     scram-sha-256

Save and close the file, then restart the PostgreSQL service to apply the changes.

systemctl restart postgresql-18

Step 5 – Create a Database and User in PostgreSQL

First, log in to the PostgreSQL shell with the following command:

sudo -u postgres psql

You will get the following output:

psql (18.3)
Type "help" for help.

postgres=# 

Next, create a new PostgreSQL user named testuser using the following command:

CREATE USER testuser WITH CREATEDB CREATEROLE PASSWORD 'passoword';

To verify the PostgreSQL users, run:

\du

You will get the following output:

                                   List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
 testuser     | Create role, Create DB                                     | {}

To create a new PostgreSQL database named testdb, run:

CREATE DATABASE testdb OWNER testuser;

To verify the PostgreSQL databases, run:

\l

You will get the following result:

                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 testdb   | testuser    | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
(4 rows)

postgres=# 

Also Read

How to Backup and Restore a Database in PostgreSQL

Conclusion

This post explained how to install PostgreSQL on Oracle Linux 10. You can now start working with PostgreSQL to familiarize yourself with its features. For security reasons, installing the latest version of PostgreSQL in the production environment is always recommended. Give it a try on your dedicated server from Atlantic.Net!