Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

How to install the PostgreSQL10 On Linux ?

PostgreSQL 10.3 installation steps:
In this tutorial i will explain how to install postgreSQL 10 on Red Hat Enterprise Linux Server release 7.3 Beta (Maipo),How to make network configuration and linux partition for DATA,ARCHIVE,BACKUP, and how to configure postgreSQL cascading replication using postgreSQL 10

Step 1. Download the rpm or directly install on linux server before this create one postgres user:
https://yum.postgresql.org/10/redhat/rhel-7-x86_64/repoview/
                                    (OR)
http://www.tutorialdba.com/2017/11/oracle-and-postgresql-dba-related.html
                                    (OR)
https://yum.postgresql.org/rpmchart.php 
 
Step 2.Install the rpm on master,slave1 and slave2 server

You need to install the rpm following sequence: Sequence would be following
1.postgresql10-libs - The shared libraries required for any PostgreSQL clients
2.postgresql10 - PostgreSQL client programs and libraries
3.postgresql10-server - The programs needed to create and run a PostgreSQL server
4.postgresql10-contrib - Contributed source and binaries distributed with PostgreSQL
[root@master postgreSQL-10]# rpm -ivh postgresql10-10.3-1PGDG.rhel7.x86_64.rpm 
Preparing...                          ################################# [100%]
 package postgresql10-10.3-1PGDG.rhel7.x86_64 is already installed
[root@master postgreSQL-10]# rpm -ivh postgresql10-server-10.3-1PGDG.rhel7.x86_64.rpm 
Preparing...                          ################################# [100%]
 package postgresql10-server-10.3-1PGDG.rhel7.x86_64 is already installed
[root@master postgreSQL-10]# rpm -ivh postgresql10-libs-10.3-1PGDG.rhel7.x86_64.rpm 
Preparing...                          ################################# [100%]
 package postgresql10-libs-10.3-1PGDG.rhel7.x86_64 is already installed
[root@master postgreSQL-10]# rpm -ivh postgresql10-contrib-10.3-1PGDG.rhel7.x86_64.rpm 
Preparing...                          ################################# [100%]
 package postgresql10-contrib-10.3-1PGDG.rhel7.x86_64 is already installed
Step 3.After installing PostgreSQL, you need to initialize the postgreSQL instance before initialize check the setup utility.
[root@master bin]# pwd
/usr/pgsql-10/bin
[root@master bin]# ls -lrt postgresql-10-setup
-rwxr-xr-x. 1 root root 8582 Feb 27 05:16 postgresql-10-setup
Then initialize the database:
[root@master bin]# /usr/pgsql-10/bin/postgresql-10-setup initdb
Initializing database ... OK
Note:PostgreSQL data is typically found /var/lib/pgsql/10/data/ directory.
Verify the data directory:
[root@master bin]# /var/lib/pgsql/10/data/
base/         pg_commit_ts/ pg_multixact/ pg_serial/    pg_stat_tmp/  pg_twophase/
global/       pg_dynshmem/  pg_notify/    pg_snapshots/ pg_subtrans/  pg_wal/
log/          pg_logical/   pg_replslot/  pg_stat/      pg_tblspc/    pg_xact/
Step 4.Currently postgres is not running we need to start the postgres cluster:
A.check the postgres cluster status:
[root@master bin]# ps -ef|grep postgres
root       5141   3519  0 18:41 pts/0    00:00:00 grep --color=auto postgres
B.start the postgres cluster:
[root@master ~]# systemctl start postgresql-10
[root@master ~]# ps -ef|grep post
root       2271      1  0 17:21 ?        00:00:00 /usr/libexec/postfix/master -w
postfix    2274   2271  0 17:21 ?        00:00:00 pickup -l -t unix -u
postfix    2275   2271  0 17:21 ?        00:00:00 qmgr -l -t unix -u
root       5171   3519  0 18:44 pts/0    00:00:00 su postgres
postgres   5172   5171  0 18:44 pts/0    00:00:00 bash
postgres   5295      1  0 18:47 ?        00:00:00 /usr/pgsql-10/bin/postmaster -D /var/lib/pgsql/10/data/
postgres   5297   5295  0 18:47 ?        00:00:00 postgres: logger process   
postgres   5299   5295  0 18:47 ?        00:00:00 postgres: checkpointer process   
postgres   5300   5295  0 18:47 ?        00:00:00 postgres: writer process   
postgres   5301   5295  0 18:47 ?        00:00:00 postgres: wal writer process   
postgres   5302   5295  0 18:47 ?        00:00:00 postgres: autovacuum launcher process   
postgres   5303   5295  0 18:47 ?        00:00:00 postgres: stats collector process   
postgres   5304   5295  0 18:47 ?        00:00:00 postgres: bgworker: logical replication launcher   
root       5306   5237  0 18:47 pts/0    00:00:00 grep --color=auto post
C.check wether the database is connect or not:
[root@master ~]# psql
psql: FATAL:  role "root" does not exist

