PostgreSQL Source Code  git master
xlogfuncs.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * xlogfuncs.c
4  *
5  * PostgreSQL write-ahead log manager user interface functions
6  *
7  * This file contains WAL control and information functions.
8  *
9  *
10  * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
11  * Portions Copyright (c) 1994, Regents of the University of California
12  *
13  * src/backend/access/transam/xlogfuncs.c
14  *
15  *-------------------------------------------------------------------------
16  */
17 #include "postgres.h"
18 
19 #include <unistd.h>
20 
21 #include "access/htup_details.h"
22 #include "access/xlog_internal.h"
23 #include "access/xlogbackup.h"
24 #include "access/xlogrecovery.h"
25 #include "catalog/pg_type.h"
26 #include "commands/waitlsn.h"
27 #include "funcapi.h"
28 #include "miscadmin.h"
29 #include "pgstat.h"
31 #include "storage/fd.h"
32 #include "storage/proc.h"
33 #include "storage/standby.h"
34 #include "utils/builtins.h"
35 #include "utils/memutils.h"
36 #include "utils/pg_lsn.h"
37 #include "utils/snapmgr.h"
38 #include "utils/timestamp.h"
39 
40 /*
41  * Backup-related variables.
42  */
43 static BackupState *backup_state = NULL;
44 static StringInfo tablespace_map = NULL;
45 
46 /* Session-level context for the SQL-callable backup functions */
48 
49 /*
50  * pg_backup_start: set up for taking an on-line backup dump
51  *
52  * Essentially what this does is to create the contents required for the
53  * backup_label file and the tablespace map.
54  *
55  * Permission checking for this function is managed through the normal
56  * GRANT system.
57  */
58 Datum
60 {
61  text *backupid = PG_GETARG_TEXT_PP(0);
62  bool fast = PG_GETARG_BOOL(1);
63  char *backupidstr;
65  MemoryContext oldcontext;
66 
67  backupidstr = text_to_cstring(backupid);
68 
69  if (status == SESSION_BACKUP_RUNNING)
70  ereport(ERROR,
71  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
72  errmsg("a backup is already in progress in this session")));
73 
74  /*
75  * backup_state and tablespace_map need to be long-lived as they are used
76  * in pg_backup_stop(). These are allocated in a dedicated memory context
77  * child of TopMemoryContext, deleted at the end of pg_backup_stop(). If
78  * an error happens before ending the backup, memory would be leaked in
79  * this context until pg_backup_start() is called again.
80  */
81  if (backupcontext == NULL)
82  {
84  "on-line backup context",
86  }
87  else
88  {
89  backup_state = NULL;
90  tablespace_map = NULL;
92  }
93 
97  MemoryContextSwitchTo(oldcontext);
98 
100  do_pg_backup_start(backupidstr, fast, NULL, backup_state, tablespace_map);
101 
103 }
104 
105 
106 /*
107  * pg_backup_stop: finish taking an on-line backup.
108  *
109  * The first parameter (variable 'waitforarchive'), which is optional,
110  * allows the user to choose if they want to wait for the WAL to be archived
111  * or if we should just return as soon as the WAL record is written.
112  *
113  * This function stops an in-progress backup, creates backup_label contents and
114  * it returns the backup stop LSN, backup_label and tablespace_map contents.
115  *
116  * The backup_label contains the user-supplied label string (typically this
117  * would be used to tell where the backup dump will be stored), the starting
118  * time, starting WAL location for the dump and so on. It is the caller's
119  * responsibility to write the backup_label and tablespace_map files in the
120  * data folder that will be restored from this backup.
121  *
122  * Permission checking for this function is managed through the normal
123  * GRANT system.
124  */
125 Datum
127 {
128 #define PG_BACKUP_STOP_V2_COLS 3
129  TupleDesc tupdesc;
131  bool nulls[PG_BACKUP_STOP_V2_COLS] = {0};
132  bool waitforarchive = PG_GETARG_BOOL(0);
133  char *backup_label;
135 
136  /* Initialize attributes information in the tuple descriptor */
137  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
138  elog(ERROR, "return type must be a row type");
139 
140  if (status != SESSION_BACKUP_RUNNING)
141  ereport(ERROR,
142  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
143  errmsg("backup is not in progress"),
144  errhint("Did you call pg_backup_start()?")));
145 
146  Assert(backup_state != NULL);
147  Assert(tablespace_map != NULL);
148 
149  /* Stop the backup */
150  do_pg_backup_stop(backup_state, waitforarchive);
151 
152  /* Build the contents of backup_label */
153  backup_label = build_backup_content(backup_state, false);
154 
156  values[1] = CStringGetTextDatum(backup_label);
158 
159  /* Deallocate backup-related variables */
160  pfree(backup_label);
161 
162  /* Clean up the session-level state and its memory context */
163  backup_state = NULL;
164  tablespace_map = NULL;
166  backupcontext = NULL;
167 
168  /* Returns the record as Datum */
170 }
171 
172 /*
173  * pg_switch_wal: switch to next xlog file
174  *
175  * Permission checking for this function is managed through the normal
176  * GRANT system.
177  */
178 Datum
180 {
181  XLogRecPtr switchpoint;
182 
183  if (RecoveryInProgress())
184  ereport(ERROR,
185  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
186  errmsg("recovery is in progress"),
187  errhint("WAL control functions cannot be executed during recovery.")));
188 
189  switchpoint = RequestXLogSwitch(false);
190 
191  /*
192  * As a convenience, return the WAL location of the switch record
193  */
194  PG_RETURN_LSN(switchpoint);
195 }
196 
197 /*
198  * pg_log_standby_snapshot: call LogStandbySnapshot()
199  *
200  * Permission checking for this function is managed through the normal
201  * GRANT system.
202  */
203 Datum
205 {
206  XLogRecPtr recptr;
207 
208  if (RecoveryInProgress())
209  ereport(ERROR,
210  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
211  errmsg("recovery is in progress"),
212  errhint("%s cannot be executed during recovery.",
213  "pg_log_standby_snapshot()")));
214 
215  if (!XLogStandbyInfoActive())
216  ereport(ERROR,
217  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
218  errmsg("pg_log_standby_snapshot() can only be used if \"wal_level\" >= \"replica\"")));
219 
220  recptr = LogStandbySnapshot();
221 
222  /*
223  * As a convenience, return the WAL location of the last inserted record
224  */
225  PG_RETURN_LSN(recptr);
226 }
227 
228 /*
229  * pg_create_restore_point: a named point for restore
230  *
231  * Permission checking for this function is managed through the normal
232  * GRANT system.
233  */
234 Datum
236 {
237  text *restore_name = PG_GETARG_TEXT_PP(0);
238  char *restore_name_str;
239  XLogRecPtr restorepoint;
240 
241  if (RecoveryInProgress())
242  ereport(ERROR,
243  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
244  errmsg("recovery is in progress"),
245  errhint("WAL control functions cannot be executed during recovery.")));
246 
247  if (!XLogIsNeeded())
248  ereport(ERROR,
249  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
250  errmsg("WAL level not sufficient for creating a restore point"),
251  errhint("\"wal_level\" must be set to \"replica\" or \"logical\" at server start.")));
252 
253  restore_name_str = text_to_cstring(restore_name);
254 
255  if (strlen(restore_name_str) >= MAXFNAMELEN)
256  ereport(ERROR,
257  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
258  errmsg("value too long for restore point (maximum %d characters)", MAXFNAMELEN - 1)));
259 
260  restorepoint = XLogRestorePoint(restore_name_str);
261 
262  /*
263  * As a convenience, return the WAL location of the restore point record
264  */
265  PG_RETURN_LSN(restorepoint);
266 }
267 
268 /*
269  * Report the current WAL write location (same format as pg_backup_start etc)
270  *
271  * This is useful for determining how much of WAL is visible to an external
272  * archiving process. Note that the data before this point is written out
273  * to the kernel, but is not necessarily synced to disk.
274  */
275 Datum
277 {
278  XLogRecPtr current_recptr;
279 
280  if (RecoveryInProgress())
281  ereport(ERROR,
282  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
283  errmsg("recovery is in progress"),
284  errhint("WAL control functions cannot be executed during recovery.")));
285 
286  current_recptr = GetXLogWriteRecPtr();
287 
288  PG_RETURN_LSN(current_recptr);
289 }
290 
291 /*
292  * Report the current WAL insert location (same format as pg_backup_start etc)
293  *
294  * This function is mostly for debugging purposes.
295  */
296 Datum
298 {
299  XLogRecPtr current_recptr;
300 
301  if (RecoveryInProgress())
302  ereport(ERROR,
303  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
304  errmsg("recovery is in progress"),
305  errhint("WAL control functions cannot be executed during recovery.")));
306 
307  current_recptr = GetXLogInsertRecPtr();
308 
309  PG_RETURN_LSN(current_recptr);
310 }
311 
312 /*
313  * Report the current WAL flush location (same format as pg_backup_start etc)
314  *
315  * This function is mostly for debugging purposes.
316  */
317 Datum
319 {
320  XLogRecPtr current_recptr;
321 
322  if (RecoveryInProgress())
323  ereport(ERROR,
324  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
325  errmsg("recovery is in progress"),
326  errhint("WAL control functions cannot be executed during recovery.")));
327 
328  current_recptr = GetFlushRecPtr(NULL);
329 
330  PG_RETURN_LSN(current_recptr);
331 }
332 
333 /*
334  * Report the last WAL receive location (same format as pg_backup_start etc)
335  *
336  * This is useful for determining how much of WAL is guaranteed to be received
337  * and synced to disk by walreceiver.
338  */
339 Datum
341 {
342  XLogRecPtr recptr;
343 
344  recptr = GetWalRcvFlushRecPtr(NULL, NULL);
345 
346  if (recptr == 0)
347  PG_RETURN_NULL();
348 
349  PG_RETURN_LSN(recptr);
350 }
351 
352 /*
353  * Report the last WAL replay location (same format as pg_backup_start etc)
354  *
355  * This is useful for determining how much of WAL is visible to read-only
356  * connections during recovery.
357  */
358 Datum
360 {
361  XLogRecPtr recptr;
362 
363  recptr = GetXLogReplayRecPtr(NULL);
364 
365  if (recptr == 0)
366  PG_RETURN_NULL();
367 
368  PG_RETURN_LSN(recptr);
369 }
370 
371 /*
372  * Compute an xlog file name and decimal byte offset given a WAL location,
373  * such as is returned by pg_backup_stop() or pg_switch_wal().
374  */
375 Datum
377 {
378  XLogSegNo xlogsegno;
379  uint32 xrecoff;
380  XLogRecPtr locationpoint = PG_GETARG_LSN(0);
381  char xlogfilename[MAXFNAMELEN];
382  Datum values[2];
383  bool isnull[2];
384  TupleDesc resultTupleDesc;
385  HeapTuple resultHeapTuple;
386  Datum result;
387 
388  if (RecoveryInProgress())
389  ereport(ERROR,
390  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
391  errmsg("recovery is in progress"),
392  errhint("%s cannot be executed during recovery.",
393  "pg_walfile_name_offset()")));
394 
395  /*
396  * Construct a tuple descriptor for the result row. This must match this
397  * function's pg_proc entry!
398  */
399  resultTupleDesc = CreateTemplateTupleDesc(2);
400  TupleDescInitEntry(resultTupleDesc, (AttrNumber) 1, "file_name",
401  TEXTOID, -1, 0);
402  TupleDescInitEntry(resultTupleDesc, (AttrNumber) 2, "file_offset",
403  INT4OID, -1, 0);
404 
405  resultTupleDesc = BlessTupleDesc(resultTupleDesc);
406 
407  /*
408  * xlogfilename
409  */
410  XLByteToSeg(locationpoint, xlogsegno, wal_segment_size);
411  XLogFileName(xlogfilename, GetWALInsertionTimeLine(), xlogsegno,
413 
414  values[0] = CStringGetTextDatum(xlogfilename);
415  isnull[0] = false;
416 
417  /*
418  * offset
419  */
420  xrecoff = XLogSegmentOffset(locationpoint, wal_segment_size);
421 
422  values[1] = UInt32GetDatum(xrecoff);
423  isnull[1] = false;
424 
425  /*
426  * Tuple jam: Having first prepared your Datums, then squash together
427  */
428  resultHeapTuple = heap_form_tuple(resultTupleDesc, values, isnull);
429 
430  result = HeapTupleGetDatum(resultHeapTuple);
431 
432  PG_RETURN_DATUM(result);
433 }
434 
435 /*
436  * Compute an xlog file name given a WAL location,
437  * such as is returned by pg_backup_stop() or pg_switch_wal().
438  */
439 Datum
441 {
442  XLogSegNo xlogsegno;
443  XLogRecPtr locationpoint = PG_GETARG_LSN(0);
444  char xlogfilename[MAXFNAMELEN];
445 
446  if (RecoveryInProgress())
447  ereport(ERROR,
448  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
449  errmsg("recovery is in progress"),
450  errhint("%s cannot be executed during recovery.",
451  "pg_walfile_name()")));
452 
453  XLByteToSeg(locationpoint, xlogsegno, wal_segment_size);
454  XLogFileName(xlogfilename, GetWALInsertionTimeLine(), xlogsegno,
456 
457  PG_RETURN_TEXT_P(cstring_to_text(xlogfilename));
458 }
459 
460 /*
461  * Extract the sequence number and the timeline ID from given a WAL file
462  * name.
463  */
464 Datum
466 {
467 #define PG_SPLIT_WALFILE_NAME_COLS 2
468  char *fname = text_to_cstring(PG_GETARG_TEXT_PP(0));
469  char *fname_upper;
470  char *p;
471  TimeLineID tli;
472  XLogSegNo segno;
474  bool isnull[PG_SPLIT_WALFILE_NAME_COLS] = {0};
475  TupleDesc tupdesc;
476  HeapTuple tuple;
477  char buf[256];
478  Datum result;
479 
480  fname_upper = pstrdup(fname);
481 
482  /* Capitalize WAL file name. */
483  for (p = fname_upper; *p; p++)
484  *p = pg_toupper((unsigned char) *p);
485 
486  if (!IsXLogFileName(fname_upper))
487  ereport(ERROR,
488  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
489  errmsg("invalid WAL file name \"%s\"", fname)));
490 
491  XLogFromFileName(fname_upper, &tli, &segno, wal_segment_size);
492 
493  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
494  elog(ERROR, "return type must be a row type");
495 
496  /* Convert to numeric. */
497  snprintf(buf, sizeof buf, UINT64_FORMAT, segno);
500  ObjectIdGetDatum(0),
501  Int32GetDatum(-1));
502 
503  values[1] = Int64GetDatum(tli);
504 
505  tuple = heap_form_tuple(tupdesc, values, isnull);
506  result = HeapTupleGetDatum(tuple);
507 
508  PG_RETURN_DATUM(result);
509 
510 #undef PG_SPLIT_WALFILE_NAME_COLS
511 }
512 
513 /*
514  * pg_wal_replay_pause - Request to pause recovery
515  *
516  * Permission checking for this function is managed through the normal
517  * GRANT system.
518  */
519 Datum
521 {
522  if (!RecoveryInProgress())
523  ereport(ERROR,
524  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
525  errmsg("recovery is not in progress"),
526  errhint("Recovery control functions can only be executed during recovery.")));
527 
528  if (PromoteIsTriggered())
529  ereport(ERROR,
530  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
531  errmsg("standby promotion is ongoing"),
532  errhint("%s cannot be executed after promotion is triggered.",
533  "pg_wal_replay_pause()")));
534 
535  SetRecoveryPause(true);
536 
537  /* wake up the recovery process so that it can process the pause request */
538  WakeupRecovery();
539 
540  PG_RETURN_VOID();
541 }
542 
543 /*
544  * pg_wal_replay_resume - resume recovery now
545  *
546  * Permission checking for this function is managed through the normal
547  * GRANT system.
548  */
549 Datum
551 {
552  if (!RecoveryInProgress())
553  ereport(ERROR,
554  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
555  errmsg("recovery is not in progress"),
556  errhint("Recovery control functions can only be executed during recovery.")));
557 
558  if (PromoteIsTriggered())
559  ereport(ERROR,
560  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
561  errmsg("standby promotion is ongoing"),
562  errhint("%s cannot be executed after promotion is triggered.",
563  "pg_wal_replay_resume()")));
564 
565  SetRecoveryPause(false);
566 
567  PG_RETURN_VOID();
568 }
569 
570 /*
571  * pg_is_wal_replay_paused
572  */
573 Datum
575 {
576  if (!RecoveryInProgress())
577  ereport(ERROR,
578  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
579  errmsg("recovery is not in progress"),
580  errhint("Recovery control functions can only be executed during recovery.")));
581 
583 }
584 
585 /*
586  * pg_get_wal_replay_pause_state - Returns the recovery pause state.
587  *
588  * Returned values:
589  *
590  * 'not paused' - if pause is not requested
591  * 'pause requested' - if pause is requested but recovery is not yet paused
592  * 'paused' - if recovery is paused
593  */
594 Datum
596 {
597  char *statestr = NULL;
598 
599  if (!RecoveryInProgress())
600  ereport(ERROR,
601  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
602  errmsg("recovery is not in progress"),
603  errhint("Recovery control functions can only be executed during recovery.")));
604 
605  /* get the recovery pause state */
606  switch (GetRecoveryPauseState())
607  {
608  case RECOVERY_NOT_PAUSED:
609  statestr = "not paused";
610  break;
612  statestr = "pause requested";
613  break;
614  case RECOVERY_PAUSED:
615  statestr = "paused";
616  break;
617  }
618 
619  Assert(statestr != NULL);
621 }
622 
623 /*
624  * Returns timestamp of latest processed commit/abort record.
625  *
626  * When the server has been started normally without recovery the function
627  * returns NULL.
628  */
629 Datum
631 {
632  TimestampTz xtime;
633 
634  xtime = GetLatestXTime();
635  if (xtime == 0)
636  PG_RETURN_NULL();
637 
638  PG_RETURN_TIMESTAMPTZ(xtime);
639 }
640 
641 /*
642  * Returns bool with current recovery mode, a global state.
643  */
644 Datum
646 {
648 }
649 
650 /*
651  * Compute the difference in bytes between two WAL locations.
652  */
653 Datum
655 {
656  Datum result;
657 
659  PG_GETARG_DATUM(0),
660  PG_GETARG_DATUM(1));
661 
662  PG_RETURN_DATUM(result);
663 }
664 
665 /*
666  * Promotes a standby server.
667  *
668  * A result of "true" means that promotion has been completed if "wait" is
669  * "true", or initiated if "wait" is false.
670  */
671 Datum
673 {
674  bool wait = PG_GETARG_BOOL(0);
675  int wait_seconds = PG_GETARG_INT32(1);
676  FILE *promote_file;
677  int i;
678 
679  if (!RecoveryInProgress())
680  ereport(ERROR,
681  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
682  errmsg("recovery is not in progress"),
683  errhint("Recovery control functions can only be executed during recovery.")));
684 
685  if (wait_seconds <= 0)
686  ereport(ERROR,
687  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
688  errmsg("\"wait_seconds\" must not be negative or zero")));
689 
690  /* create the promote signal file */
692  if (!promote_file)
693  ereport(ERROR,
695  errmsg("could not create file \"%s\": %m",
697 
698  if (FreeFile(promote_file))
699  ereport(ERROR,
701  errmsg("could not write file \"%s\": %m",
703 
704  /* signal the postmaster */
705  if (kill(PostmasterPid, SIGUSR1) != 0)
706  {
707  (void) unlink(PROMOTE_SIGNAL_FILE);
708  ereport(ERROR,
709  (errcode(ERRCODE_SYSTEM_ERROR),
710  errmsg("failed to send signal to postmaster: %m")));
711  }
712 
713  /* return immediately if waiting was not requested */
714  if (!wait)
715  PG_RETURN_BOOL(true);
716 
717  /* wait for the amount of time wanted until promotion */
718 #define WAITS_PER_SECOND 10
719  for (i = 0; i < WAITS_PER_SECOND * wait_seconds; i++)
720  {
721  int rc;
722 
724 
725  if (!RecoveryInProgress())
726  PG_RETURN_BOOL(true);
727 
729 
730  rc = WaitLatch(MyLatch,
732  1000L / WAITS_PER_SECOND,
733  WAIT_EVENT_PROMOTE);
734 
735  /*
736  * Emergency bailout if postmaster has died. This is to avoid the
737  * necessity for manual cleanup of all postmaster children.
738  */
739  if (rc & WL_POSTMASTER_DEATH)
740  ereport(FATAL,
741  (errcode(ERRCODE_ADMIN_SHUTDOWN),
742  errmsg("terminating connection due to unexpected postmaster exit"),
743  errcontext("while waiting on promotion")));
744  }
745 
747  (errmsg_plural("server did not promote within %d second",
748  "server did not promote within %d seconds",
749  wait_seconds,
750  wait_seconds)));
751  PG_RETURN_BOOL(false);
752 }
753 
754 /*
755  * Waits until recovery replays the target LSN with optional timeout.
756  */
757 Datum
759 {
760  XLogRecPtr target_lsn = PG_GETARG_LSN(0);
761  int64 timeout = PG_GETARG_INT64(1);
762 
763  if (timeout < 0)
764  ereport(ERROR,
765  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
766  errmsg("\"timeout\" must not be negative")));
767 
768  /*
769  * We are going to wait for the LSN replay. We should first care that we
770  * don't hold a snapshot and correspondingly our MyProc->xmin is invalid.
771  * Otherwise, our snapshot could prevent the replay of WAL records
772  * implying a kind of self-deadlock. This is the reason why
773  * pg_wal_replay_wait() is a procedure, not a function.
774  *
775  * At first, we should check there is no active snapshot. According to
776  * PlannedStmtRequiresSnapshot(), even in an atomic context, CallStmt is
777  * processed with a snapshot. Thankfully, we can pop this snapshot,
778  * because PortalRunUtility() can tolerate this.
779  */
780  if (ActiveSnapshotSet())
782 
783  /*
784  * At second, invalidate a catalog snapshot if any. And we should be done
785  * with the preparation.
786  */
788 
789  /* Give up if there is still an active or registered snapshot. */
790  if (GetOldestSnapshot())
791  ereport(ERROR,
792  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
793  errmsg("pg_wal_replay_wait() must be only called without an active or registered snapshot"),
794  errdetail("Make sure pg_wal_replay_wait() isn't called within a transaction with an isolation level higher than READ COMMITTED, another procedure, or a function.")));
795 
796  /*
797  * As the result we should hold no snapshot, and correspondingly our xmin
798  * should be unset.
799  */
801 
802  (void) WaitForLSNReplay(target_lsn, timeout);
803 
804  PG_RETURN_VOID();
805 }
int16 AttrNumber
Definition: attnum.h:21
Datum numeric_in(PG_FUNCTION_ARGS)
Definition: numeric.c:636
static Datum values[MAXATTR]
Definition: bootstrap.c:150
#define CStringGetTextDatum(s)
Definition: builtins.h:97
unsigned int uint32
Definition: c.h:506
#define Assert(condition)
Definition: c.h:849
#define UINT64_FORMAT
Definition: c.h:540
int64 TimestampTz
Definition: timestamp.h:39
int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:1180
int errcode_for_file_access(void)
Definition: elog.c:876
int errdetail(const char *fmt,...)
Definition: elog.c:1203
int errhint(const char *fmt,...)
Definition: elog.c:1317
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define errcontext
Definition: elog.h:196
#define FATAL
Definition: elog.h:41
#define WARNING
Definition: elog.h:36
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
#define ereport(elevel,...)
Definition: elog.h:149
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2158
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2606
int FreeFile(FILE *file)
Definition: fd.c:2804
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1807
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:643
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
#define PG_RETURN_NULL()
Definition: fmgr.h:345
#define PG_GETARG_INT64(n)
Definition: fmgr.h:283
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:372
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:645
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:276
@ TYPEFUNC_COMPOSITE
Definition: funcapi.h:149
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition: funcapi.h:230
pid_t PostmasterPid
Definition: globals.c:105
struct Latch * MyLatch
Definition: globals.c:62
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1116
int i
Definition: isn.c:73
void ResetLatch(Latch *latch)
Definition: latch.c:724
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition: latch.c:517
#define WL_TIMEOUT
Definition: latch.h:130
#define WL_LATCH_SET
Definition: latch.h:127
#define WL_POSTMASTER_DEATH
Definition: latch.h:131
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:383
char * pstrdup(const char *in)
Definition: mcxt.c:1696
void pfree(void *pointer)
Definition: mcxt.c:1521
MemoryContext TopMemoryContext
Definition: mcxt.c:149
void * palloc0(Size size)
Definition: mcxt.c:1347
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:454
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_START_SMALL_SIZES
Definition: memutils.h:177
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:122
static char promote_file[MAXPGPATH]
Definition: pg_ctl.c:100
static int wait_seconds
Definition: pg_ctl.c:76
Datum pg_lsn_mi(PG_FUNCTION_ARGS)
Definition: pg_lsn.c:224
#define PG_GETARG_LSN(n)
Definition: pg_lsn.h:33
static Datum LSNGetDatum(XLogRecPtr X)
Definition: pg_lsn.h:28
#define PG_RETURN_LSN(x)
Definition: pg_lsn.h:34
static char * buf
Definition: pg_test_fsync.c:73
unsigned char pg_toupper(unsigned char ch)
Definition: pgstrcasecmp.c:105
#define snprintf
Definition: port.h:238
uintptr_t Datum
Definition: postgres.h:64
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
static Datum CStringGetDatum(const char *X)
Definition: postgres.h:350
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212
static Datum UInt32GetDatum(uint32 X)
Definition: postgres.h:232
MemoryContextSwitchTo(old_ctx)
bool ActiveSnapshotSet(void)
Definition: snapmgr.c:782
void PopActiveSnapshot(void)
Definition: snapmgr.c:743
void InvalidateCatalogSnapshot(void)
Definition: snapmgr.c:422
Snapshot GetOldestSnapshot(void)
Definition: snapmgr.c:323
PGPROC * MyProc
Definition: proc.c:67
XLogRecPtr LogStandbySnapshot(void)
Definition: standby.c:1281
StringInfo makeStringInfo(void)
Definition: stringinfo.c:41
XLogRecPtr startpoint
Definition: xlogbackup.h:26
XLogRecPtr stoppoint
Definition: xlogbackup.h:35
TransactionId xmin
Definition: proc.h:177
Definition: c.h:678
#define InvalidTransactionId
Definition: transam.h:31
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:67
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:651
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:68
char * text_to_cstring(const text *t)
Definition: varlena.c:217
text * cstring_to_text(const char *s)
Definition: varlena.c:184
void WaitForLSNReplay(XLogRecPtr targetLSN, int64 timeout)
Definition: waitlsn.c:221
XLogRecPtr GetWalRcvFlushRecPtr(XLogRecPtr *latestChunkStart, TimeLineID *receiveTLI)
#define kill(pid, sig)
Definition: win32_port.h:503
#define SIGUSR1
Definition: win32_port.h:180
bool RecoveryInProgress(void)
Definition: xlog.c:6333
TimeLineID GetWALInsertionTimeLine(void)
Definition: xlog.c:6519
XLogRecPtr RequestXLogSwitch(bool mark_unimportant)
Definition: xlog.c:8059
SessionBackupState get_backup_status(void)
Definition: xlog.c:9100
int wal_segment_size
Definition: xlog.c:142
XLogRecPtr GetXLogInsertRecPtr(void)
Definition: xlog.c:9434
XLogRecPtr GetFlushRecPtr(TimeLineID *insertTLI)
Definition: xlog.c:6498
void register_persistent_abort_backup_handler(void)
Definition: xlog.c:9420
XLogRecPtr GetXLogWriteRecPtr(void)
Definition: xlog.c:9450
void do_pg_backup_start(const char *backupidstr, bool fast, List **tablespaces, BackupState *state, StringInfo tblspcmapfile)
Definition: xlog.c:8791
XLogRecPtr XLogRestorePoint(const char *rpName)
Definition: xlog.c:8077
void do_pg_backup_stop(BackupState *state, bool waitforarchive)
Definition: xlog.c:9119
#define PROMOTE_SIGNAL_FILE
Definition: xlog.h:309
SessionBackupState
Definition: xlog.h:286
@ SESSION_BACKUP_RUNNING
Definition: xlog.h:288
#define XLogIsNeeded()
Definition: xlog.h:109
#define XLogStandbyInfoActive()
Definition: xlog.h:123
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)
static bool IsXLogFileName(const char *fname)
static void XLogFromFileName(const char *fname, TimeLineID *tli, XLogSegNo *logSegNo, int wal_segsz_bytes)
#define MAXFNAMELEN
#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes)
static void XLogFileName(char *fname, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
char * build_backup_content(BackupState *state, bool ishistoryfile)
Definition: xlogbackup.c:29
uint64 XLogRecPtr
Definition: xlogdefs.h:21
uint32 TimeLineID
Definition: xlogdefs.h:59
uint64 XLogSegNo
Definition: xlogdefs.h:48
Datum pg_is_wal_replay_paused(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:574
Datum pg_wal_lsn_diff(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:654
Datum pg_backup_start(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:59
Datum pg_create_restore_point(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:235
Datum pg_current_wal_insert_lsn(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:297
Datum pg_switch_wal(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:179
Datum pg_wal_replay_wait(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:758
Datum pg_is_in_recovery(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:645
#define PG_SPLIT_WALFILE_NAME_COLS
Datum pg_split_walfile_name(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:465
Datum pg_backup_stop(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:126
#define WAITS_PER_SECOND
Datum pg_last_xact_replay_timestamp(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:630
Datum pg_log_standby_snapshot(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:204
static BackupState * backup_state
Definition: xlogfuncs.c:43
Datum pg_current_wal_lsn(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:276
Datum pg_last_wal_receive_lsn(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:340
#define PG_BACKUP_STOP_V2_COLS
Datum pg_walfile_name(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:440
Datum pg_current_wal_flush_lsn(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:318
Datum pg_walfile_name_offset(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:376
static MemoryContext backupcontext
Definition: xlogfuncs.c:47
static StringInfo tablespace_map
Definition: xlogfuncs.c:44
Datum pg_promote(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:672
Datum pg_get_wal_replay_pause_state(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:595
Datum pg_last_wal_replay_lsn(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:359
Datum pg_wal_replay_pause(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:520
Datum pg_wal_replay_resume(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:550
void SetRecoveryPause(bool recoveryPause)
void WakeupRecovery(void)
bool PromoteIsTriggered(void)
XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI)
RecoveryPauseState GetRecoveryPauseState(void)
TimestampTz GetLatestXTime(void)
@ RECOVERY_PAUSED
Definition: xlogrecovery.h:48
@ RECOVERY_NOT_PAUSED
Definition: xlogrecovery.h:46
@ RECOVERY_PAUSE_REQUESTED
Definition: xlogrecovery.h:47