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/postgressed -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.
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 @
Observations:
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.