Step-by-step installation of installation of PostgreSQL 12.3 on CentOS 8.1 from source
In this post we have explained how to (step-by-step) install PostgreSQL 12.3 on CentOS 8.1. Please don’t use this blog post for installation and configuration of PostgreSQL 12.3 from source in production, We have written this post only for learning purpose and definitely not a recommendation for PostgreSQL deployment. This installation was done from PostgreSQL 12.3 source file (Postgresql-12.3.tar.bz2). You can follow the same steps for PostgreSQL 12.3 installation on other versions of CentOS and “Red Hat Linux”, The following steps remain same for other PostgreSQL versions also. You can always configure custom values for OS user, group, installation directories, port etc.
Step-by-step installation of PostgreSQL 12.3 on CentOS 8.1
Step 1
Confirm the CentOS Linux is configured accordingly for PostgreSQL installation and configuration. Connect using PostgreSQL administration user
Step 2
You can create folders for PostgreSQL binaries, data, backup files etc.
- binaries — /databases/postgres/postgres_binaries
- data — /databases/postgres/postgres_data
- logs — /databases/postgres/postgres_logs
- backups — /databases/postgres/postgres_backup
1 2 3 4 5 6 7 8 |
$ cd /databases/ $ mkdir postgres $ cd postgres/ $ mkdir postgres_binaries $ mkdir postgres_data $ mkdir postgres_logs $ mkdir postgres_backup $ mkdir postgres_temp |
Step 3
Confirm the owner of source tar file is PostgreSQL administration user and also grant 775 permission to the source tar file:
1 |
$ cp /media/sf_commonshare/setups/DB_setups_centOS_8/postgresql-12.3.tar.bz2 /databases/postgres/postgres_binaries/ |
1 2 3 |
$ cd /databases/postgres/postgres_binaries $ chown postgresadmin:postgresadmin postgresql-12.3.tar.bz2 $ chmod 775 postgresql-12.3.tar.bz2 |
Step 4
Create a new folder postgresql-12.3-installers to retain PostgreSQL installers:
1 2 |
$ cd /databases/postgres/postgres_binaries $ mkdir postgresql-12.3-installers |
Step 5
Extract the source tar file:
1 2 |
$ cd /databases/postgres/postgres_binaries $ tar -xvf postgresql-12.3.tar.bz2 |
Step 6
When you extract the source tar file a new folder by name “postgresql-12.3” gets created. Please follow the commands step-by-step as copied below:
1 2 3 4 5 6 7 8 9 |
$ cd /databases/postgres/postgres_binaries $ ./postgresql-12.3/configure — prefix /databases/postgres/postgres_binaries/postgresql-12.3-installers — without-readline — without-zlib $ make $ make install |
Step 7
Please configure environment file you need to start and stop PostgreSQL server. In this post we have created it by name “postgres_12.3_env.sh” in the folder “/database/postgres”
1 2 3 4 5 |
$ export PATH=/databases/postgres/postgres_binaries/postgresql-12.3-installers/bin:$PATH $ export PGDATA=/databases/postgres/postgres_data $ export PGDATABASE=postgres $ export PGUSER=postgres $ export PGPORT=5434 |
Step 8
You can grant 775 permission to the environment file
1 2 |
$ cd /databases/postgres $ chmod 775 postgres_12.3_env.sh |
Step 9
Initialize PostgreSQL database or cluster using initdb
1 2 3 |
$ cd /databases/postgres/postgres_binaries/postgresql-12.3-installers $ ./bin/initdb -D /databases/postgres/postgres_data -U postgres |
Step 10
Start PostgreSQL database using command pg_ctl.
1 2 3 4 5 |
$ cd /databases/postgres/postgres_binaries/postgresql-12.3-installers $ ./bin/pg_ctl -D /databases/postgres/postgres_data -l /databases/postgres/ $ postgres_logs/12.3_postgres_logfile.log -o “-p 5434” start |
Note: pg_ctl uses ‘-D’ option for the data directory and ‘-l’ option for log
Step 11
Test connecting to PostgreSQL from psql
1 2 3 4 5 |
$ cd /databases/postgres $ . ./postgres_12.3_env.sh $ psql |
How to debug PostgreSQL connectivity issues post installation:
- Stop PostgreSQL Server with ‘pg_ctl_stop’ and go to data directory of PostgreSQL
- open PostgreSQL configuration file pg_hba.conf file and append the entry given in the line copied below
host all all 0.0.0.0/0 md5 - Open PostgreSQL configuration file postgresql.conf and update listen_address with values below
listen_addresses = ‘*’ - Start PostgreSQL Server using ‘pg_ctl start’