PostgreSQL - Backup & Point In Time Recovery

 In this post you will learn about how to restore a PostgreSQL database in Point in time.

  • Allow you to restore database to a specific moment in time PITR.
  • It make use of live database files and WAL files.
  • This method can only backup and restore the whole cluster, for individual database use pg_dump.
  • It can be done when the DB is online.

Step 1. If archive logs not enable then enable it, otherwise go to Step3.

Create Directory for archive logs

Step2. Restart the cluster

Pg_ctl status -D /Clusterpath

Step3. Insert some data into database

Create table and insert data into it

create table happy ( id integer, Ename varchar(20)) ;

Check if the data inserted properly.

Step4. Archive the logs

select pg_switch_wal();

Step 5. Take the base backup

I am taking the base backup at /postgres/postgres12.2/backup/basebackup

Step6- Stop DB and Delete the cluster.

#pg_ctl stop -D /postgres/postgres12.2/data/

Step 7 Restore the Database server

Make sure directories are there before importing. Restore Data folder and WAL folder.

Step8 — Start the server

./pg_ctl start -D /postgres/postgres12.2/data

Step9- PITR steps

  • Take the base backup
  • At this moment there are only 2 rows in HAPPY table, Insert more rows
  • Delete the data directory.
  • Restore the DATA directory from Backup
  • Create recovery.signal file and Add parameters

Comments

Popular posts from this blog

PostgreSQL - Architecture

Installing pgbadger on Linux for PostgreSQL log analysis