Re: pg_start_backup and pg_stop_backup Re: Re: [COMMITTERS] pgsql: Make CheckRequiredParameterValues() depend upon correct - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: pg_start_backup and pg_stop_backup Re: Re: [COMMITTERS] pgsql: Make CheckRequiredParameterValues() depend upon correct
Date
Msg-id 4BD953A6.70409@enterprisedb.com
Whole thread Raw
In response to Re: pg_start_backup and pg_stop_backup Re: Re: [COMMITTERS] pgsql: Make CheckRequiredParameterValues() depend upon correct  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: pg_start_backup and pg_stop_backup Re: Re: [COMMITTERS] pgsql: Make CheckRequiredParameterValues() depend upon correct  (Robert Haas <robertmhaas@gmail.com>)
Re: pg_start_backup and pg_stop_backup Re: Re: [COMMITTERS] pgsql: Make CheckRequiredParameterValues() depend upon correct  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Tom Lane wrote:
> Yeah.  ISTM the real bottom line here is that we have only a weak grasp
> on how these features will end up being used; or for that matter what
> the common error scenarios will be.  I think that for the time being
> we should err on the side of being permissive.  We can tighten things
> up and add more nanny-ism in the warnings later on, when we have
> more field experience.

Ok, here's a proposed patch. Per discussion, it relaxes the checks in
pg_start/stop_backup() so that they can be used as long as wal_level >=
'archive', even if archiving is disabled.

If archiving is not enabled, it can't wait for the files to be archived.
Instead, it prints a notice:

NOTICE:  WAL archiving is not enabled, you must ensure that all required
WAL segments are streamed or copied through other means to restore the
backup

That is instead of the usual notice when archiving is enabled:

NOTICE: pg_stop_backup complete, all required WAL segments have been
archived

--
  Heikki Linnakangas
  EnterpriseDB   http://www.enterprisedb.com
*** a/src/backend/access/transam/xlog.c
--- b/src/backend/access/transam/xlog.c
***************
*** 8200,8217 **** pg_start_backup(PG_FUNCTION_ARGS)
                   errmsg("recovery is in progress"),
                   errhint("WAL control functions cannot be executed during recovery.")));

!     if (!XLogArchivingActive())
!         ereport(ERROR,
!                 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
!                  errmsg("WAL archiving is not active"),
!                  errhint("archive_mode must be enabled at server start.")));
!
!     if (!XLogArchiveCommandSet())
          ereport(ERROR,
                  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
!                  errmsg("WAL archiving is not active"),
!                  errhint("archive_command must be defined before "
!                          "online backups can be made safely.")));

      backupidstr = text_to_cstring(backupid);

--- 8200,8210 ----
                   errmsg("recovery is in progress"),
                   errhint("WAL control functions cannot be executed during recovery.")));

!     if (!XLogIsNeeded())
          ereport(ERROR,
                  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
!                  errmsg("WAL level not sufficient for making an online backup"),
!                  errhint("wal_level must be set to 'archive' or 'hot_standby' at server start.")));

      backupidstr = text_to_cstring(backupid);

***************
*** 8399,8409 **** pg_stop_backup(PG_FUNCTION_ARGS)
                   errmsg("recovery is in progress"),
                   errhint("WAL control functions cannot be executed during recovery.")));

!     if (!XLogArchivingActive())
          ereport(ERROR,
                  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
!                  errmsg("WAL archiving is not active"),
!                  errhint("archive_mode must be enabled at server start.")));

      /*
       * OK to clear forcePageWrites
--- 8392,8402 ----
                   errmsg("recovery is in progress"),
                   errhint("WAL control functions cannot be executed during recovery.")));

!     if (!XLogIsNeeded())
          ereport(ERROR,
                  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
!                  errmsg("WAL level not sufficient for making an online backup"),
!                  errhint("wal_level must be set to 'archive' or 'hot_standby' at server start.")));

      /*
       * OK to clear forcePageWrites
***************
*** 8511,8526 **** pg_stop_backup(PG_FUNCTION_ARGS)
      CleanupBackupHistory();

      /*
!      * Wait until both the last WAL file filled during backup and the history
!      * file have been archived.  We assume that the alphabetic sorting
!      * property of the WAL files ensures any earlier WAL files are safely
!      * archived as well.
       *
       * We wait forever, since archive_command is supposed to work and we
       * assume the admin wanted his backup to work completely. If you don't
       * wish to wait, you can set statement_timeout.  Also, some notices are
       * issued to clue in anyone who might be doing this interactively.
       */
      XLByteToPrevSeg(stoppoint, _logId, _logSeg);
      XLogFileName(lastxlogfilename, ThisTimeLineID, _logId, _logSeg);

--- 8504,8530 ----
      CleanupBackupHistory();

      /*
!      * If archiving is enabled, wait for all the required WAL files to be
!      * archived before returning. If archiving isn't enabled, the required
!      * WAL needs to be transported via streaming replication (hopefully
!      * with wal_keep_segments set high enough), or some more exotic
!      * mechanism like polling and copying files from pg_xlog with script.
!      * We have no control over those mechanisms, so it's up to the user to
!      * ensure that he gets all the required WAL.
!      *
!      * We wait until both the last WAL file filled during backup and the
!      * history file have been archived, and assume that the alphabetic
!      * sorting property of the WAL files ensures any earlier WAL files are
!      * safely archived as well.
       *
       * We wait forever, since archive_command is supposed to work and we
       * assume the admin wanted his backup to work completely. If you don't
       * wish to wait, you can set statement_timeout.  Also, some notices are
       * issued to clue in anyone who might be doing this interactively.
       */
+     if (XLogArchivingActive())
+     {
+         /* XXX: fix indentation before committing */
      XLByteToPrevSeg(stoppoint, _logId, _logSeg);
      XLogFileName(lastxlogfilename, ThisTimeLineID, _logId, _logSeg);

***************
*** 8559,8564 **** pg_stop_backup(PG_FUNCTION_ARGS)
--- 8563,8572 ----

      ereport(NOTICE,
              (errmsg("pg_stop_backup complete, all required WAL segments have been archived")));
+     }
+     else
+         ereport(NOTICE,
+                 (errmsg("WAL archiving is not enabled, you must ensure that all required WAL segments are streamed or
copiedthrough other means to restore the backup"))); 

      /*
       * We're done.  As a convenience, return the ending WAL location.

pgsql-hackers by date:

Previous
From: Simon Riggs
Date:
Subject: Re: Toast rel options
Next
From: Teodor Sigaev
Date:
Subject: Choosing between seqscan and bitmap scan