Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
1 views

installing-postgres-17-using-source-files

This document provides a step-by-step guide for installing PostgreSQL 17 from source files on a CentOS 10 EC2 instance. It outlines the necessary packages, user creation, downloading and configuring PostgreSQL, and initializing the database cluster. The guide emphasizes the benefits of source installation, such as customization and development opportunities.

Uploaded by

Rekesh Patel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

installing-postgres-17-using-source-files

This document provides a step-by-step guide for installing PostgreSQL 17 from source files on a CentOS 10 EC2 instance. It outlines the necessary packages, user creation, downloading and configuring PostgreSQL, and initializing the database cluster. The guide emphasizes the benefits of source installation, such as customization and development opportunities.

Uploaded by

Rekesh Patel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Installing Postgres 17 using source files

Dear readers,
In this document, I’ll show you how to install PG 17 using source files.

Various methods to install PG


1. YUM: From Linux machine run yum install and required PG packages will be downloaded from the
internet
2. RPM: Download required PG packages (.rpm) from internet to the Linux machine and then install those
packages via rpm
3. Source files: Download required PG source files from internet to the Linux machine, compile them and
then install.

Reasons to choose source files installation over other methods:


1. You want to use some customized PG options/settings e.g. Use different block size than default 8Kb or
want bigger WAL files than default 16 MB etc.
2. You want to develop a custom PG release of yours.
3. You found an are to improveme in PG and want to introduce that in PG
4. And many more

I have a CentOS 10 EC2 of t2.micro size (as it’s available for free and suits to our purpose), so let’s begin.

1. Installing the necessary packages:


a. gcc: To compile and execute PG core files
b. make: As PG is written in C language, it’s core files will be complied and executed using make
utility. Makefile is a special file that has entries of the files to be compiled and then run (resulting
into PG installation in our case).
c. zlib-devel: To support various PG compression algorithms
d. wget: To download PG files from the internet
e. libucu-devel: Development files for International Components for Unicode
f. bison: Needed for debugging PG parser grammer
g. flex: A tool for generating scanners (text pattern recognizers)
h. perl: Neede for OpenSSL configuration option
i. readline-devel: To provide history in psql (when we hit up arrow, we can see previous
commands we executed)

[root@ip-172-31-31-68 ~]# cat /etc/redhat-release


CentOS Stream release 10 (Coughlan)

[root@ip-172-31-31-68 ~]# yum install -y gcc readline-devel make zlib-devel openssl-devel


wget libicu-devel bison flex perl

2. Creating postgres user and directories for PGDATA, PG binaries

[root@ip-172-31-31-68 ~]# useradd -d /home/postgres -U postgres


[root@ip-172-31-31-68 ~]# echo postgres | passwd "postgres" --stdin
BAD PASSWORD: The password contains the user name in some form

Created by Amol V. Palav [+91 7045443328] Page 1


[root@ip-172-31-31-68 ~]# mkdir -p /pgdata/17/main
[root@ip-172-31-31-68 ~]# chown -R postgres:postgres /pgdata
[root@ip-172-31-31-68 ~]# chmod -R 755 /pgdata
[root@ip-172-31-31-68 ~]# mkdir -p /home/postgres/bin/pgsql/17
[root@ip-172-31-31-68 ~]# chmod -R 755 /home/postgres/bin/pgsql/17
[root@ip-172-31-31-68 ~]# chown postgres: /home/postgres/bin/pgsql/17

3. Downloading and unzipping PG binaries

[root@ip-172-31-31-68 ~]# cd /tmp


[root@ip-172-31-31-68 tmp]# wget https://ftp.postgresql.org/pub/source/v17.2/postgresql-
17.2.tar.gz
[root@ip-172-31-31-68 tmp]# ls -lh postgresql-17*
[root@ip-172-31-31-68 tmp]# gunzip postgresql-17.2.tar.gz
[root@ip-172-31-31-68 tmp]# tar -xpf postgresql-17.2.tar
[root@ip-172-31-31-68 tmp]# cd postgresql-17.2
[root@ip-172-31-31-68 postgresql-17.2]# ls -lh

4. We can see configure utility that’ll help us to install PG using various options. We can see various
options this utility provides using below command

[[root@ip-172-31-31-68 postgresql-17.2]# ./configure --help

Created by Amol V. Palav [+91 7045443328] Page 2


5. Generating PG binaries (kind of a PG home where various utilities will reside e.g. psql, pg_dump)

[root@ip-172-31-31-68 postgresql-17.2]# ./configure --prefix=/home/postgres/bin/pgsql/17 --


with-openssl
[root@ip-172-31-31-68 postgresql-17.2]# make
[root@ip-172-31-31-68 postgresql-17.2]# make install

6. Generating an environment file/profile for postgres user

[root@ip-172-31-31-68 postgresql-17.2]# echo '


alias lt="ls -ltrh"
alias lta="ls -ltrha"
alias cl="clear"
alias lk="ps -ef | grep "
alias lki="ps -ef | grep "
export PGDATA=/pgdata/17/main
export PATH=/home/postgres/bin/pgsql/17/bin:$PATH
export LD_LIBRARY_PATH=/home/postgres/bin/pgsql/17/lib:$LD_LIBRARY_PATH
' >> /home/postgres/.bash_profile

[root@ip-172-31-31-68 postgresql-17.2]# chmod 755 /home/postgres/.bash_profile

[root@ip-172-31-31-68 postgresql-17.2]# chown postgres: /home/postgres/.bash_profile

Created by Amol V. Palav [+91 7045443328] Page 3


7. Initializing and starting the PG cluster via postgres user

[root@ip-172-31-31-68 postgresql-17.2]# sudo su - postgres


[postgres@ip-172-31-31-68 ~]$ which initdb
~/bin/pgsql/17/bin/initdb
[postgres@ip-172-31-31-68 ~]$ echo $PGDATA/
/pgdata/17/main/
[postgres@ip-172-31-31-68 ~]$ initdb -D $PGDATA –k
[postgres@ip-172-31-31-68 ~]$ pg_ctl -D $PGDATA/ start

8. Verification

[postgres@ip-172-31-31-68 ~]$ pg_ctl -D $PGDATA/ status

# from psql prompt


postgres=# select version();
postgres=# show data_checksums;

Created by Amol V. Palav [+91 7045443328] Page 4

You might also like