]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Refactor code retrieving string for RecoveryPauseState
authorMichael Paquier <michael@paquier.xyz>
Fri, 6 Mar 2026 02:53:23 +0000 (11:53 +0900)
committerMichael Paquier <michael@paquier.xyz>
Fri, 6 Mar 2026 02:53:23 +0000 (11:53 +0900)
This refactoring is going to be useful in an upcoming commit, to avoid
some code duplication with the function pg_get_wal_replay_pause_state(),
that returns a string for the recovery pause state.

Refactoring opportunity noticed while hacking on a different patch.

Discussion: https://postgr.es/m/CABPTF7W+Nody-+P9y4PNk37-QWuLpfUrEonHuEhrX+Vx9Kq+Kw@mail.gmail.com

src/backend/access/transam/xlogfuncs.c

index 2efe4105efba4aad2d879e5ee3330ad82d15b24c..785430558953b713928b6ca263d196422fa8ed87 100644 (file)
@@ -44,6 +44,33 @@ static StringInfo tablespace_map = NULL;
 /* Session-level context for the SQL-callable backup functions */
 static MemoryContext backupcontext = NULL;
 
+
+/*
+ * Return a string constant representing the recovery pause state. This is
+ * used in system functions and views, and should *not* be translated.
+ */
+static const char *
+GetRecoveryPauseStateString(RecoveryPauseState pause_state)
+{
+       const char *statestr = NULL;
+
+       switch (pause_state)
+       {
+               case RECOVERY_NOT_PAUSED:
+                       statestr = "not paused";
+                       break;
+               case RECOVERY_PAUSE_REQUESTED:
+                       statestr = "pause requested";
+                       break;
+               case RECOVERY_PAUSED:
+                       statestr = "paused";
+                       break;
+       }
+
+       Assert(statestr != NULL);
+       return statestr;
+}
+
 /*
  * pg_backup_start: set up for taking an on-line backup dump
  *
@@ -592,7 +619,7 @@ pg_is_wal_replay_paused(PG_FUNCTION_ARGS)
 Datum
 pg_get_wal_replay_pause_state(PG_FUNCTION_ARGS)
 {
-       char       *statestr = NULL;
+       RecoveryPauseState state;
 
        if (!RecoveryInProgress())
                ereport(ERROR,
@@ -600,22 +627,10 @@ pg_get_wal_replay_pause_state(PG_FUNCTION_ARGS)
                                 errmsg("recovery is not in progress"),
                                 errhint("Recovery control functions can only be executed during recovery.")));
 
-       /* get the recovery pause state */
-       switch (GetRecoveryPauseState())
-       {
-               case RECOVERY_NOT_PAUSED:
-                       statestr = "not paused";
-                       break;
-               case RECOVERY_PAUSE_REQUESTED:
-                       statestr = "pause requested";
-                       break;
-               case RECOVERY_PAUSED:
-                       statestr = "paused";
-                       break;
-       }
+       state = GetRecoveryPauseState();
 
-       Assert(statestr != NULL);
-       PG_RETURN_TEXT_P(cstring_to_text(statestr));
+       /* get the recovery pause state */
+       PG_RETURN_TEXT_P(cstring_to_text(GetRecoveryPauseStateString(state)));
 }
 
 /*