Atlantic.Net Blog

How to Install and Use PostgreSQL 13 on Rocky Linux 8

Hitesh Jethva
by Atlantic.Net (345 posts) under Dedicated Server Hosting, Tutorials
0 Comments

PostgreSQL is a free and open-source, and is one of the most advanced database systems around the world. At the time of writing this article, the latest version of PostgreSQL is PostgreSQL 13. This version comes with significant improvements to the indexing and lookup system. It is very popular among professionals and developers who are trying to find their way in Relational Database Management Systems. It is used by many large companies including Apple, Reddit, Spotify, Skype, Instagram, and more.

In this post, we will show you how to install PostgreSQL 13 on Rocky Linux 8.

Prerequisites

  • A server running Rocky Linux 8 on the Atlantic.Net Cloud Platform
  • A root password is configured on your server

Step 1 – Create Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing Rocky Linux as the operating system with at least 2GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Once you are logged in to your server, run the following command to update your base system with the latest available packages.

dnf update -y

Step 2 – Add PostgreSQL 13 Repository

By default, the latest version of PostgreSQL 13 is not included in the RockyLinux 8 default repository. You will need to add the PostgreSQL official repository to your system.
You can add it using the following command:

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

Once the repository is added, you can verify it using the following command:

dnf -qy repolist

You should get the following output:

repo id                                              repo name
appstream                                            Rocky Linux 8 - AppStream
baseos                                               Rocky Linux 8 - BaseOS
extras                                               Rocky Linux 8 - Extras
pgdg-common                                          PostgreSQL common RPMs for RHEL/CentOS 8 - x86_64
pgdg10                                               PostgreSQL 10 for RHEL/CentOS 8 - x86_64
pgdg11                                               PostgreSQL 11 for RHEL/CentOS 8 - x86_64
pgdg12                                               PostgreSQL 12 for RHEL/CentOS 8 - x86_64
pgdg13                                               PostgreSQL 13 for RHEL/CentOS 8 - x86_64
pgdg96                                               PostgreSQL 9.6 for RHEL/CentOS 8 - x86_64

In order to use the PostgreSQL repository, you will need to disable the PostgreSQL default repository. You can disable it using the following command:

dnf module -qy disable postgresql

Step 3 – Install PostgreSQL 13

You can now install the latest version of PostgreSQL 13 using the following command:

dnf install postgresql13-server -y

Once PostgreSQL is installed, initialize the PostgreSQL database with the following command:

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

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

systemctl start postgresql-13
systemctl enable postgresql-13

Step 4 – Create Admin User for PostgreSQL

It is recommended to create a separate user for PostgreSQL.

To do so, log in to PostgreSQL with the following command:

su - postgres
psql

Next, create an admin user with the desired role and set a password with the following command:

CREATE USER hitesh WITH CREATEDB CREATEROLE PASSWORD 'userpassword';

You can now check the user with the following command:

\du

Sample output:

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

Step 5 – Create Database and Table in PostgreSQL

In this section, we will show you how to create a database and table in PostgreSQL.

First, log in to PostgreSQL with the following command:

su - postgres
psql

Next, create a database with the following command:

CREATE DATABASE hiteshdb OWNER hitesh;

Next, verify your database with the following command:

\l

You should see all databases in the following output:

                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 hiteshdb  | hitesh   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 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

Next, create a table named students with the following command:

CREATE TABLE students (
   id INT PRIMARY KEY     NOT NULL,
   name           TEXT    NOT NULL,
   age            INT     NOT NULL,
   address        CHAR(50),
   salary         REAL
);

You can verify the table with the following command:

\d

Sample output:

          List of relations
 Schema |   Name   | Type  |  Owner   
--------+----------+-------+----------
 public | students | table | postgres
(1 row)

To display your table properties, run the following command:

\d students

Sample output:

                 Table "public.students"
 Column  |     Type      | Collation | Nullable | Default 
---------+---------------+-----------+----------+---------
 id      | integer       |           | not null | 
 name    | text          |           | not null | 
 age     | integer       |           | not null | 
 address | character(50) |           |          | 
 salary  | real          |           |          | 
Indexes:
    "students_pkey" PRIMARY KEY, btree (id)

Conclusion

In the above guide, we explained how to install PostgreSQL 13 on RockyLinux 8. We also explained how to create a database and table in PostgreSQL. You should now be able to use the PostgreSQL database with your applications. Give it a try on dedicated hosting from Atlantic.Net today!

Get A Free To Use Cloud VPS

Free Tier Includes:
G3.2GB Cloud VPS Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Us Now! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Recent Posts

How to Install Python 3.10 on Rocky Linux 8
How to Install TaskBoard on Rocky Linux 8
How to Set Up Pritunl VPN Server on Rocky Linux 8
How to Install Teampass Password Manager on Rocky Linux 8
How to Install and Configure RabbitMQ Server on Rocky Linux 8

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G3.2GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2323 Bryan Street,

Dallas, Texas 75201

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources