Tuesday, 10 July 2018

Setup PostgreSQL Using Source Based Installation


Download and setup PostgreSQL using source Based Installation
There are many ways to install & setup PostgreSQL like Package based installation, installer based installation and Source based installation. In this blog, I will show you, how we can setup PostgreSQL 10 using Source Based installation on OEL 6.5 64 Bit Machine.

Pre-requisites
1. Create a PostgreSQL Group and User on the OS.
[root@postgres221 ~]# groupadd postgres
[root@postgres221 ~]# useradd -g postgres postgres
2. Download and install the gcc zlib-devel readline-devel packages if not installed
Note: I installed from the Linux iso media
[root@postgres221 ~]# cd /media/OL6.5\ x86_64\ Disc\ 1\ 20131125/Packages/
[root@postgres221 Packages]# rpm -Uvh *gcc* --nodeps
Preparing...                ########################################### [100%]
   1:libgcc                 ########################################### [  8%]
   2:gcc                    ########################################### [ 17%]
   3:compat-gcc-34          ########################################### [ 25%]
   4:gcc-c++                ########################################### [ 33%]
   5:gcc-objc               ########################################### [ 42%]
   6:gcc-objc++             ########################################### [ 50%]
   7:compat-gcc-34-g77      ########################################### [ 58%]
   8:gcc-gfortran           ########################################### [ 67%]
   9:gcc-gnat               ########################################### [ 75%]
  10:gcc-java               ########################################### [ 83%]
  11:libgcc                 ########################################### [ 92%]
  12:compat-gcc-34-c++      ########################################### [100%]
[root@postgres221 Packages]# rpm -Uvh *zlib-devel* --nodeps
Preparing...                ########################################### [100%]
        package zlib-devel-1.2.3-29.el6.x86_64 is already installed
[root@postgres221 Packages]# rpm -Uvh *readline-devel* --nodeps
Preparing...                ########################################### [100%]
        package readline-devel-6.0-4.el6.x86_64 is already installed
Step 1: Download & extract PostgreSQL Source Code from the below site.
https://www.postgresql.org/ftp/source/

Step 2: Install postgreSQL
[root@postgres221 postgres]# tar -zxvf postgresql-10.0.tar.gz

Once untar the file, it will create a folder:
[root@postgres221 postgres]# ls -ltr
total 25252
drwxrwxrwx 6     1107     1107     4096 Oct  2  2017 postgresql-10.0

[root@postgres221 postgres]# cd postgresql-10.0
[root@postgres221 postgresql-10.0]# ls -ltr
total 672
-rw-r--r--  1 1107 1107   1212 Oct  2  2017 README
-rw-r--r--  1 1107 1107   1529 Oct  2  2017 Makefile
-rw-r--r--  1 1107 1107    284 Oct  2  2017 HISTORY
-rw-r--r--  1 1107 1107   3638 Oct  2  2017 GNUmakefile.in
-rw-r--r--  1 1107 1107   1192 Oct  2  2017 COPYRIGHT
-rw-r--r--  1 1107 1107  76410 Oct  2  2017 configure.in
-rwxr-xr-x  1 1107 1107 495611 Oct  2  2017 configure
-rw-r--r--  1 1107 1107    457 Oct  2  2017 aclocal.m4
drwxrwxrwx 55 1107 1107   4096 Oct  2  2017 contrib
drwxrwxrwx  2 1107 1107   4096 Oct  2  2017 config
drwxrwxrwx  3 1107 1107   4096 Oct  2  2017 doc
-rw-r--r--  1 1107 1107  71584 Oct  2  2017 INSTALL
drwxrwxrwx 16 1107 1107   4096 Oct  2  2017 src

[root@postgres221 postgresql-10.0]# ./configure
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking which template to use... linux
checking whether NLS is wanted... no
checking for default port number... 5432
checking for block size... 8kB
checking for segment size... 1GB
checking for WAL block size... 8kB
checking for WAL segment size... 16MB
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
.
.
.
config.status: linking src/backend/port/dynloader/linux.h to src/include/dynloader.h
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@postgres221 postgresql-10.0]#

[root@postgres221 postgresql-10.0]# make
make -C src all
make[1]: Entering directory `/postgres/postgresql-10.0/src'
make -C common all
make[2]: Entering directory `/postgres/postgresql-10.0/src/common'
make -C ../backend submake-errcodes
make[3]: Entering directory `/postgres/postgresql-10.0/src/backend'
prereqdir=`cd 'utils/' >/dev/null && pwd` && \
          cd '../../src/include/utils/' && rm -f errcodes.h && \
          ln -s "$prereqdir/errcodes.h" .
make[3]: Leaving directory `/postgres/postgresql-10.0/src/backend'
  .
  .
  .
