Skip to content

Commit c84c070

Browse files
committed
added conf file setup instructions
1 parent 619614d commit c84c070

File tree

4 files changed

+165
-5
lines changed

4 files changed

+165
-5
lines changed

install.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

pgpool.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# PGPool -II Install and Setup
2+
3+
## Install the package ( CentOS 7 )
4+
5+
```
6+
yum install -y http://www.pgpool.net/yum/rpms/4.1/redhat/rhel-7-x86_64/pgpool-II-release-4.1-1.noarch.rpm
7+
yum install pgpool-II-pg12-devel pgpool-II-pg12-extensions pgpool-I2-pg12 pgpool-II-pg12-debuginfo -y
8+
systemctl enable pgpool.service
9+
systemctl restart pgpool.service
10+
```
11+
12+
Configure pgpool.conf
13+
14+
```
15+
# - Backend Connection Settings -
16+
17+
backend_hostname0 = '165.227.44.48'
18+
# Host name or IP address to connect to for backend 0
19+
backend_port0 = 5432
20+
# Port number for backend 0
21+
backend_weight0 = 1
22+
# Weight for backend 0 (only in load balancing mode)
23+
backend_data_directory0 = '/var/lib/pgsql/12/data'
24+
# Data directory for backend 0
25+
backend_flag0 = 'ALLOW_TO_FAILOVER'
26+
# Controls various backend behavior
27+
# ALLOW_TO_FAILOVER, DISALLOW_TO_FAILOVER
28+
# or ALWAYS_MASTER
29+
backend_application_name0 = 'server0'
30+
# walsender's application_name, used for "show pool_nodes" command
31+
32+
backend_hostname1 = '178.128.228.63'
33+
backend_port1 = 5432
34+
backend_weight1 = 1
35+
backend_data_directory1 = '/var/lib/pgsql/12/data'
36+
backend_flag1 = 'ALLOW_TO_FAILOVER'
37+
backend_application_name1 = 'server1'
38+
39+
```
40+
41+
Enable Load balance
42+
43+
```
44+
#------------------------------------------------------------------------------
45+
# LOAD BALANCING MODE
46+
#------------------------------------------------------------------------------
47+
48+
load_balance_mode = on
49+
# Activate load balancing mode
50+
# (change requires restart)
51+
```

postres-install.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Install pgsql 12 on CentOS 7
2+
3+
```
4+
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
5+
yum install postgresql12 postgresql12-contrib postgresql12-server -y
6+
/usr/pgsql-12/bin/postgresql-12-setup initdb
7+
systemctl enable postgresql-12;
8+
systemctl start postgresql-12
9+
su - postgres
10+
psql
11+
```

