Wednesday, January 29, 2025

PostgreSQL Source-Based Installation on Centos

PostgreSQL Source-Based Installation On Centos

Pre-requisites:

sudo yum update -y
yum install sudo

vi /etc/sudoers
root ALL=(ALL) ALL

sudo yum groupinstall "Development Tools" -y
sudo yum install -y readline-devel zlib-devel


Download PostgreSQL:

yum install wget
wget https://ftp.postgresql.org/pub/source/v15.3/postgresql-15.3.tar.gz
tar -zxvf postgresql-15.3.tar.gz

cd postgresql-15.3

Configure & Compile:
./configure --prefix=/u01/postgres/pgdata_15
make
sudo make install

Create PostgreSQL User:

[root@HOST01 postgresql-15.3]# pwd

/u01/soft/postgresql-15.3
bash

sudo useradd postgres
sudo mkdir -p /u01/postgres
sudo chown -R postgres:postgres /u01/soft/postgresql-15.3
sudo chmod -R 0700 /u01/soft/postgresql-15.3

Set Environment Variables:

[postgres@HOST02 pgdata_15]$ pwd

/u01/postgres/pgdata_15
bash

su - postgres
export PATH=$PATH:/u01/postgres/pgdata_15/bin
export PGDATA=/u01/postgres/pgdata_15/data
export LD_LIBRARY_PATH=/u01/postgres/pgdata_15/lib:$LD_LIBRARY_PATH


Initialize Database Cluster:

[postgres@HOST02 bin]$ pwd

/u01/postgres/pgdata_15/bin

mkdir -p /u01/postgres/pgdata_15/data
sudo chown -R postgres:postgres /u01/postgres/pgdata_15/data
sudo chmod -R 0700 /u01/postgres/pgdata_15/data

bash
/u01/postgres/pgdata_15/bin/initdb -D /u01/postgres/pgdata_15/data

Start PostgreSQL Server:

bash

pg_ctl -D /u01/postgres/pgdata_15/data -l logfile start

Verify Installation:
bash
pg_ctl -D /u01/postgres/pgdata_15/data status

psql --version

Optional: Set PostgreSQL to Start on Boot:

If you want PostgreSQL to start automatically on boot, you can create a systemd service file.

Example:

ini

[Unit]

Description=PostgreSQL database server

Documentation=https://www.postgresql.org

After=network.target

[Service]

Type=forking

User=postgres

Group=postgres

Environment=PGDATA=/u01/postgres/pgdata_15/data

ExecStart=/u01/postgres/pgdata_15/bin/pg_ctl start -D ${PGDATA} -s -l /var/log/pgsql.log -o "-c config_file=/u01/postgres/pgdata_15/data/postgresql.conf"

ExecStop=/u01/postgres/pgdata_15/bin/pg_ctl stop -D ${PGDATA} -s -m fast

ExecReload=/u01/postgres/pgdata_15/bin/pg_ctl reload -D ${PGDATA} -s -c config_file=/u01/postgres/pgdata_15/data/postgresql.conf


[Install]

Save this as /etc/systemd/system/postgresql.service and then enable and start it:

bash

sudo systemctl enable postgresql

sudo systemctl start postgresql

This should cover all the steps for a source-based installation of PostgreSQL. If you encounter any issues, let me know and I'll help you troubleshoot!

No comments:

Post a Comment