Ads

11 March 2026

PostgreSQL Source Code Installation

 Build From Source Code:

PostgreSQL Source Code Installation means compiling and installing PostgreSQL directly from its source files instead of using prebuilt packages.

Prerequisite:


Before we install PostgreSQL software/cluster, we need to ensure that we have all the necessary tools and libraries on our system.

We need install software using root user only 

○ C Compiler: PostgreSQL is written in C, so a C compiler is a must. Popular choices include GCC (GNU Compiler Collection) and Clang.

○ Build Tools: Ensure you have essential build tools like make and autoconf installed. These tools help in compiling the source code efficiently.

○ Libraries: PostgreSQL requires certain libraries like readline and zlib. We need to install these development libraries on our system.

○ readline-devel: Provides the necessary libraries for command-line editing and history.

○ zlib-devel: Required for compression support.

○ gcc: The GNU Compiler Collection needed to compile the PostgreSQL source code.

○ make: A build tool used to compile and install the software.

Step1) Install Required Packages

[root@post101 ~]# yum install readline-devel zlib-devel openssl-devel libxml2-devel libxslt-devel systemd-devel wget tar perl perl-core perl-FindBin -y

OR

[root@post101 ~]# sudo dnf install readline-devel zlib-devel openssl-devel libxml2-devel libxslt-devel systemd-devel wget tar perl perl-core perl-FindBin -y


Step2) Create postgres user and add user to sudoers file

[root@post101 ~]# adduser postgres
[root@post101 ~]# passwd postgres

Retype new password:
passwd: all authentication tokens updated successfully.
[root@post101 ~]# vi /etc/sudoers
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
postgres ALL=(ALL)      ALL

Step3) 

Download Source Code From https://www.postgresql.org/download/ 

Download software and copy software using WinSCP




OR

Use below command if we have internet connection 

[root@post101 ~]# 

[root@post101 ~]# wget https://ftp.postgresql.org/pub/source/v17.1/postgresql-17.1.tar.gz










Step4) untar zip file and go to postgresql-17.1

[root@post101 ~]# tar -xvzf postgresql-17.1.tar.gz












[root@post101 ~]# cd postgresql-17.1
[root@post101 postgresql-17.1]# ls -lrt
total 820
drwxrwxr-x. 16 root root   4096 Nov 12  2024 src
-rw-rw-r--.  1 root root    983 Nov 12  2024 README.md
-rw-rw-r--.  1 root root   6484 Nov 12  2024 meson_options.txt
-rw-rw-r--.  1 root root 115220 Nov 12  2024 meson.build
-rw-rw-r--.  1 root root   1822 Nov 12  2024 Makefile
-rw-rw-r--.  1 root root    277 Nov 12  2024 HISTORY
-rw-rw-r--.  1 root root   4176 Nov 12  2024 GNUmakefile.in
drwxrwxr-x.  3 root root     87 Nov 12  2024 doc
-rw-rw-r--.  1 root root   1192 Nov 12  2024 COPYRIGHT
drwxrwxr-x. 59 root root   4096 Nov 12  2024 contrib
-rw-rw-r--.  1 root root  88218 Nov 12  2024 configure.ac
-rwxrwxr-x.  1 root root 578504 Nov 12  2024 configure
drwxrwxr-x.  2 root root   4096 Nov 12  2024 config
-rw-rw-r--.  1 root root    365 Nov 12  2024 aclocal.m4
[root@post101 postgresql-17.1]#

















Step5) Create directory for software binaries installation

[root@post101 ~]# mkdir -p /u01/pgsql-17/
[root@post101 ~]# cd /u01/pgsql-17/
[root@post101 pgsql-17]# ls -lrt
total 0
[root@post101 pgsql-17]#
 


Step6) ./configure

Configure the Build

This prepares the build environment.

prefix ==> Installation directory
configure ==> Checks OS libraries & prepares compilation

[root@post101 postgresql-17.1]# ./configure --prefix=/u01/pgsql-17

i got the below errors , so can skip by using below command '

checking for icu-uc icu-i18n... no
configure: error: ICU library not found
If you have ICU already installed, see config.log for details on the
failure.  It is possible the compiler isn't looking in the proper directory.
Use --without-icu to disable ICU support.

[root@post101 postgresql-17.1]# ./configure --prefix=/u01/pgsql-17 --without-icu --without-readline

This time this got succeed without any erros 

config.status: creating src/include/pg_config_ext.h
config.status: creating src/interfaces/ecpg/include/ecpg_config.h
config.status: linking src/backend/port/tas/dummy.s to src/backend/port/tas.s
config.status: linking src/backend/port/posix_sema.c to src/backend/port/pg_sema.c
config.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c
config.status: linking src/include/port/linux.h to src/include/pg_config_os.h
config.status: linking src/makefiles/Makefile.linux to src/Makefile.port
[root@post101 postgresql-17.1]#

step7) make (Compile the Source Code)

This step builds PostgreSQL binaries.

