-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 06/01/2013 02:43 AM, Christoph Moench-Tegeder wrote:
> ## Joe Conway (mail@joeconway.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.
Joe
- --
Joe Conway
credativ LLC: http://www.credativ.us
Linux, PostgreSQL, and general Open Source
Training, Service, Consulting, & 24x7 Support
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQIcBAEBAgAGBQJRqg8eAAoJEDfy90M199hlm2wP/ihMBBOvhT+fbXHcZj6A4wW9
/d3N2KZ6tRZE6Sb6W6ouy8jdMjgQsVfgrfHh7Ts0NS1cu6k2mTgbjxfi2JygjFzh
PLpj4b9cRMYRLaeEj5Ik69HM/IMg6gLW5WM2hRrRiXopbxXIK8qR37rQmjWM2aYU
OJ+qlKKx1K5d/VS6bmxveprAMzplR/U9OhEOteFo+A2ODl7Vsd9wL2NIa6DyiVvq
BsM0QEJjkFZSkKvrZyWctO6v6j/ccNgo2xUJMyPAOVFxabOTw1CMUjdVDM9Im61/
c+AfchWCVHaLOGMY7KlGUmNhHuWcIY23u2sucn5JMpNbOmJRyexwsXCYIkBZXZdP
OpaMq1w37aY2HwtrSpAgzUditQqoMjbq0PVgwoTu8P+pYbwToNclXW/TGq2zeDA3
mKWUCGGbSKfjoQks0yMNho05YIJkCkZeTDRMTuXN6k2Gf3WgqRyNwDfjnT0+YFZn
Su93JZ5gE/vDugf7o47OeyrLTXcqVt3WgTCae7A70Vi2nenq6jWVCCKqTz9E7Ct6
I3Vhjal0dxpd6pi0sfI6msRAnPKoxfu9vjXdDuRf+NbzxpG8Gwb+HDaZzE/ffqz8
/473B/ZgNqCIXd9/loCTVdnewSaUDNuGqNxmmCMtFpmEC1SZ0zZZhImeLQFkA17k
mwSGNqxchm8J/4ExM/n9
=x1tN
-----END PGP SIGNATURE-----