()

Install PostgreSQL 13 on Linux Using YUM Command

 
In this blog, we will see How to download and install PostgreSQL 13 on Oracle Linux Server release 7.9.

You can get all required commands to install PostgreSQL on Linux from PostgreSQL documentation. Click here to download/follow the steps for PostgreSQL 13 on Linux.

Once click on the above link, the URL Page will be open. Select the below options to get Installation steps for OEL (Oracle Enterprise Linux).
Select version: 13
Select platform: Red Hat Enterprise, CentOS or Oracle Version 7
Select architecture: x86_64

Step 1. Download PostgreSql repository: Use OS command yum to download PostgreSQL repository, Please note yum command require Internet Connection on Server. You can use yum repolist command to verify PostgreSQL repository created in Server.

[root@test-machine02 ~]# yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

Dependencies Resolved

==============================================================================================================================================================================================
 Package                                       Arch                                Version                                 Repository                                                    Size
==============================================================================================================================================================================================
Installing:
 pgdg-redhat-repo                              noarch                              42.0-14                                 /pgdg-redhat-repo-latest.noarch                               11 k

Transaction Summary
==============================================================================================================================================================================================
Install  1 Package

Total size: 11 k
Installed size: 11 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : pgdg-redhat-repo-42.0-14.noarch                                                                                                                                            1/1
  Verifying  : pgdg-redhat-repo-42.0-14.noarch                                                                                                                                            1/1

Installed:
  pgdg-redhat-repo.noarch 0:42.0-14

Complete!

[root@test-machine02 yum.repos.d]# pwd
/etc/yum.repos.d

[root@test-machine02 yum.repos.d]# ls -l *pg*
-rw-r--r--. 1 root root 9738 Sep 24 18:14 pgdg-redhat-all.repo

[root@test-machine02 yum.repos.d]# yum repolist
repo id                                                             repo name                                                                                                           status
ol7_UEKR5/x86_64                                                    Latest Unbreakable Enterprise Kernel Release 5 for Oracle Linux 7Server (x86_64)                                       245
ol7_UEKR6/x86_64                                                    Latest Unbreakable Enterprise Kernel Release 6 for Oracle Linux 7Server (x86_64)                                       208
ol7_latest/x86_64                                                   Oracle Linux 7Server Latest (x86_64)                                                                                21,673
pgdg-common/7Server/x86_64                                          PostgreSQL common RPMs for RHEL/CentOS 7Server - x86_64                                                                386
pgdg10/7Server/x86_64                                               PostgreSQL 10 for RHEL/CentOS 7Server - x86_64                                                                         838
pgdg11/7Server/x86_64                                               PostgreSQL 11 for RHEL/CentOS 7Server - x86_64                                                                         877
pgdg12/7Server/x86_64                                               PostgreSQL 12 for RHEL/CentOS 7Server - x86_64                                                                         447
pgdg13/7Server/x86_64                                               PostgreSQL 13 for RHEL/CentOS 7Server - x86_64                                                                         170
pgdg95/7Server/x86_64                                               PostgreSQL 9.5 for RHEL/CentOS 7Server - x86_64                                                                        746
pgdg96/7Server/x86_64                                               PostgreSQL 9.6 for RHEL/CentOS 7Server - x86_64                                                                        805
repolist: 26,901


Step 2. Install PostgreSQL Server: Use OS command “yum” to install PostgreSQL Version 13.

[root@test-machine02 yum.repos.d]#  yum install -y postgresql13-server
Total                                                                                                                                                         1.8 MB/s | 7.1 MB  00:00:04
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
Importing GPG key 0x442DF0F8:
 Userid     : "PostgreSQL RPM Building Project <pgsqlrpms-hackers@pgfoundry.org>"
 Fingerprint: 68c9 e2b9 1a37 d136 fe74 d176 1f16 d2e1 442d f0f8
 Package    : pgdg-redhat-repo-42.0-14.noarch (@/pgdg-redhat-repo-latest.noarch)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : postgresql13-libs-13.1-1PGDG.rhel7.x86_64                                                                                                                                  1/3
  Installing : postgresql13-13.1-1PGDG.rhel7.x86_64                                                                                                                                       2/3
  Installing : postgresql13-server-13.1-1PGDG.rhel7.x86_64                                                                                                                                3/3
  Verifying  : postgresql13-libs-13.1-1PGDG.rhel7.x86_64                                                                                                                                  1/3
  Verifying  : postgresql13-13.1-1PGDG.rhel7.x86_64                                                                                                                                       2/3
  Verifying  : postgresql13-server-13.1-1PGDG.rhel7.x86_64                                                                                                                                3/3