[root@post101 postgresql-17.1]# make

Steep8) make install (Install PostgreSQL)

[root@post101 postgresql-17.1]# cd /u01/pgsql-17/
[root@post101 pgsql-17]# ls -lrt
total 16
drwxr-xr-x. 6 root root 4096 Mar 11 20:42 include
drwxr-xr-x. 2 root root 4096 Mar 11 20:43 bin
drwxr-xr-x. 6 root root 4096 Mar 11 20:43 share
drwxr-xr-x. 4 root root 4096 Mar 11 20:43 lib
[root@post101 pgsql-17]#


After installation, PostgreSQL will be located at:

 /u01/pgsql-17/

we can see all executable files on bin location

[root@post101 postgresql-17.1]# cd /u01/pgsql-17/
[root@post101 pgsql-17]# ls -lrt
total 16
drwxr-xr-x. 6 root root 4096 Mar 11 20:42 include
drwxr-xr-x. 2 root root 4096 Mar 11 20:43 bin
drwxr-xr-x. 6 root root 4096 Mar 11 20:43 share
drwxr-xr-x. 4 root root 4096 Mar 11 20:43 lib
[root@post101 pgsql-17]# cd bin/
[root@post101 bin]# ls -lrt
total 15360
-rwxr-xr-x. 1 root root 10154008 Mar 11 20:42 postgres
-rwxr-xr-x. 1 root root  1083408 Mar 11 20:42 ecpg
-rwxr-xr-x. 1 root root   170704 Mar 11 20:42 initdb
-rwxr-xr-x. 1 root root   115224 Mar 11 20:42 pg_amcheck
-rwxr-xr-x. 1 root root    49664 Mar 11 20:42 pg_archivecleanup
-rwxr-xr-x. 1 root root   173376 Mar 11 20:42 pg_basebackup
-rwxr-xr-x. 1 root root   114304 Mar 11 20:42 pg_createsubscriber
-rwxr-xr-x. 1 root root   116408 Mar 11 20:42 pg_receivewal
-rwxr-xr-x. 1 root root   116160 Mar 11 20:42 pg_recvlogical
-rwxr-xr-x. 1 root root    85440 Mar 11 20:42 pg_checksums
-rwxr-xr-x. 1 root root   187312 Mar 11 20:42 pg_combinebackup
-rwxr-xr-x. 1 root root    47808 Mar 11 20:42 pg_config
-rwxr-xr-x. 1 root root    66592 Mar 11 20:42 pg_controldata
-rwxr-xr-x. 1 root root    82176 Mar 11 20:42 pg_ctl
-rwxr-xr-x. 1 root root   440376 Mar 11 20:42 pg_dump
-rwxr-xr-x. 1 root root   220784 Mar 11 20:42 pg_restore
-rwxr-xr-x. 1 root root   136528 Mar 11 20:42 pg_dumpall
-rwxr-xr-x. 1 root root    77088 Mar 11 20:42 pg_resetwal
-rwxr-xr-x. 1 root root   169448 Mar 11 20:42 pg_rewind
-rwxr-xr-x. 1 root root    55160 Mar 11 20:42 pg_test_fsync
-rwxr-xr-x. 1 root root    44120 Mar 11 20:42 pg_test_timing
-rwxr-xr-x. 1 root root   189328 Mar 11 20:42 pg_upgrade
-rwxr-xr-x. 1 root root   139072 Mar 11 20:42 pg_verifybackup
-rwxr-xr-x. 1 root root   123536 Mar 11 20:42 pg_waldump
-rwxr-xr-x. 1 root root    76488 Mar 11 20:42 pg_walsummary
-rwxr-xr-x. 1 root root   211344 Mar 11 20:43 pgbench
-rwxr-xr-x. 1 root root   528168 Mar 11 20:43 psql
-rwxr-xr-x. 1 root root    83648 Mar 11 20:43 createdb
-rwxr-xr-x. 1 root root    79032 Mar 11 20:43 dropdb
-rwxr-xr-x. 1 root root    88576 Mar 11 20:43 createuser
-rwxr-xr-x. 1 root root    78968 Mar 11 20:43 dropuser
-rwxr-xr-x. 1 root root    83888 Mar 11 20:43 clusterdb
-rwxr-xr-x. 1 root root    97744 Mar 11 20:43 vacuumdb
-rwxr-xr-x. 1 root root    93024 Mar 11 20:43 reindexdb
-rwxr-xr-x. 1 root root    78472 Mar 11 20:43 pg_isready
[root@post101 bin]#


Step8) Create Data Directory and grant Permissions to postgres user

[root@post101 bin]# mkdir -p /u01/pgdata
[root@post101 bin]# cd /u01/pgdata
[root@post101 pgdata]# ls -lrt
total 0
[root@post101 pgdata]#
[root@post101 pgdata]# chown -R postgres:postgres /u01/pgdata

Step9) switch to postgres user 

