Hi, I got an assert failure when executing pg_terminate_backend to the process that waiting for WAL to be archived in non-exclusive backup mode.
TRAP: FailedAssertion("!(XLogCtl->Insert.nonExclusiveBackups > 0)", File: "xlog.c", Line: 11123) The one reproducing procedure is, 1. Start postgres with enabling the WAL archive 2. Execute pg_start_backup() 3. Revoke the access privileges of archive directory. (e.g., chown root:root /path/to/archive) 4. Execute pg_stop_backup() and hangs 5. Execute pg_terminate_backend() to the process that is waiting for WAL to be archived. Got the assertion failure. Perhaps we can reproduce it using pg_basebackup as well. I think the cause of this is that do_pg_abort_backup can be called even after we decremented XLogCtl->Insert.nonExclusiveBackups in do_pg_stop_backup(). That is, do_pg_abort_backup can be called with XLogCtl->Insert.nonExclusiveBackups = 0 when the transaction aborts after processed the nonExclusiveBackups (e.g, during waiting for WAL to be archived) The bug can happen in PostgreSQL 9.1 or higher that non-exclusive backup has been introduced, so we should back-patch to the all supported versions. I changed do_pg_abort_backup() so that it decrements nonExclusiveBackups only if > 0. Feedback is very welcome. Regards, -- Masahiko Sawada NIPPON TELEGRAPH AND TELEPHONE CORPORATION NTT Open Source Software Center
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 0513471..b0381e8 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -11165,8 +11165,15 @@ void do_pg_abort_backup(void) { WALInsertLockAcquireExclusive(); - Assert(XLogCtl->Insert.nonExclusiveBackups > 0); - XLogCtl->Insert.nonExclusiveBackups--; + + /* + * This can be called after we decremented nonExclusiveBackups in + * do_pg_stop_backup. So prevent it to be negative value. + */ +- Assert(XLogCtl->Insert.nonExclusiveBackups >= 0); + if (XLogCtl->Insert.nonExclusiveBackups > 0) + XLogCtl->Insert.nonExclusiveBackups--; + if (XLogCtl->Insert.exclusiveBackupState == EXCLUSIVE_BACKUP_NONE && XLogCtl->Insert.nonExclusiveBackups == 0)
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers