Giter Site home page Giter Site logo

postgres's Introduction

postgres

Postgres PITR Backup & Restore Demo Configuration

Continuous Archiving and Point-in-Time Recovery (PITR)

Cick here for Video Demo https://youtu.be/WZps_MYYvV8

Postgres WAL Archiving

  1. Create the WAL & backup Directory and add necessary Permisson
bash~ mkdir -p  /var/lib/pgsql/wals/
bash~ mkdir -p  /var/lib/pgsql/backups/
bash~ chown postgres:postgres -R /var/lib/pgsql/backups/
bash~ chown postgres:postgres -R /var/lib/pgsql/wals/
  1. Edit the postgresql.conf with postgres user and add the below changes
wal_level=archive
archive_mode=on
archive_command = 'test ! -f /var/lib/pgsql/wals/%f && cp %p /var/lib/pgsql/wals/%f'
  1. Restart the database

bash~ service postgresql restart

  1. Prepare for the basebackup
su - postgres
psql -c "SELECT pg_start_backup('label');" postgres 
tar -C /var/lib/pgsql/data/ -czvf /var/lib/pgsql/backups/pg_basebackup_backup.tar.gz .
psql -c "SELECT pg_stop_backup();" postgres

Add Data to PostgreSQL

bash~  su - postgres
bash~  createdb mydb
bash~  psql -s mydb

Testing Restore

  1. Stop the postgres
bash~ /etc/init.d/postgresql stop
  1. Remove the data folder and Initilize the DB
bash~ cd /var/lib/pgsql/
bash~ rm -rf data/
  1. Initilaize the Database
bash~ /etc/init.d/postgresql initdb
bash~ /etc/init.d/postgresql start

Restore from WAL Archiving

  1. Stop the Postgres Server
bash~ /etc/init.d/postgresql stop
  1. Extract the Basebackup...
bash~  tar xvf /var/lib/pgsql/backups/pg_basebackup_backup.tar.gz -C /var/lib/pgsql/data
  1. Create recovery.conf with the below content and check the permission also
bash~ cd /var/lib/pgsql/data
bash~ cat recovery.conf 
restore_command = 'cp /var/lib/pgsql/wals/%f %p'
  1. Restart the Postgres DB
bash~ /etc/init.d/postgresql start
  1. Upon completion of the recovery process, the server will rename recovery.conf to recovery.done
bash~ cd /var/lib/pgsql/data
bash~ cat recover.done

postgres's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

possebon crbll0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.