On 06/01/2013 02:43 AM, Christoph Moench-Tegeder wrote:
## Joe Conway (email@example.com
However there is a period of time after pg_start_backup() is
first executed to when it completes, during which backup_label
file does not exist yet, but the backup has essentially been
started. Is there any way to detect this state?
When I did some research on the very same question just a few
weeks ago, I settled for external locks (lockfile,
pg_advisory_lock(), ..., depending on your exact situation) around
the backup-taking code.
Right, and an external lockfile is good except there is a race condition.
Proc1, t0) SELECT pg_start_backup(...) -- command starts to execute
Proc2, t1) lay down a lockfile (or other mechanism)
Proc2, t2) check for running backup by looking for backup_label
Proc1, t3) SELECT pg_start_backup(...) -- command finishes,
-- backup_label created
So you are forced to sleep for some arbitrary time just in case
pg_start_backup() has started but not completed at the point when you
try to lock out the backup.
Or better (at least my solution), is you check pg_stat_activity for
the presence of a running "SELECT pg_start_backup(...)" command prior
to checking for backup_label. I imagine there is still a small race
condition there but at least much smaller.
credativ LLC: http://www.credativ.us
Linux, PostgreSQL, and general Open Source
Training, Service, Consulting, & 24x7 Support