PostgreSQL Point In Time Recovery(PITR)

Point In Time Recovery :


need: one last basebackup and also enable archive before basebackup

how to setup basebackup


step1: pg_hba.conf

ipv4 and repliaction entery

goto data directory

vi pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             192.168.1.221/32        trust
host    all             all             127.0.0.1/32            ident
# IPv6 local connections:
host    all             all             ::1/128                 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             192.168.1.222/32        trust

step2: vi postgresql.conf

listern_address=*
archive_mode=on
archive_command='cp %p /arch/%f'
wal_level=replica
full_page_writes=on
max_wal_sender=6
wal_keep_segement=500
max_replication_slot=2
log_statement='all'

STEP3: restart the server
su - postgres
cd /usr/pgsql-11/bin
./pg_ctl -D /var/lib/pgsql/11/data restart

step4: run pg_basebackup utility tool

pg_basebackup Options:

-P progres
-v verbose
-c checkpoint
-X wals
-R create recovery.conf file
-T tablespace
-T curent_tablespace_directory=backup_tablespace_directory

without tablespace:

./pg_basebackup -h 192.168.1.21 -p 5432 -P -v -X stream or fetch  -c fast -R -Fp -D /backup/bk_1

with tablespace

./pg_basebackup -h 192.168.1.221 -p 5432 -P -v -c fast -X stream -R -T /tbs_1=/tbs_new1 -T /tbs_2=/tbs_new2mn  -Fp -D /backup/bk_`date +%d%m%y%H%M%S`


step5: create some tables and drop tables

step6: take last basebackup and edit recovery.conf file,postgresql.conf file

goto backup directory

vi recovery.conf

restore_command = 'cp /arch/%f %p'
recovery_target_time = '2020-04-16 19:34:24.31'
trigger_file = '/etc/error.conf'

vi postgresql.conf

port=3456 //change only same machine
#archive_command='cp %p /arch/%f'  //disable archive_command
hot_standby=on //enable (remove # )

step7:start the backup server
su - postgres
cd /usr/pgsql-11/bin
./pg_ctl -D /backup/bk_1 start
./psql
postgres=#select pg_is_in_recovery(); //check t=true f=false
t
step8:take particular table dump backup and restore main server

Comments

Popular posts from this blog

PostgreSQL pg_pool-II Installation and Configuration

PostgreSQL Migration Using MTK

PostgreSQL Pages and Tuples