Sunday, 20 June 2021

Installation and setting up Postgres 13 on RHEL


Setting up the PostgreSQL RDBMS in Red-Hat Linux is pretty easy.  Following article describes the installation and initial setup for a PostgreSQL database.

Official documentation : https://www.postgresql.org/download/linux/redhat/

To add the EPEL8 repository to RHEL 8 / CentOS 8


root@localhost ~]# yum install virtualbox-guest-utils
Error: There are no enabled repositories in "/etc/yum.repos.d", "/etc/yum/repos.d", "/etc/distro.repos.d".


[root@localhost ~]# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

epel-release-latest-8.noarch.rpm                                        14 kB/s |  22 kB     00:01
Dependencies resolved.
=======================================================================================================
 Package                   Architecture        Version                 Repository                 Size
=======================================================================================================
Installing:
 epel-release              noarch              8-10.el8                @commandline               22 k
Transaction Summary
=======================================================================================================
Install  1 Package
Total size: 22 k
Installed size: 32 k
Is this ok [y/N]: y

Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                               1/1
  Installing       : epel-release-8-10.el8.noarch                                                  1/1
  Running scriptlet: epel-release-8-10.el8.noarch                                                  1/1
  Verifying        : epel-release-8-10.el8.noarch                                                  1/1
Installed products updated.
Installed:
  epel-release-8-10.el8.noarch

Complete!


[root@localhost ~]#  rpm -ql epel-release

/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
/etc/yum.repos.d/epel-modular.repo
/etc/yum.repos.d/epel-playground.repo
/etc/yum.repos.d/epel-testing-modular.repo
/etc/yum.repos.d/epel-testing.repo
/etc/yum.repos.d/epel.repo
/usr/lib/systemd/system-preset/90-epel.preset
/usr/share/doc/epel-release
/usr/share/doc/epel-release/GPL
/usr/share/doc/epel-release/README-epel-8-packaging.md

 

Download the package

[root@localhost ~]# dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

[root@localhost ~]# dnf update



Search for the package in the repo and install. The output looks like this


[root@localhost ~]# yum search postgresql13

Last metadata expiration check: 0:00:07 ago on Sat 19 Jun 2021 01:51:50 PM EDT.
======================================================== Name Exactly Matched: postgresql13 =========================================================
postgresql13.x86_64 : PostgreSQL client programs and libraries
============================================================ Name Matched: postgresql13 =============================================================
postgresql13-contrib.x86_64 : Contributed source and binaries distributed with PostgreSQL
postgresql13-devel.x86_64 : PostgreSQL development header files and libraries
postgresql13-docs.x86_64 : Extra documentation for PostgreSQL
postgresql13-libs.x86_64 : The shared libraries required for any PostgreSQL clients
postgresql13-llvmjit.x86_64 : Just-in-time compilation support for PostgreSQL
postgresql13-odbc.x86_64 : PostgreSQL ODBC driver
postgresql13-plperl.x86_64 : The Perl procedural language for PostgreSQL
postgresql13-plpython3.x86_64 : The Python3 procedural language for PostgreSQL
postgresql13-pltcl.x86_64 : The Tcl procedural language for PostgreSQL
[postgresql13-server.x86_64 : The programs needed to create and run a PostgreSQL server
postgresql13-test.x86_64 : The test suite distributed with PostgreSQL
[root@localhost ~]#

 

[root@localhost ~]# yum -y install postgresql13 postgresql13-server

The above step completes PostgreSQL 13 Server installation. It installs below packages

postgresql13: Key clients and libraries, and documentation

postgresql13-server: Server executable and data files


Once the software is installed, as a root initialize the cluster with below command.

To initialize and start the database 

[root@localhost ~]# sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
Initializing database ... OK


[root@localhost ~]# systemctl start postgresql-13

[root@localhost ~]# systemctl status postgresql-13

 postgresql-13.service - PostgreSQL 13 database server

   Loaded: loaded (/usr/lib/systemd/system/postgresql-13.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-06-19 13:56:27 EDT; 11s ago
     Docs: https://www.postgresql.org/docs/13/static/
  Process: 5259 ExecStartPre=/usr/pgsql-13/bin/postgresql-13-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 5264 (postmaster)
    Tasks: 8 (limit: 11251)
   Memory: 16.9M
   CGroup: /system.slice/postgresql-13.service
           ├─5264 /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/13/data/
           ├─5266 postgres: logger
           ├─5268 postgres: checkpointer
           ├─5269 postgres: background writer
           ├─5270 postgres: walwriter
           ├─5271 postgres: autovacuum launcher
           ├─5272 postgres: stats collector
           └─5273 postgres: logical replication launcher
 
Jun 19 13:56:27 localhost.localdomain systemd[1]: Starting PostgreSQL 13 database server...
Jun 19 13:56:27 localhost.localdomain postmaster[5264]: 2021-06-19 13:56:27.539 EDT [5264] LOG:  redirecting log output to logging collector process
Jun 19 13:56:27 localhost.localdomain postmaster[5264]: 2021-06-19 13:56:27.539 EDT [5264] HINT:  Future log output will appear in directory "log".
Jun 19 13:56:27 localhost.localdomain systemd[1]: Started PostgreSQL 13 database server.

[root@localhost ~]#

 

To enable the service to start when the system is rebooted

[root@localhost ~]# systemctl enable postgresql-13

Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-13.service  /usr/lib/systemd/system/postgresql-13.service.

 

Setting Environment Variables  (Login as a postgres user)

[postgres@localhost ~]$  psql -c "alter user postgres with password 'postgres'"
ALTER ROLE

 

Setting up Bash Profile

If you installed into /usr/local/pgsql or some other location that is not searched for programs by default, you should add /usr/local/pgsql/bin (or whatever you set --bindir ) into your PATH. Strictly speaking, this is not necessary, but it will make the use of PostgreSQL much more convenient.

To do this, add the following to your shell start-up file, such as ~/.bash_profile (or /etc/profile, if you want it to affect all users):

 

Set /usr/pgsql-13/bin in system PATH

[postgres@localhost~]$ls -la
[postgres@localhost~]$ vi .bash_profile
[postgres@localhost~]$ . .bash_profile
[postgres@localhost~]$ cat .bash_profile

# .bash_profile
            # Get the aliases and functions

if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
           # User specific environment and startup programs

           PATH=/usr/pgsql-13/bin:$PATH
export PATH #PATH=$PATH:$HOME/.local/bin:$HOME/bin #export PATH



Read more 

SSL Setup for Postgres in Linux

Configure Streaming Replication in PostgreSQL

All about Physical Replication and Log shipping in Postgres 

Possible ways to recover space from deleted rows with insufficient disk space

Streaming-Replication Sync and Async, benefits of streaming replication over Log-shipping

 


 




No comments:

Post a Comment