make -C config all
make[1]: Entering directory `/postgres/postgresql-10.0/config'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/postgres/postgresql-10.0/config'
All of PostgreSQL successfully made. Ready to install.

[root@postgres221 postgresql-10.0]# make install
make[1]: Entering directory `/postgres/postgresql-10.0/config'
/bin/mkdir -p '/usr/local/pgsql/lib/pgxs/config'
/usr/bin/install -c -m 755 ./install-sh '/usr/local/pgsql/lib/pgxs/config/install-sh'
/usr/bin/install -c -m 755 ./missing '/usr/local/pgsql/lib/pgxs/config/missing'
make[1]: Leaving directory `/postgres/postgresql-10.0/config'
PostgreSQL installation complete.

Step 3: Verify the postgreSQL directory structure
[root@postgres221 postgresql-10.0]#  ls -l /usr/local/pgsql/
total 16
drwxr-xr-x 2 root root 4096 Jul 11 00:23 bin
drwxr-xr-x 6 root root 4096 Jul 11 00:23 include
drwxr-xr-x 4 root root 4096 Jul 11 00:23 lib
drwxr-xr-x 6 root root 4096 Jul 11 00:23 share






Step 4: Change the group and ownership to postgres
[root@postgres221 postgresql-10.0]# chown -R postgres:postgres /usr/local/pgsql/
[root@postgres221 postgresql-10.0]# ls -ltr /usr/local/pgsql/
total 16
drwxr-xr-x 6 postgres postgres 4096 Jul 11 00:23 include
drwxr-xr-x 2 postgres postgres 4096 Jul 11 00:23 bin
drwxr-xr-x 6 postgres postgres 4096 Jul 11 00:23 share
drwxr-xr-x 4 postgres postgres 4096 Jul 11 00:23 lib

Step 5: Initialize postgreSQL data directory
[root@postgres221 postgresql-10.0]# su – postgres

[postgres@postgres221 ~]$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/
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.

creating directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
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:

    /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data/ -l logfile start
Note: Its created data directory by own in /usr/local/pgsql/data

Step 6: Validate the postgreSQL data directory

[postgres@postgres221 ~]$ ls -ltr /usr/local/pgsql/data/
total 112
-rw------- 1 postgres postgres     3 Jul 11 00:27 PG_VERSION
drwx------ 2 postgres postgres  4096 Jul 11 00:27 pg_twophase
drwx------ 2 postgres postgres  4096 Jul 11 00:27 pg_tblspc
drwx------ 2 postgres postgres  4096 Jul 11 00:27 pg_stat_tmp
drwx------ 2 postgres postgres  4096 Jul 11 00:27 pg_stat
drwx------ 2 postgres postgres  4096 Jul 11 00:27 pg_snapshots
drwx------ 2 postgres postgres  4096 Jul 11 00:27 pg_serial
drwx------ 2 postgres postgres  4096 Jul 11 00:27 pg_replslot
drwx------ 4 postgres postgres  4096 Jul 11 00:27 pg_multixact
drwx------ 2 postgres postgres  4096 Jul 11 00:27 pg_dynshmem
drwx------ 2 postgres postgres  4096 Jul 11 00:27 pg_commit_ts
-rw------- 1 postgres postgres 22778 Jul 11 00:27 postgresql.conf
-rw------- 1 postgres postgres    88 Jul 11 00:27 postgresql.auto.conf
-rw------- 1 postgres postgres  1636 Jul 11 00:27 pg_ident.conf
-rw------- 1 postgres postgres  4513 Jul 11 00:27 pg_hba.conf
drwx------ 2 postgres postgres  4096 Jul 11 00:27 pg_xact
drwx------ 3 postgres postgres  4096 Jul 11 00:27 pg_wal
drwx------ 2 postgres postgres  4096 Jul 11 00:27 pg_subtrans
drwx------ 2 postgres postgres  4096 Jul 11 00:27 pg_notify
drwx------ 2 postgres postgres  4096 Jul 11 00:27 global
drwx------ 5 postgres postgres  4096 Jul 11 00:27 base
drwx------ 4 postgres postgres  4096 Jul 11 00:27 pg_logical

Step 7: Start postgreSQL database

[postgres@postgres221 ~]$  /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data/ -l logfile start
waiting for server to start.... done
server started

Step 8: Create postgreSQL DB and test the installation
[postgres@postgres221 ~]$ /usr/local/pgsql/bin/createdb scott
[postgres@postgres221 ~]$ /usr/local/pgsql/bin/psql scott
/usr/local/pgsql/bin/psql: symbol lookup error: /usr/local/pgsql/bin/psql: undefined symbol:  PQsetErrorContextVisibility    รง error
To resolve the above error, I use the following command
[postgres@postgres221 ~]$ export LD_LIBRARY_PATH=/usr/local/pgsql/lib:${LD_LIBRARY_PATH}
[postgres@postgres221 ~]$ /usr/local/pgsql/bin/psql scott
psql (10.0)
Type "help" for help.

scott=#









No comments:

Post a Comment