[root@post101 pgdata]# su - postgres
[postgres@post101 ~]$ cd /u01/pg
pgdata/   pgsql-17/
[postgres@post101 ~]$ cd /u01/pgdata/
[postgres@post101 pgdata]$ pwd
/u01/pgdata
[postgres@post101 pgdata]$ ls -lrt
total 0
[postgres@post101 pgdata]$

Step10)  Initialize Database Cluster

[postgres@post101 bin]$ /u01/pgsql-17/bin/initdb -D /u01/pgdata

The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /u01/pgdata ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default "max_connections" ... 100
selecting default "shared_buffers" ... 128MB
selecting default time zone ... Asia/Kolkata
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    /u01/pgsql-17/bin/pg_ctl -D /u01/pgdata -l logfile start

[postgres@post101 bin]$

Step11) Start PostgreSQL cluster 

[postgres@post101 bin]$ /u01/pgsql-17/bin/pg_ctl  -D /u01/pgdata start
waiting for server to start....2026-03-11 20:56:42.024 IST [9732] LOG:  starting PostgreSQL 17.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44.0.3), 64-bit
2026-03-11 20:56:42.035 IST [9732] LOG:  listening on IPv6 address "::1%1", port 5432
2026-03-11 20:56:42.035 IST [9732] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2026-03-11 20:56:42.417 IST [9732] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2026-03-11 20:56:42.432 IST [9735] LOG:  database system was shut down at 2026-03-11 20:54:02 IST
2026-03-11 20:56:42.446 IST [9732] LOG:  database system is ready to accept connections
 done
server started
[postgres@post101 bin]$
[postgres@post101 bin]$ ps -ef|grep postgres
root      7357  3458  0 20:51 pts/0    00:00:00 su - postgres
postgres  7358  7357  0 20:51 pts/0    00:00:00 -bash
postgres  9732     1  0 20:56 ?        00:00:00 /u01/pgsql-17/bin/postgres -D /u01/pgdata
postgres  9733  9732  0 20:56 ?        00:00:00 postgres: checkpointer
postgres  9734  9732  0 20:56 ?        00:00:00 postgres: background writer
postgres  9736  9732  0 20:56 ?        00:00:00 postgres: walwriter
postgres  9737  9732  0 20:56 ?        00:00:00 postgres: autovacuum launcher
postgres  9738  9732  0 20:56 ?        00:00:00 postgres: logical replication launcher
postgres 10878  7358 99 20:59 pts/0    00:00:00 ps -ef
postgres 10879  7358  0 20:59 pts/0    00:00:00 grep --color=auto postgres
[postgres@post101 bin]$



Step12) Set Environment Variables

[postgres@post101 ~]$ vi .bash_profile

export PATH=$PATH:/u01/pgsql-17/bin
export PGDATA=/u01/pgdata


[postgres@post101 ~]$ . .bash_profile
[postgres@post101 ~]$ source .bash_profile
[postgres@post101 ~]$ psql
psql (17.1)
Type "help" for help.

postgres=# \l
                                                     List of databases
   Name    |  Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | Locale | ICU
Rules |   Access privileges
-----------+----------+----------+-----------------+-------------+-------------+--------+-----
------+-----------------------
 postgres  | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |        |
      |
 template0 | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |        |
      | =c/postgres          +
           |          |          |                 |             |             |        |
      | postgres=CTc/postgres
 template1 | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |        |
      | =c/postgres          +
           |          |          |                 |             |             |        |
      | postgres=CTc/postgres
(3 rows)



Step13) How to start postgres services auto start whenever server rebooted/shutdown 

Switch to root user

[postgres@post101 ~]$ su -
Password:
Last login: Wed Mar 11 19:59:13 IST 2026 from 2406:7400:9a:e591:fc9d:9082:d6a7:20c1 on pts/0
[root@post101 ~]# 
[root@post101 ~]# cd /etc/rc.d
[root@post101 rc.d]# ls -lrt
total 8
drwxr-xr-x. 2 root root   61 Jun 12  2024 rc6.d
drwxr-xr-x. 2 root root   61 Jun 12  2024 rc5.d
drwxr-xr-x. 2 root root   61 Jun 12  2024 rc4.d
drwxr-xr-x. 2 root root   61 Jun 12  2024 rc3.d
drwxr-xr-x. 2 root root   61 Jun 12  2024 rc2.d
drwxr-xr-x. 2 root root   61 Jun 12  2024 rc1.d
drwxr-xr-x. 2 root root   61 Jun 12  2024 rc0.d
-rw-r--r--. 1 root root  473 Oct 10  2024 rc.local
drwxr-xr-x. 2 root root 4096 Feb  6 17:55 init.d
[root@post101 rc.d]# vi rc.local
[root@post101 rc.d]# cat rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local

su - postgres -c 'pg_ctl -D $PGDATA start'

[root@post101 rc.d]#
[root@post101 rc.d]# chmod +x /etc/rc.d/rc.local







No comments:

Post a Comment