Step by Step to install PostgreSQL 15 with a custom data directory and enable checksums on CentOS 7


Step by Step to install PostgreSQL  with a custom data directory and enable checksums on CentOS 7

1) Download PostgreSQL Repository RPM

#For RHEL 7/CentOS 7
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

#For RHEL 8/CentOS 8
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

#For RHEL 9
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm

List Repos: sudo yum -y repolist

2) Update your system & Add the EPEL repository which has dependencies required by PostgreSQL 15.

#For RHEL 7/CentOS 7
sudo yum -y update
sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

#For RHEL 8/CentOS 8
sudo yum -y update
sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

#For RHEL 9
sudo yum -y update
sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm

3) Install PosgreSQL on CentOS 7/RHEL 8

sudo yum install -y postgresql15-server

4) Update the service file, Initialize the Postgres with a custom Data directory and enable checksums

mkdir -p /data1/postgres
sudo chown postgres:postgres /data1/postgres

sed -i "s|Environment=PGDATA=/var/lib/pgsql/15/data|Environment=PGDATA=/data1/postgres|" /usr/lib/systemd/system/postgresql-15.service 

sudo systemctl daemon-reload

PGSETUP_INITDB_OPTIONS="-k -D /data1/postgres" /usr/pgsql-15/bin/postgresql-15-setup initdb

-k Use checksums on data pages to help detect corruption by the I/O system that would otherwise be silent. Enabling checksums may incur a noticeable performance penalty. If set, checksums are calculated for all objects, in all databases. All checksum failures will be reported in the pg_stat_database view. When enabled, each data page includes a checksum that is updated when the page is written and verified each time the page is read. Only data pages are protected by checksums.


    
    Check Checksums: /usr/pgsql-15/bin/pg_checksums -D /data1/postgres


#To initialize Postgres without a custom directory & without enabling checksums
sudo /usr/pgsql-15/bin/postgresql-15-setup initdb -k

5) Start the Database

sudo systemctl start postgresql-15

6) Optional step: To start Postges automatically every time when the server got rebooted

sudo systemctl enable postgresql-15

Sample commands:

psql (hit enter)
psql> \l+
psql> \du
psql> create database test;
psql> \c test
psql> create table test as select * from pg_database;
psql> \q


Demo:


To Remove Postgres from Server:

List Postgres RPMs:            yum list |grep -i postgresql|grep @

Remove Postgres RPMs:     yum remove postgresql* (Caution: Please don't execute the remove command unless you really want to destroy (or) decommission Postgres on the server


Observations:

Error1: All matches were filtered out by modular filtering for argument: postgresql15-server
workaround1: dnf module disable postgresql

Error2:Errors during downloading metadata for repository 'rhel-8-for-x86_64-appstream-rpms':
-Curl error (6): Couldn't resolve host name for https://cdn.redhat.com/content/dist/rhel8/8/x86_64/appstream/os/repodata/repomd.xml [Could not resolve host: cdn.redhat.com]
workaround2:
subscription-manager repos --disable fast-datapath-for-rhel-8-x86_64-rpms
subscription-manager repos --enable fast-datapath-for-rhel-8-x86_64-rpms

Error3: Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Workaround3: vi /etc/resolv.conf (add nameserver 9.9.9.9)


DISCLAIMER

The purpose of sharing the content on this website is to Educate. The author/owner of the content do not warrant that the information provided on this website is fully complete and shall not be responsible for any errors or omissions.The author/owner shall have neither liability nor responsibility to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the contents of this website. So, use the content of this website at your own risk.

This content has been shared under Educational And Non-Profit Purposes Only. No Copyright Infringement Intended, All Rights Reserved to the Actual Owner.

For Copyright Content Removal Please Contact us by Email at besttechreads[at]gmail.com

Post a Comment

Previous Post Next Post