replication.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Stream Replication Setup for PGSQL
2+
3+
1. Install postgres in the primary and standby server as usual. This requires only configure, make and make install.
4+
2. Create the initial database cluster in the primary server as usual, using initdb.
5+
3. Create an user named replication with REPLICATION privileges.
6+
7+
```
8+
CREATE ROLE replication WITH REPLICATION PASSWORD 'password' LOGIN
9+
```
10+
4. Set up connections and authentication on the primary so that the standby server can successfully connect to the replication pseudo-database on the primary.
11+
$ $EDITOR postgresql.conf
12+
13+
listen_addresses = '192.168.0.10'
14+
$ $EDITOR pg_hba.conf
15+
16+
# The standby server must connect with a user that has replication privileges.
17+
# TYPE DATABASE USER ADDRESS METHOD
18+
host replication replication 192.168.0.20/32 md5
19+
20+
The following parameters on the master are considered as mandatory when setting up streaming replication.
21+
22+
archive_mode : Must be set to ON to enable archiving of WALs.
23+
wal_level : Must be at least set to hot_standby until version 9.5 or replica in the later versions.
24+
max_wal_senders : Must be set to 3 if you are starting with one slave. For every slave, you may add 2 wal senders.
25+
wal_keep_segments : Set the WAL retention in pg_xlog (until PostgreSQL 9.x) and pg_wal (from PostgreSQL 10). Every WAL requires 16MB of space unless you have explicitly modified the WAL segment size. You may start with 100 or more depending on the space and the amount of WAL that could be generated during a backup.
26+
archive_command : This parameter takes a shell command or external programs. It can be a simple copy command to copy the WAL segments to another location or a script that has the logic to archive the WALs to S3 or a remote backup server.
27+
listen_addresses : Specifies which IP interfaces could accept connections. You could specify all the TCP/IP addresses on which the server could listen to connections from client. ‘*’ means all available IP interfaces. The default : localhost allows only local TCP/IP connections to be made to the postgres server.
28+
hot_standby : Must be set to ON on standby/replica and has no effect on the master. However, when you setup your replication, parameters set on the master are automatically copied. This parameter is important to enable READS on slave. Otherwise, you cannot run your SELECT queries against slave.
29+
30+
$ $EDITOR postgresql.conf
31+
32+
# To enable read-only queries on a standby server, wal_level must be set to
33+
# "hot_standby". But you can choose "archive" if you never connect to the
34+
# server in standby mode.
35+
wal_level = hot_standby
36+
37+
# Set the maximum number of concurrent connections from the standby servers.
38+
max_wal_senders = 5
39+
40+
# To prevent the primary server from removing the WAL segments required for
41+
# the standby server before shipping them, set the minimum number of segments
42+
# retained in the pg_xlog directory. At least wal_keep_segments should be
43+
# larger than the number of segments generated between the beginning of
44+
# online-backup and the startup of streaming replication. If you enable WAL
45+
# archiving to an archive directory accessible from the standby, this may
46+
# not be necessary.
47+
wal_keep_segments = 32
48+
49+
# Enable WAL archiving on the primary to an archive directory accessible from
50+
# the standby. If wal_keep_segments is a high enough number to retain the WAL
51+
# segments required for the standby server, this is not necessary.
52+
archive_mode = on
53+
archive_command = 'cp %p /path_to/archive/%f'
54+
55+
ALTER SYSTEM SET wal_level TO 'hot_standby';
56+
ALTER SYSTEM SET archive_mode TO 'ON';
57+
ALTER SYSTEM SET max_wal_senders TO '5';
58+
ALTER SYSTEM SET wal_keep_segments TO '10';
59+
ALTER SYSTEM SET listen_addresses TO '*';
60+
ALTER SYSTEM SET hot_standby TO 'ON';
61+
62+
psql -U postgres -p 5432 -c "select pg_reload_conf()"
63+
64+
On Slave
65+
66+
pg_basebackup -h 192.168.0.28 -U replicator -p 5432 -D $PGDATA -P -Xs -R
67+
68+
Potential error
69+
70+
pg_basebackup: error: directory "/var/lib/pgsql/12/data" exists but is not empty
71+
72+
Create a recovery command file in the standby server; the following parameters are required for streaming replication.
73+
$ $EDITOR recovery.conf
74+
# Note that recovery.conf must be in $PGDATA directory.
75+
# It should NOT be located in the same directory as postgresql.conf
76+
77+
# Specifies whether to start the server as a standby. In streaming replication,
78+
# this parameter must to be set to on.
79+
standby_mode = 'on'
80+
81+
# Specifies a connection string which is used for the standby server to connect
82+
# with the primary.
83+
primary_conninfo = 'host=192.168.0.10 port=5432 user=replication password=password'
84+
85+
# Specifies a trigger file whose presence should cause streaming replication to
86+
# end (i.e., failover).
87+
trigger_file = '/path_to/trigger'
88+
89+
# Specifies a command to load archive segments from the WAL archive. If
90+
# wal_keep_segments is a high enough number to retain the WAL segments
91+
# required for the standby server, this may not be necessary. But
92+
# a large workload can cause segments to be recycled before the standby
93+
# is fully synchronized, requiring you to start again from a new base backup.
94+
restore_command = 'cp /path_to/archive/%f "%p"'
95+
96+
Start postgres in the standby server. It will start streaming replication.
97+
98+
How to do failover
99+
Create the trigger file in the standby after the primary fails.
100+
How to stop the primary or the standby server
101+
Shut down it as usual (pg_ctl stop).
102+
How to restart streaming replication after failover
103+
Repeat the operations from 6th; making a fresh backup, some configurations and starting the original primary as the standby. The primary server doesn't need to be stopped during these operations.

0 commit comments

Comments
 (0)