Installed:
  postgresql13-server.x86_64 0:13.1-1PGDG.rhel7

Dependency Installed:
  postgresql13.x86_64 0:13.1-1PGDG.rhel7                                                      postgresql13-libs.x86_64 0:13.1-1PGDG.rhel7

Complete!


Step 3. Initialize DB and Enable Auto Restart: Follow the below steps.

[root@test-machine02 yum.repos.d]# /usr/pgsql-13/bin/postgresql-13-setup initdb
Initializing database ... OK


[root@test-machine02 yum.repos.d]# systemctl enable postgresql-13
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-13.service to /usr/lib/systemd/system/postgresql-13.service.

[root@test-machine02 yum.repos.d]# systemctl start postgresql-13

[root@test-machine02 13]# systemctl status postgresql-13
â postgresql-13.service - PostgreSQL 13 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-13.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2020-12-23 15:31:11 +03; 23min ago
     Docs: https://www.postgresql.org/docs/13/static/
  Process: 8402 ExecStartPre=/usr/pgsql-13/bin/postgresql-13-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 8408 (postmaster)


Step 4. Login to psql: Yum command will take care of all prerequisites and once all above steps are done you will notice OS user: postgres and Binary Location: /usr/pgsql-13/bin/ and Data Directory Location: /var/lib/pgsql/13/data/ created. Perform switch user to postgres and type psql (terminal-based front-end to PostgreSQL). When you enter psql you will be connected to psql terminal with database: postgres and user: postgres (Here postgres=# is DBName). Use command \conninfo to get connection details.

[root@test-machine02 yum.repos.d]# id postgres
uid=26(postgres) gid=26(postgres) groups=26(postgres)

Binary Location : 
--------------------------
[root@test-machine02 yum.repos.d]# cd /usr/pgsql-13/bin/
[root@test-machine02 bin]# ls -ltr
total 10884
-rwxr-xr-x. 1 root root    9622 Feb 11 04:42 postgresql-13-setup
-rwxr-xr-x. 1 root root    2175 Feb 11 04:42 postgresql-13-check-db-dir
-rwxr-xr-x. 1 root root   80264 Feb 11 04:42 vacuumdb
-rwxr-xr-x. 1 root root   75992 Feb 11 04:42 reindexdb
-rwxr-xr-x. 1 root root  644224 Feb 11 04:42 psql

Data Directory Location : 
--------------------------
[root@test-machine02 bin]# cd /var/lib/pgsql/13/data/
[root@test-machine02 data]# ls -ltr
total 64
-rw-------. 1 postgres postgres     3 Apr 26 15:07 PG_VERSION
drwx------. 2 postgres postgres     6 Apr 26 15:07 pg_twophase
drwx------. 2 postgres postgres     6 Apr 26 15:07 pg_tblspc
drwx------. 2 postgres postgres     6 Apr 26 15:07 pg_stat

[root@test-machine02 data]# su - postgres
Last login: Mon Apr 26 15:21:21 +03 2021 on pts/0
-bash-4.2$
-bash-4.2$ psql
psql (13.2)
Type "help" for help.
postgres=#

postgres=# \conninfo
You are connected to database "postgres" as user "postgres" via socket in "/var/run/postgresql" at port "5432".
postgres=#


Step 5. Verify PostgreSql Version: Use command SELECT version() or SHOW server_version.

postgres=# SELECT version();
                                                 version
---------------------------------------------------------------------------------------------------------
 PostgreSQL 13.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
(1 row)

postgres=# SHOW server_version;
 server_version
----------------
 13.2
(1 row)

postgres=#


This document is just for learning purpose and always validate in the LAB environment first before applying in the LIVE environment.


Hope so you like this article!
Please share your valuable feedback/comments/subscribe and follow us below and don’t forget to click on the bell icon to get the most recent update. Click here to understand more about our pursuit.

Related Articles


Loading

How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Jamsher Khan

Hello and welcome to DBsGuru,I’m Jamsher Khan working as Senior Oracle DBA based in KSA-Jeddah, I have working experience in Oracle DBA, SQL Server, MySql, PostgreSQL, Linux, Golden Gate, ODA.Thanks for the visits!Share Learn Grow!