How do I restore a database from postgres logs?

Asked

Viewed 128 times

2

I have the database logs I get through the commands pg_start_backupand pg_stop_backup. I wonder how do I restore the bank through them?

Thank you!

  • Welcome to the OS. What version of Postgresql are you using?

  • Thanks. I’m using version 9.4.

1 answer

0

I understand that you have a Postgresql 9.4 running and want to restore the database from a backup made.

Just to remind you that the pg_start_backup prevents writing to the folder where the database is located, to maintain the consistency of the data.

To perform a backup and restore it using pg_start_backup, you need:

1 - Execute `select pg_start_backup('label');`
2 - Execute o `rsync` da sua pasta cluster (por padrão na versão 9.4 é a: `/var/lib/postgresql/9.4/main/` se não me engano)
3 - Execute `select pg_stop_backup();`
4 - Copie todos os logs desde do inicio do `pg_start_backup` até depois que voce tenha executado o `pg_stop_backup`. Quando falo logs me refiro aos wal_files (Você pode checar aonde eles estão sendo armazenados através do `archive_command` no seu `postgresql.conf`).

When you have performed the rsync + copy wal_files to the new server, you can already start Postgres.

Always remember to follow the logs to know if there was an error.

EDIT: USING THE pg_basebackup

I always do backups and restore my banks using the pg_basebackup. In my opinion it is better and easier to use.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.