- You need to make a base backup of the master server from the standby server, this helps to bootstrap the standby server.
Stop the PostgreSQL severvice
[postgres@rac10-p data]$ pg_ctl stop -D /var/lib/pgsql/13/data
[postgres@rac10-p ~]$
[postgres@rac10-p 13]$ pwd
/var/lib/pgsql/13
[postgres@rac10-p 13]$ /usr/pgsql-13/bin/pg_ctl -D /var/lib/pgsql/13/data stop
waiting for server to shut down.... done
server stopped
[postgres@rac10-p ~]$ cd $PGDATA
[postgres@rac10-p data]$ ls -lrt
total 132
drwx------. 2 postgres postgres 4096 Aug 11 00:11 pg_twophase
drwx------. 2 postgres postgres 4096 Aug 11 00:11 pg_snapshots
drwx------. 2 postgres postgres 4096 Aug 11 00:11 pg_serial
drwx------. 2 postgres postgres 4096 Aug 11 00:11 pg_notify
drwx------. 2 postgres postgres 4096 Aug 11 00:11 pg_dynshmem
drwx------. 2 postgres postgres 4096 Aug 11 00:11 pg_commit_ts
-rw-------. 1 postgres postgres 3 Aug 11 00:11 PG_VERSION
drwx------. 2 postgres postgres 4096 Aug 11 00:11 pg_tblspc
drwx------. 2 postgres postgres 4096 Aug 11 00:11 pg_replslot
drwx------. 4 postgres postgres 4096 Aug 11 00:11 pg_multixact
-rw-------. 1 postgres postgres 28086 Aug 11 00:11 postgresql.conf
-rw-------. 1 postgres postgres 88 Aug 11 00:11 postgresql.auto.conf
-rw-------. 1 postgres postgres 1636 Aug 11 00:11 pg_ident.conf
-rw-------. 1 postgres postgres 4548 Aug 11 00:11 pg_hba.conf
drwx------. 2 postgres postgres 4096 Aug 11 00:11 pg_xact
drwx------. 3 postgres postgres 4096 Aug 11 00:11 pg_wal
drwx------. 2 postgres postgres 4096 Aug 11 00:11 pg_subtrans
drwx------. 5 postgres postgres 4096 Aug 11 00:11 base
drwx------. 2 postgres postgres 4096 Aug 11 00:12 log
-rw-------. 1 postgres postgres 30 Aug 11 08:52 current_logfiles
-rw-------. 1 postgres postgres 58 Aug 11 08:52 postmaster.opts
-rw-------. 1 postgres postgres 99 Aug 11 08:52 postmaster.pid
drwx------. 2 postgres postgres 4096 Aug 11 08:52 pg_stat
drwx------. 2 postgres postgres 4096 Aug 11 08:53 global
drwx------. 4 postgres postgres 4096 Aug 11 08:57 pg_logical
drwx------. 2 postgres postgres 4096 Aug 11 12:51 pg_stat_tmp
[postgres@rac10-p data]$ cd ..
[postgres@rac10-p 13]$ ls -lrt
total 12
drwx------. 2 postgres postgres 4096 Aug 9 03:25 backups
-rw-------. 1 postgres postgres 920 Aug 11 00:11 initdb.log
drwx------. 20 postgres postgres 4096 Aug 11 08:52 data
[postgres@rac10-p 13]$
I have already "data" folder in my server so just moving existing data folder to data_bkp
[postgres@rac10-p 13]$ mv data data_bkp
Create DATA directory once again :-
[postgres@rac10-p 13]$
[postgres@rac10-p 13]$ mkdir -p data/
[postgres@rac10-p 13]$ chmod 700 data/
[postgres@rac10-p 13]$ chown -R postgres:postgres data/
[postgres@rac10-p 13]$
[postgres@rac10-p 13]$
6)
Then user the pg_basebackup tool to take the base backup with the right ownership.
(the database system under i.e. postgres, within the postgres user account) and with the right permissions.
Below command is used to setting up the Replication
[postgres@rac10-p bin]$ pg_basebackup -h 192.168.1.43 -U repuser -p 5432 -D /var/lib/pgsql/13/data -Fp -Xs -P -R
25254/25254 kB (100%), 1/1 tablespace
With above command, Slave server will connect to the Master (Primary) server and will copy all the data directory from Master server. The connection will be trough a PostgreSQL database user, in our case this user is repuser. And at the end of the command we created the replication slot. What is a replication slot? Basically, the Master server is able to delete the WAL files if it is not needed anymore. But maybe the Slave server did not receive and applied it yet. In this case, the replication will fail. But if we have the replication slot configured, this process will not let the Master server delete the WAL files which did not receive by Slave server yet. At the end the standby.signal file has been created which make it the replica.
Crosscheck the data with is restored or not ..
[postgres@rac10-p bin]$ cd /var/lib/pgsql/13/data
[postgres@rac10-p data]$ ls -lrt
total 268
-rw-------. 1 postgres postgres 224 Aug 11 13:03 backup_label
-rw-------. 1 postgres postgres 28086 Aug 11 13:03 postgresql.conf
drwx------. 2 postgres postgres 4096 Aug 11 13:03 pg_twophase
drwx------. 2 postgres postgres 4096 Aug 11 13:03 pg_snapshots
drwx------. 4 postgres postgres 4096 Aug 11 13:03 pg_multixact
drwx------. 2 postgres postgres 4096 Aug 11 13:03 pg_commit_ts
drwx------. 3 postgres postgres 4096 Aug 11 13:03 pg_wal
drwx------. 2 postgres postgres 4096 Aug 11 13:03 pg_notify
-rw-------. 1 postgres postgres 4619 Aug 11 13:03 pg_hba.conf
drwx------. 2 postgres postgres 4096 Aug 11 13:03 log
drwx------. 5 postgres postgres 4096 Aug 11 13:03 base
drwx------. 2 postgres postgres 4096 Aug 11 13:03 pg_xact
-rw-------. 1 postgres postgres 3 Aug 11 13:03 PG_VERSION
drwx------. 2 postgres postgres 4096 Aug 11 13:03 pg_tblspc
drwx------. 2 postgres postgres 4096 Aug 11 13:03 pg_subtrans
drwx------. 2 postgres postgres 4096 Aug 11 13:03 pg_stat_tmp
drwx------. 2 postgres postgres 4096 Aug 11 13:03 pg_stat
drwx------. 2 postgres postgres 4096 Aug 11 13:03 pg_serial
drwx------. 2 postgres postgres 4096 Aug 11 13:03 pg_replslot
drwx------. 4 postgres postgres 4096 Aug 11 13:03 pg_logical
-rw-------. 1 postgres postgres 1636 Aug 11 13:03 pg_ident.conf
drwx------. 2 postgres postgres 4096 Aug 11 13:03 pg_dynshmem
drwx------. 2 postgres postgres 4096 Aug 11 13:03 global
-rw-------. 1 postgres postgres 30 Aug 11 13:03 current_logfiles
-rw-------. 1 postgres postgres 0 Aug 11 13:03 standby.signal
-rw-------. 1 postgres postgres 478 Aug 11 13:03 postgresql.auto.conf
-rw-------. 1 postgres postgres 135417 Aug 11 13:03 backup_manifest
[postgres@rac10-p data]$ cat postgresql.auto.conf
# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command.
archive_mode = 'on'
archive_command = 'test ! -f /backup/PostgreSQL13_arch/%f && cp %p //backup/PostgreSQL13_arch/%f'
listen_addresses = '*'
primary_conninfo = 'user=repuser passfile=''/var/lib/pgsql/.pgpass'' channel_binding=prefer host=192.168.1.43 port=5432 sslmode=prefer sslcompression=0 ssl_min_protocol_version=TLSv1.2 gssencmode=prefer krbsrvname=postgres target_session_attrs=any'
Check the PostgreSQL service start or not ..
[postgres@rac10-p data]$ ps -ef| grep postgres
root 10000 9940 0 11:48 pts/0 00:00:00 su - postgres
postgres 10001 10000 0 11:48 pts/0 00:00:00 -bash
postgres 12991 10001 0 13:06 pts/0 00:00:00 ps -ef
postgres 12992 10001 0 13:06 pts/0 00:00:00 grep --color=auto postgres
[postgres@rac10-p data]$
Start the PostgreSQL service as below:-
[postgres@rac10-p data]$ pg_ctl start -D /var/lib/pgsql/13/data
waiting for server to start....2024-08-11 13:06:17.934 IST [13003] LOG: redirecting log output to logging collector process
2024-08-11 13:06:17.934 IST [13003] HINT: Future log output will appear in directory "log".
done
server started
[postgres@rac10-p data]$ ps -ef| grep postgres
root 10000 9940 0 11:48 pts/0 00:00:00 su - postgres
postgres 10001 10000 0 11:48 pts/0 00:00:00 -bash
postgres 13003 1 0 13:06 ? 00:00:00 /usr/pgsql-13/bin/postgres -D /var/lib/pgsql/13/data
postgres 13004 13003 0 13:06 ? 00:00:00 postgres: logger
postgres 13005 13003 0 13:06 ? 00:00:00 postgres: startup recovering 000000010000000000000004
postgres 13006 13003 0 13:06 ? 00:00:00 postgres: checkpointer
postgres 13007 13003 0 13:06 ? 00:00:00 postgres: background writer
postgres 13008 13003 0 13:06 ? 00:00:00 postgres: stats collector
postgres 13009 13003 1 13:06 ? 00:00:00 postgres: walreceiver streaming 0/4000060
postgres 13010 10001 0 13:06 pts/0 00:00:00 ps -ef
postgres 13011 10001 0 13:06 pts/0 00:00:00 grep --color=auto postgres
[postgres@rac10-p data]$
Check receiver background process started or not :-
[postgres@rac10-p data]$ ps -eaf | grep receiver
postgres 13009 13003 0 13:06 ? 00:00:00 postgres: walreceiver streaming 0/4000060
postgres 13021 10001 0 13:07 pts/0 00:00:00 grep --color=auto receiver
[postgres@rac10-p data]$
[postgres@rac10-p data]$
[postgres@rac10-p data]$ psql
psql (13.16)
Type "help" for help.
postgres=# select pg_is_in_recovery();
pg_is_in_recovery
-------------------
t
(1 row)
No comments:
Post a Comment