Thread: What is the correct steps if tar process is killed during pg_start_backup() and pg_stop_backup()

Hello everyone, 

I have goolged this issued for some time, but I do not find much valuable information.

Here is my questions, I would like to know when I invoke pg_start_backup() and execute tar for backup my cluster data, but due to some reasons, tar is stopped. Q1) Should I invoke pg_stop_backup() to complete the procedure if I do not want to re-tar again? Q2) What if I decide to re-tar again my data, should I need to invoke pg_stop_backup() first and perform pg_start_backup() -> tar -> pg_stop_backup()? 

Yours sincerely,

Z.H Shin


Shih Théo wrote:
> I have goolged this issued for some time, but I do not find much valuable information.
> 
> Here is my questions, I would like to know when I invoke pg_start_backup() and execute tar for backup
> my cluster data, but due to some reasons, tar is stopped.

> Q1) Should I invoke pg_stop_backup() to
> complete the procedure if I do not want to re-tar again?

Yes, otherwise PostgreSQL remains in online backup mode.

> Q2) What if I decide to re-tar again my data,
> should I need to invoke pg_stop_backup() first and perform pg_start_backup() -> tar ->
> pg_stop_backup()?

No, that is not necessary.

Yours,
Laurenz Albe


On Wed, Jul 15, 2015 at 6:10 AM, Albe Laurenz <laurenz.albe@wien.gv.at> wrote:
> Q2) What if I decide to re-tar again my data,
> should I need to invoke pg_stop_backup() first and perform pg_start_backup() -> tar ->
> pg_stop_backup()?

No, that is not necessary.

I'd say that although it is not necessary, it is a good practice. As you are going to do the copy all over again, better reduce the window required for recovery. If you don't call pg_stop_backup, the restore will consider the first needed WAL file to be the one returned by the call of pg_start_backup; if this call and the tar error are not very closer in time and you have a lot of activity in the system that generated many WAL files, then the restore will require more WAL files then it is actually necessary.

Besides, if you are doing an script for this procedure, you'd better have the script handle the error and call the pg_stop_backup directly.

At last, any reason for not using pg_basebackup in this case? I'd say it is preferred over pg_start_backup+tar+pg_stop_backup, and less error prone.

Regards,
--
Matheus de Oliveira


Thank you for reply. This helps me a lot. 
The only reason why I use  pg_start_backup rather than pg_basebackup is because the db system in my company is still under 8.3.
I think I would try to convince my chief to upgrate it.

Regards,

Z.H. Shih

2015-07-15 19:50 GMT+08:00 Matheus de Oliveira <matioli.matheus@gmail.com>:

On Wed, Jul 15, 2015 at 6:10 AM, Albe Laurenz <laurenz.albe@wien.gv.at> wrote:
> Q2) What if I decide to re-tar again my data,
> should I need to invoke pg_stop_backup() first and perform pg_start_backup() -> tar ->
> pg_stop_backup()?

No, that is not necessary.

I'd say that although it is not necessary, it is a good practice. As you are going to do the copy all over again, better reduce the window required for recovery. If you don't call pg_stop_backup, the restore will consider the first needed WAL file to be the one returned by the call of pg_start_backup; if this call and the tar error are not very closer in time and you have a lot of activity in the system that generated many WAL files, then the restore will require more WAL files then it is actually necessary.

Besides, if you are doing an script for this procedure, you'd better have the script handle the error and call the pg_stop_backup directly.

At last, any reason for not using pg_basebackup in this case? I'd say it is preferred over pg_start_backup+tar+pg_stop_backup, and less error prone.

Regards,
--
Matheus de Oliveira