[root@master ~]# su postgres
[postgres@master root]$ cd
[postgres@master ~]$ psql
psql (10.3)
Type "help" for help.

postgres=# show data_directory;
     data_directory     
------------------------
 /var/lib/pgsql/10/data
(1 row)
For More info about postgresql server start|stop|reload|restart
Step 5.Now we want to move the data's to data partition before do this stop the cluster.

A.Stop the Server as postgres user after installation of postgres don't use as a root user for start and stop the server use mostly postgres user
[postgres@master ~]$ /usr/pgsql-10/bin/pg_ctl -D /var/lib/pgsql/10/data/ stop
waiting for server to shut down.... done
server stopped
B.Move the Data location to data partition:
[postgres@master ~]$ rsync -av /var/lib/pgsql/10/data/* /DATA/
sending incremental file list
PG_VERSION
current_logfiles
pg_hba.conf
pg_ident.conf
postgresql.auto.conf
postgresql.conf
postmaster.opts
base/
base/1/
base/1/112
...
..
.
sent 41370578 bytes  received 18299 bytes  16555550.80 bytes/sec
total size is 41316241  speedup is 1.00
C.check the data directory on postgresql.conf file
[postgres@slave1 ~]$ cat /mnt/DATA/postgresql.conf |grep data_directory
#data_directory = 'ConfigDir'  # use data in another directory
As postgres user:
start the server as postgres you will get error for changing the ownership permission
[postgres@master DATA]$ /usr/pgsql-10/bin/pg_ctl -D /DATA start
waiting for server to start....2018-03-06 19:18:05.013 IST [5745] FATAL:  data directory "/mnt/DATA" has group or world access
2018-03-06 19:18:05.013 IST [5745] DETAIL:  Permissions should be u=rwx (0700).
 stopped waiting
pg_ctl: could not start server
Examine the log output.

Solution:
Now change the permission of postgres user like 700 then start the cluster.
[postgres@master ~]$  chmod 0700 /DATA/
[postgres@master ~]$ /usr/pgsql-10/bin/pg_ctl -D /mnt/DATA start
waiting for server to start....2018-03-06 19:22:47.515 IST [5920] LOG:  listening on IPv6 address "::1%1", port 5432
2018-03-06 19:22:47.515 IST [5920] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2018-03-06 19:22:47.517 IST [5920] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2018-03-06 19:22:47.521 IST [5920] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2018-03-06 19:22:47.660 IST [5920] LOG:  redirecting log output to logging collector process
2018-03-06 19:22:47.660 IST [5920] HINT:  Future log output will appear in directory "log".
 done
server started
Note:Now again check the postgres process and data direcory wether run or not,see the data directory changed from "/var/lib/pgsql/10/data/" to "/mnt/DATA"
[postgres@master DATA]$ ps -ef|grep postgres
root       5171   3519  0 18:44 pts/0    00:00:00 su postgres
postgres   5172   5171  0 18:44 pts/0    00:00:00 bash
root       5317   5237  0 18:48 pts/0    00:00:00 su postgres
postgres   5318   5317  0 18:48 pts/0    00:00:00 bash
root       5876   5843  0 19:22 pts/0    00:00:00 su postgres
postgres   5877   5876  0 19:22 pts/0    00:00:00 bash
postgres   5920      1  0 19:22 pts/0    00:00:00 /usr/pgsql-10/bin/postgres -D /mnt/DATA
postgres   5921   5920  0 19:22 ?        00:00:00 postgres: logger process   
postgres   5923   5920  0 19:22 ?        00:00:00 postgres: checkpointer process   
postgres   5924   5920  0 19:22 ?        00:00:00 postgres: writer process   
postgres   5925   5920  0 19:22 ?        00:00:00 postgres: wal writer process   
postgres   5926   5920  0 19:22 ?        00:00:00 postgres: autovacuum launcher process  
postgres   5927   5920  0 19:22 ?        00:00:00 postgres: stats collector process   
postgres   5928   5920  0 19:22 ?        00:00:00 postgres: bgworker: logical replication launcher  
postgres   5980   5877  0 19:28 pts/0    00:00:00 ps -ef
postgres   5981   5877  0 19:28 pts/0    00:00:00 grep --color=auto postgres
Step 6:Now check the database is connect or not,and check the data directory of postgres database
[postgres@master ~]$ psql
psql (10.3)
Type "help" for help.

postgres=# 

postgres=# show data_directory;
 data_directory 
----------------
 /mnt/DATA
(1 row)



Comments

Popular posts from this blog

PostgreSQL pgBadger

PostgreSQL Pgbadger Installation On Linux

How to configure Replication Manager (repmgr) ?

What's is the difference between streaming replication Vs hot standby vs warm standby ?

PostgreSQL Sequence