Thursday, 20 February 2020

Source installation postgresql 9.5

In this blog we will see how to install postgresql 9.5 source installation.

We will get rpm files for the latest 9.5 version ,

if we need the older version the best way is to source or binary installation. 




Step 1: Download postgreSQL source code


From the postgreSQL download site, choose the version



wget https://ftp.postgresql.org/pub/source/v9.5.9/postgresql-9.5.9.tar.gz



Step 2: Install postgreSQL


tar -zxvf postgresql-9.5.9.tar.gz 

cp -r postgresql-9.5.9 /opt/

cd /opt/postgresql-9.5.9

./configure

 make

make install


PostgreSQL Installation Issue1:


You may encounter the following error message while performing ./configure during postgreSQL installation.

 

# ./configure

checking for -lreadline... no

checking for -ledit... no

configure: error: readline library not found

If you have readline already installed, see config.log for details on the

failure.  It is possible the compiler isn't looking in the proper directory.

Use --without-readline to disable readline support.

PostgreSQL Installation Solution1:


Install the readline-devel and libtermcap-devel to solve the above issue


yum install libtermcap-devel 

yum install readline-devel


Other error fix


yum groupinstall "Development Tools"

./configure   --without-zlib


Step 3: Verify the postgreSQL directory structure


After the installation, make sure bin, doc, include, lib, man and share directories are created under the default /usr/local/pgsql directory as shown below.


# ls -l /usr/local/pgsql/


[root@db2 postgresql-9.5.9]# ls -l /usr/local/pgsql/

total 16

drwxr-xr-x 2 root root 4096 May 13 15:08 bin

drwxr-xr-x 6 root root 4096 May 13 15:08 include

drwxr-xr-x 4 root root 4096 May 13 15:08 lib

drwxr-xr-x 6 root root 4096 May 13 15:08 share

[root@db2 postgresql-9.5.9]#




Step 4: Create postgreSQL user account


# adduser postgres


# passwd postgres

Changing password for user postgres.

New UNIX password:

Retype new UNIX password:

passwd: all authentication tokens updated successfully.




Step 5: Create postgreSQL data directory


Create the postgres data directory and make postgres user as the owner.



mkdir /usr/local/pgsql/data

chown postgres:postgres /usr/local/pgsql/data

ls -ld /usr/local/pgsql/data


Step 6: Initialize postgreSQL data directory


Before you can start creating any postgreSQL database, the empty data directory created in the above step should be initialized using the initdb command as shown below.


su - postgres

/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/


May face below error 

initdb: invalid locale settings; check LANG and LC_* environment variables


Fix will be 

export LC_ALL="en_US.UTF-8"

Step 7: Validate the postgreSQL data directory


Make sure all postgres DB configuration files (For example, postgresql.conf) are created under the data directory as shown below.


$ ls -l /usr/local/pgsql/data

bash-4.2$ ls -l /usr/local/pgsql/data

total 48

drwx------ 5 postgres postgres    41 May 13 15:17 base

drwx------ 2 postgres postgres  4096 May 13 15:17 global

drwx------ 2 postgres postgres    18 May 13 15:17 pg_clog

drwx------ 2 postgres postgres     6 May 13 15:17 pg_commit_ts

drwx------ 2 postgres postgres     6 May 13 15:17 pg_dynshmem

-rw------- 1 postgres postgres  4468 May 13 15:17 pg_hba.conf

-rw------- 1 postgres postgres  1636 May 13 15:17 pg_ident.conf

drwx------ 4 postgres postgres    39 May 13 15:17 pg_logical

drwx------ 4 postgres postgres    36 May 13 15:17 pg_multixact

drwx------ 2 postgres postgres    18 May 13 15:17 pg_notify

drwx------ 2 postgres postgres     6 May 13 15:17 pg_replslot

drwx------ 2 postgres postgres     6 May 13 15:17 pg_serial

drwx------ 2 postgres postgres     6 May 13 15:17 pg_snapshots

drwx------ 2 postgres postgres     6 May 13 15:17 pg_stat

drwx------ 2 postgres postgres     6 May 13 15:17 pg_stat_tmp

drwx------ 2 postgres postgres    18 May 13 15:17 pg_subtrans

drwx------ 2 postgres postgres     6 May 13 15:17 pg_tblspc

drwx------ 2 postgres postgres     6 May 13 15:17 pg_twophase

-rw------- 1 postgres postgres     4 May 13 15:17 PG_VERSION

drwx------ 3 postgres postgres    60 May 13 15:17 pg_xlog

-rw------- 1 postgres postgres    88 May 13 15:17 postgresql.auto.conf

-rw------- 1 postgres postgres 21332 May 13 15:17 postgresql.conf

Step 8: Start postgreSQL database


Use the postgres postmaster command to start the postgreSQL server in the background as shown below.


/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data/ -l logfile start

$ cat logfile


bash-4.2$ cat  logfile

LOG:  database system was shut down at 2020-05-13 15:17:46 IST

LOG:  MultiXact member wraparound protections are now enabled

LOG:  database system is ready to accept connections

LOG:  autovacuum launcher started


Step 9: Login and create postgreSQL DB and test the installation 


bash-4.2$ /usr/local/pgsql/bin/psql

psql (9.5.9)

Type "help" for help.


postgres=# \l

                                  List of databases

   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges

-----------+----------+----------+-------------+-------------+-----------------------

 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |

 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +

           |          |          |             |             | postgres=CTc/postgres

 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +

           |          |          |             |             | postgres=CTc/postgres

(3 rows)


postgres=# create database test;

CREATE DATABASE

postgres=# \l

                                  List of databases

   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges

-----------+----------+----------+-------------+-------------+-----------------------

 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |

 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +

           |          |          |             |             | postgres=CTc/postgres

 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +

           |          |          |             |             | postgres=CTc/postgres

 test      | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |

(4 rows)


postgres=#


No comments: