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

sudo yum groupinstall "Development Tools" -y

sudo yum install -y readline-devel zlib-devel


Download PostgreSQL:

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:

bash

sudo useradd postgres

sudo mkdir -p /u01/postgres

sudo chown -R postgres:postgres /u01/postgres

sudo chmod -R 0700 /u01/postgres


Set Environment Variables:

bash

su - postgres

export PATH=/u01/postgres/pgdata_15/bin:$PATH

export LD_LIBRARY_PATH=/u01/postgres/pgdata_15/lib:$LD_LIBRARY_PATH

echo 'export PATH=/u01/postgres/pgdata_15/bin:$PATH' >> ~/.bash_profile

echo 'export LD_LIBRARY_PATH=/u01/postgres/pgdata_15/lib:$LD_LIBRARY_PATH' >> ~/.bash_profile

source ~/.bash_profile


Initialize Database Cluster:

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