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-2023, 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 "access/xlogutils.h"
26 #include "catalog/pg_type.h"
27 #include "funcapi.h"
28 #include "miscadmin.h"
29 #include "pgstat.h"
31 #include "storage/fd.h"
32 #include "storage/ipc.h"
33 #include "storage/smgr.h"
34 #include "storage/standby.h"
35 #include "utils/builtins.h"
36 #include "utils/guc.h"
37 #include "utils/memutils.h"
38 #include "utils/numeric.h"
39 #include "utils/pg_lsn.h"
40 #include "utils/timestamp.h"
41 #include "utils/tuplestore.h"
42 
43 /*
44  * Backup-related variables.
45  */
46 static BackupState *backup_state = NULL;
47 static StringInfo tablespace_map = NULL;
48 
49 /* Session-level context for the SQL-callable backup functions */
51 
52 /*
53  * pg_backup_start: set up for taking an on-line backup dump
54  *
55  * Essentially what this does is to create the contents required for the
56  * backup_label file and the tablespace map.
57  *
58  * Permission checking for this function is managed through the normal
59  * GRANT system.
60  */
61 Datum
63 {
64  text *backupid = PG_GETARG_TEXT_PP(0);
65  bool fast = PG_GETARG_BOOL(1);
66  char *backupidstr;
68  MemoryContext oldcontext;
69 
70  backupidstr = text_to_cstring(backupid);
71 
72  if (status == SESSION_BACKUP_RUNNING)
73  ereport(ERROR,
74  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
75  errmsg("a backup is already in progress in this session")));
76 
77  /*
78  * backup_state and tablespace_map need to be long-lived as they are used
79  * in pg_backup_stop(). These are allocated in a dedicated memory context
80  * child of TopMemoryContext, deleted at the end of pg_backup_stop(). If
81  * an error happens before ending the backup, memory would be leaked in
82  * this context until pg_backup_start() is called again.
83  */
84  if (backupcontext == NULL)
85  {
87  "on-line backup context",
89  }
90  else
91  {
92  backup_state = NULL;
93  tablespace_map = NULL;
95  }
96 
100  MemoryContextSwitchTo(oldcontext);
101 
103  do_pg_backup_start(backupidstr, fast, NULL, backup_state, tablespace_map);
104 
106 }
107 
108 
109 /*
110  * pg_backup_stop: finish taking an on-line backup.
111  *
112  * The first parameter (variable 'waitforarchive'), which is optional,
113  * allows the user to choose if they want to wait for the WAL to be archived
114  * or if we should just return as soon as the WAL record is written.
115  *
116  * This function stops an in-progress backup, creates backup_label contents and
117  * it returns the backup stop LSN, backup_label and tablespace_map contents.
118  *
119  * The backup_label contains the user-supplied label string (typically this
120  * would be used to tell where the backup dump will be stored), the starting
121  * time, starting WAL location for the dump and so on. It is the caller's
122  * responsibility to write the backup_label and tablespace_map files in the
123  * data folder that will be restored from this backup.
124  *
125  * Permission checking for this function is managed through the normal
126  * GRANT system.
127  */
128 Datum
130 {
131 #define PG_BACKUP_STOP_V2_COLS 3
132  TupleDesc tupdesc;
134  bool nulls[PG_BACKUP_STOP_V2_COLS] = {0};
135  bool waitforarchive = PG_GETARG_BOOL(0);
136  char *backup_label;
138 
139  /* Initialize attributes information in the tuple descriptor */
140  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
141  elog(ERROR, "return type must be a row type");
142 
143  if (status != SESSION_BACKUP_RUNNING)
144  ereport(ERROR,
145  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
146  errmsg("backup is not in progress"),
147  errhint("Did you call pg_backup_start()?")));
148 
149  Assert(backup_state != NULL);
150  Assert(tablespace_map != NULL);
151 
152  /* Stop the backup */
153  do_pg_backup_stop(backup_state, waitforarchive);
154 
155  /* Build the contents of backup_label */
156  backup_label = build_backup_content(backup_state, false);
157 
159  values[1] = CStringGetTextDatum(backup_label);
161 
162  /* Deallocate backup-related variables */
163  pfree(backup_label);
164 
165  /* Clean up the session-level state and its memory context */
166  backup_state = NULL;
167  tablespace_map = NULL;
169  backupcontext = NULL;
170 
171  /* Returns the record as Datum */
173 }
174 
175 /*
176  * pg_switch_wal: switch to next xlog file
177  *
178  * Permission checking for this function is managed through the normal
179  * GRANT system.
180  */
181 Datum
183 {
184  XLogRecPtr switchpoint;
185 
186  if (RecoveryInProgress())
187  ereport(ERROR,
188  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
189  errmsg("recovery is in progress"),
190  errhint("WAL control functions cannot be executed during recovery.")));
191 
192  switchpoint = RequestXLogSwitch(false);
193 
194  /*
195  * As a convenience, return the WAL location of the switch record
196  */
197  PG_RETURN_LSN(switchpoint);
198 }
199 
200 /*
201  * pg_log_standby_snapshot: call LogStandbySnapshot()
202  *
203  * Permission checking for this function is managed through the normal
204  * GRANT system.
205  */
206 Datum
208 {
209  XLogRecPtr recptr;
210 
211  if (RecoveryInProgress())
212  ereport(ERROR,
213  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
214  errmsg("recovery is in progress"),
215  errhint("%s cannot be executed during recovery.",
216  "pg_log_standby_snapshot()")));
217 
218  if (!XLogStandbyInfoActive())
219  ereport(ERROR,
220  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
221  errmsg("pg_log_standby_snapshot() can only be used if wal_level >= replica")));
222 
223  recptr = LogStandbySnapshot();
224 
225  /*
226  * As a convenience, return the WAL location of the last inserted record
227  */
228  PG_RETURN_LSN(recptr);
229 }
230 
231 /*
232  * pg_create_restore_point: a named point for restore
233  *
234  * Permission checking for this function is managed through the normal
235  * GRANT system.
236  */
237 Datum
239 {
240  text *restore_name = PG_GETARG_TEXT_PP(0);
241  char *restore_name_str;
242  XLogRecPtr restorepoint;
243 
244  if (RecoveryInProgress())
245  ereport(ERROR,
246  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
247  errmsg("recovery is in progress"),
248  errhint("WAL control functions cannot be executed during recovery.")));
249 
250  if (!XLogIsNeeded())
251  ereport(ERROR,
252  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
253  errmsg("WAL level not sufficient for creating a restore point"),
254  errhint("wal_level must be set to \"replica\" or \"logical\" at server start.")));
255 
256  restore_name_str = text_to_cstring(restore_name);
257 
258  if (strlen(restore_name_str) >= MAXFNAMELEN)
259  ereport(ERROR,
260  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
261  errmsg("value too long for restore point (maximum %d characters)", MAXFNAMELEN - 1)));
262 
263  restorepoint = XLogRestorePoint(restore_name_str);
264 
265  /*
266  * As a convenience, return the WAL location of the restore point record
267  */
268  PG_RETURN_LSN(restorepoint);
269 }
270 
271 /*
272  * Report the current WAL write location (same format as pg_backup_start etc)
273  *
274  * This is useful for determining how much of WAL is visible to an external
275  * archiving process. Note that the data before this point is written out
276  * to the kernel, but is not necessarily synced to disk.
277  */
278 Datum
280 {
281  XLogRecPtr current_recptr;
282 
283  if (RecoveryInProgress())
284  ereport(ERROR,
285  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
286  errmsg("recovery is in progress"),
287  errhint("WAL control functions cannot be executed during recovery.")));
288 
289  current_recptr = GetXLogWriteRecPtr();
290 
291  PG_RETURN_LSN(current_recptr);
292 }
293 
294 /*
295  * Report the current WAL insert location (same format as pg_backup_start etc)
296  *
297  * This function is mostly for debugging purposes.
298  */
299 Datum
301 {
302  XLogRecPtr current_recptr;
303 
304  if (RecoveryInProgress())
305  ereport(ERROR,
306  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
307  errmsg("recovery is in progress"),
308  errhint("WAL control functions cannot be executed during recovery.")));
309 
310  current_recptr = GetXLogInsertRecPtr();
311 
312  PG_RETURN_LSN(current_recptr);
313 }
314 
315 /*
316  * Report the current WAL flush location (same format as pg_backup_start etc)
317  *
318  * This function is mostly for debugging purposes.
319  */
320 Datum
322 {
323  XLogRecPtr current_recptr;
324 
325  if (RecoveryInProgress())
326  ereport(ERROR,
327  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
328  errmsg("recovery is in progress"),
329  errhint("WAL control functions cannot be executed during recovery.")));
330 
331  current_recptr = GetFlushRecPtr(NULL);
332 
333  PG_RETURN_LSN(current_recptr);
334 }
335 
336 /*
337  * Report the last WAL receive location (same format as pg_backup_start etc)
338  *
339  * This is useful for determining how much of WAL is guaranteed to be received
340  * and synced to disk by walreceiver.
341  */
342 Datum
344 {
345  XLogRecPtr recptr;
346 
347  recptr = GetWalRcvFlushRecPtr(NULL, NULL);
348 
349  if (recptr == 0)
350  PG_RETURN_NULL();
351 
352  PG_RETURN_LSN(recptr);
353 }
354 
355 /*
356  * Report the last WAL replay location (same format as pg_backup_start etc)
357  *
358  * This is useful for determining how much of WAL is visible to read-only
359  * connections during recovery.
360  */
361 Datum
363 {
364  XLogRecPtr recptr;
365 
366  recptr = GetXLogReplayRecPtr(NULL);
367 
368  if (recptr == 0)
369  PG_RETURN_NULL();
370 
371  PG_RETURN_LSN(recptr);
372 }
373 
374 /*
375  * Compute an xlog file name and decimal byte offset given a WAL location,
376  * such as is returned by pg_backup_stop() or pg_switch_wal().
377  */
378 Datum
380 {
381  XLogSegNo xlogsegno;
382  uint32 xrecoff;
383  XLogRecPtr locationpoint = PG_GETARG_LSN(0);
384  char xlogfilename[MAXFNAMELEN];
385  Datum values[2];
386  bool isnull[2];
387  TupleDesc resultTupleDesc;
388  HeapTuple resultHeapTuple;
389  Datum result;
390 
391  if (RecoveryInProgress())
392  ereport(ERROR,
393  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
394  errmsg("recovery is in progress"),
395  errhint("%s cannot be executed during recovery.",
396  "pg_walfile_name_offset()")));
397 
398  /*
399  * Construct a tuple descriptor for the result row. This must match this
400  * function's pg_proc entry!
401  */
402  resultTupleDesc = CreateTemplateTupleDesc(2);
403  TupleDescInitEntry(resultTupleDesc, (AttrNumber) 1, "file_name",
404  TEXTOID, -1, 0);
405  TupleDescInitEntry(resultTupleDesc, (AttrNumber) 2, "file_offset",
406  INT4OID, -1, 0);
407 
408  resultTupleDesc = BlessTupleDesc(resultTupleDesc);
409 
410  /*
411  * xlogfilename
412  */
413  XLByteToSeg(locationpoint, xlogsegno, wal_segment_size);
414  XLogFileName(xlogfilename, GetWALInsertionTimeLine(), xlogsegno,
416 
417  values[0] = CStringGetTextDatum(xlogfilename);
418  isnull[0] = false;
419 
420  /*
421  * offset
422  */
423  xrecoff = XLogSegmentOffset(locationpoint, wal_segment_size);
424 
425  values[1] = UInt32GetDatum(xrecoff);
426  isnull[1] = false;
427 
428  /*
429  * Tuple jam: Having first prepared your Datums, then squash together
430  */
431  resultHeapTuple = heap_form_tuple(resultTupleDesc, values, isnull);
432 
433  result = HeapTupleGetDatum(resultHeapTuple);
434 
435  PG_RETURN_DATUM(result);
436 }
437 
438 /*
439  * Compute an xlog file name given a WAL location,
440  * such as is returned by pg_backup_stop() or pg_switch_wal().
441  */
442 Datum
444 {
445  XLogSegNo xlogsegno;
446  XLogRecPtr locationpoint = PG_GETARG_LSN(0);
447  char xlogfilename[MAXFNAMELEN];
448 
449  if (RecoveryInProgress())
450  ereport(ERROR,
451  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
452  errmsg("recovery is in progress"),
453  errhint("%s cannot be executed during recovery.",
454  "pg_walfile_name()")));
455 
456  XLByteToSeg(locationpoint, xlogsegno, wal_segment_size);
457  XLogFileName(xlogfilename, GetWALInsertionTimeLine(), xlogsegno,
459 
460  PG_RETURN_TEXT_P(cstring_to_text(xlogfilename));
461 }
462 
463 /*
464  * Extract the sequence number and the timeline ID from given a WAL file
465  * name.
466  */
467 Datum
469 {
470 #define PG_SPLIT_WALFILE_NAME_COLS 2
471  char *fname = text_to_cstring(PG_GETARG_TEXT_PP(0));
472  char *fname_upper;
473  char *p;
474  TimeLineID tli;
475  XLogSegNo segno;
477  bool isnull[PG_SPLIT_WALFILE_NAME_COLS] = {0};
478  TupleDesc tupdesc;
479  HeapTuple tuple;
480  char buf[256];
481  Datum result;
482 
483  fname_upper = pstrdup(fname);
484 
485  /* Capitalize WAL file name. */
486  for (p = fname_upper; *p; p++)
487  *p = pg_toupper((unsigned char) *p);
488 
489  if (!IsXLogFileName(fname_upper))
490  ereport(ERROR,
491  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
492  errmsg("invalid WAL file name \"%s\"", fname)));
493 
494  XLogFromFileName(fname_upper, &tli, &segno, wal_segment_size);
495 
496  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
497  elog(ERROR, "return type must be a row type");
498 
499  /* Convert to numeric. */
500  snprintf(buf, sizeof buf, UINT64_FORMAT, segno);
503  ObjectIdGetDatum(0),
504  Int32GetDatum(-1));
505 
506  values[1] = Int64GetDatum(tli);
507 
508  tuple = heap_form_tuple(tupdesc, values, isnull);
509  result = HeapTupleGetDatum(tuple);
510 
511  PG_RETURN_DATUM(result);
512 
513 #undef PG_SPLIT_WALFILE_NAME_COLS
514 }
515 
516 /*
517  * pg_wal_replay_pause - Request to pause recovery
518  *
519  * Permission checking for this function is managed through the normal
520  * GRANT system.
521  */
522 Datum
524 {
525  if (!RecoveryInProgress())
526  ereport(ERROR,
527  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
528  errmsg("recovery is not in progress"),
529  errhint("Recovery control functions can only be executed during recovery.")));
530 
531  if (PromoteIsTriggered())
532  ereport(ERROR,
533  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
534  errmsg("standby promotion is ongoing"),
535  errhint("%s cannot be executed after promotion is triggered.",
536  "pg_wal_replay_pause()")));
537 
538  SetRecoveryPause(true);
539 
540  /* wake up the recovery process so that it can process the pause request */
541  WakeupRecovery();
542 
543  PG_RETURN_VOID();
544 }
545 
546 /*
547  * pg_wal_replay_resume - resume recovery now
548  *
549  * Permission checking for this function is managed through the normal
550  * GRANT system.
551  */
552 Datum
554 {
555  if (!RecoveryInProgress())
556  ereport(ERROR,
557  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
558  errmsg("recovery is not in progress"),
559  errhint("Recovery control functions can only be executed during recovery.")));
560 
561  if (PromoteIsTriggered())
562  ereport(ERROR,
563  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
564  errmsg("standby promotion is ongoing"),
565  errhint("%s cannot be executed after promotion is triggered.",
566  "pg_wal_replay_resume()")));
567 
568  SetRecoveryPause(false);
569 
570  PG_RETURN_VOID();
571 }
572 
573 /*
574  * pg_is_wal_replay_paused
575  */
576 Datum
578 {
579  if (!RecoveryInProgress())
580  ereport(ERROR,
581  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
582  errmsg("recovery is not in progress"),
583  errhint("Recovery control functions can only be executed during recovery.")));
584 
586 }
587 
588 /*
589  * pg_get_wal_replay_pause_state - Returns the recovery pause state.
590  *
591  * Returned values:
592  *
593  * 'not paused' - if pause is not requested
594  * 'pause requested' - if pause is requested but recovery is not yet paused
595  * 'paused' - if recovery is paused
596  */
597 Datum
599 {
600  char *statestr = NULL;
601 
602  if (!RecoveryInProgress())
603  ereport(ERROR,
604  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
605  errmsg("recovery is not in progress"),
606  errhint("Recovery control functions can only be executed during recovery.")));
607 
608  /* get the recovery pause state */
609  switch (GetRecoveryPauseState())
610  {
611  case RECOVERY_NOT_PAUSED:
612  statestr = "not paused";
613  break;
615  statestr = "pause requested";
616  break;
617  case RECOVERY_PAUSED:
618  statestr = "paused";
619  break;
620  }
621 
622  Assert(statestr != NULL);
624 }
625 
626 /*
627  * Returns timestamp of latest processed commit/abort record.
628  *
629  * When the server has been started normally without recovery the function
630  * returns NULL.
631  */
632 Datum
634 {
635  TimestampTz xtime;
636 
637  xtime = GetLatestXTime();
638  if (xtime == 0)
639  PG_RETURN_NULL();
640 
641  PG_RETURN_TIMESTAMPTZ(xtime);
642 }
643 
644 /*
645  * Returns bool with current recovery mode, a global state.
646  */
647 Datum
649 {
651 }
652 
653 /*
654  * Compute the difference in bytes between two WAL locations.
655  */
656 Datum
658 {
659  Datum result;
660 
662  PG_GETARG_DATUM(0),
663  PG_GETARG_DATUM(1));
664 
665  PG_RETURN_DATUM(result);
666 }
667 
668 /*
669  * Promotes a standby server.
670  *
671  * A result of "true" means that promotion has been completed if "wait" is
672  * "true", or initiated if "wait" is false.
673  */
674 Datum
676 {
677  bool wait = PG_GETARG_BOOL(0);
678  int wait_seconds = PG_GETARG_INT32(1);
679  FILE *promote_file;
680  int i;
681 
682  if (!RecoveryInProgress())
683  ereport(ERROR,
684  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
685  errmsg("recovery is not in progress"),
686  errhint("Recovery control functions can only be executed during recovery.")));
687 
688  if (wait_seconds <= 0)
689  ereport(ERROR,
690  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
691  errmsg("\"wait_seconds\" must not be negative or zero")));
692 
693  /* create the promote signal file */
695  if (!promote_file)
696  ereport(ERROR,
698  errmsg("could not create file \"%s\": %m",
700 
701  if (FreeFile(promote_file))
702  ereport(ERROR,
704  errmsg("could not write file \"%s\": %m",
706 
707  /* signal the postmaster */
708  if (kill(PostmasterPid, SIGUSR1) != 0)
709  {
710  (void) unlink(PROMOTE_SIGNAL_FILE);
711  ereport(ERROR,
712  (errcode(ERRCODE_SYSTEM_ERROR),
713  errmsg("failed to send signal to postmaster: %m")));
714  }
715 
716  /* return immediately if waiting was not requested */
717  if (!wait)
718  PG_RETURN_BOOL(true);
719 
720  /* wait for the amount of time wanted until promotion */
721 #define WAITS_PER_SECOND 10
722  for (i = 0; i < WAITS_PER_SECOND * wait_seconds; i++)
723  {
724  int rc;
725 
727 
728  if (!RecoveryInProgress())
729  PG_RETURN_BOOL(true);
730 
732 
733  rc = WaitLatch(MyLatch,
735  1000L / WAITS_PER_SECOND,
736  WAIT_EVENT_PROMOTE);
737 
738  /*
739  * Emergency bailout if postmaster has died. This is to avoid the
740  * necessity for manual cleanup of all postmaster children.
741  */
742  if (rc & WL_POSTMASTER_DEATH)
743  ereport(FATAL,
744  (errcode(ERRCODE_ADMIN_SHUTDOWN),
745  errmsg("terminating connection due to unexpected postmaster exit"),
746  errcontext("while waiting on promotion")));
747  }
748 
750  (errmsg_plural("server did not promote within %d second",
751  "server did not promote within %d seconds",
752  wait_seconds,
753  wait_seconds)));
754  PG_RETURN_BOOL(false);
755 }
int16 AttrNumber
Definition: attnum.h:21
Datum numeric_in(PG_FUNCTION_ARGS)
Definition: numeric.c:627
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define CStringGetTextDatum(s)
Definition: builtins.h:94
unsigned int uint32
Definition: c.h:495
#define UINT64_FORMAT
Definition: c.h:538
int64 TimestampTz
Definition: timestamp.h:39
int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:1179
int errcode_for_file_access(void)
Definition: elog.c:881
int errhint(const char *fmt,...)
Definition: elog.c:1316
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#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 ereport(elevel,...)
Definition: elog.h:149
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2072
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2553
int FreeFile(FILE *file)
Definition: fd.c:2751
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1790
#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:644
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
#define PG_RETURN_NULL()
Definition: fmgr.h:345
#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:646
#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:101
struct Latch * MyLatch
Definition: globals.c:58
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1117
int i
Definition: isn.c:73
void ResetLatch(Latch *latch)
Definition: latch.c:725
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition: latch.c:518
#define WL_TIMEOUT
Definition: latch.h:130
#define WL_LATCH_SET
Definition: latch.h:127
#define WL_POSTMASTER_DEATH
Definition: latch.h:131
Assert(fmt[strlen(fmt) - 1] !='\n')
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:330
char * pstrdup(const char *in)
Definition: mcxt.c:1644
void pfree(void *pointer)
Definition: mcxt.c:1456
MemoryContext TopMemoryContext
Definition: mcxt.c:141
void * palloc0(Size size)
Definition: mcxt.c:1257
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:403
#define AllocSetContextCreate
Definition: memutils.h:126
#define ALLOCSET_START_SMALL_SIZES
Definition: memutils.h:167
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:121
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
static char promote_file[MAXPGPATH]
Definition: pg_ctl.c:99
static int wait_seconds
Definition: pg_ctl.c:75
Datum pg_lsn_mi(PG_FUNCTION_ARGS)
Definition: pg_lsn.c:225
#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
XLogRecPtr LogStandbySnapshot(void)
Definition: standby.c:1287
StringInfo makeStringInfo(void)
Definition: stringinfo.c:41
XLogRecPtr startpoint
Definition: xlogbackup.h:26
XLogRecPtr stoppoint
Definition: xlogbackup.h:33
Definition: c.h:676
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:605
#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
XLogRecPtr GetWalRcvFlushRecPtr(XLogRecPtr *latestChunkStart, TimeLineID *receiveTLI)
#define kill(pid, sig)
Definition: win32_port.h:485
#define SIGUSR1
Definition: win32_port.h:180
bool RecoveryInProgress(void)
Definition: xlog.c:6037
TimeLineID GetWALInsertionTimeLine(void)
Definition: xlog.c:6225
XLogRecPtr RequestXLogSwitch(bool mark_unimportant)
Definition: xlog.c:7693
SessionBackupState get_backup_status(void)
Definition: xlog.c:8731
int wal_segment_size
Definition: xlog.c:146
XLogRecPtr GetXLogInsertRecPtr(void)
Definition: xlog.c:9065
XLogRecPtr GetFlushRecPtr(TimeLineID *insertTLI)
Definition: xlog.c:6202
void register_persistent_abort_backup_handler(void)
Definition: xlog.c:9051
XLogRecPtr GetXLogWriteRecPtr(void)
Definition: xlog.c:9081
void do_pg_backup_start(const char *backupidstr, bool fast, List **tablespaces, BackupState *state, StringInfo tblspcmapfile)
Definition: xlog.c:8422
XLogRecPtr XLogRestorePoint(const char *rpName)
Definition: xlog.c:7711
void do_pg_backup_stop(BackupState *state, bool waitforarchive)
Definition: xlog.c:8750
#define PROMOTE_SIGNAL_FILE
Definition: xlog.h:301
SessionBackupState
Definition: xlog.h:278
@ SESSION_BACKUP_RUNNING
Definition: xlog.h:280
#define XLogIsNeeded()
Definition: xlog.h:107
#define XLogStandbyInfoActive()
Definition: xlog.h:121
#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:577
Datum pg_wal_lsn_diff(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:657
Datum pg_backup_start(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:62
Datum pg_create_restore_point(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:238
Datum pg_current_wal_insert_lsn(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:300
Datum pg_switch_wal(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:182
Datum pg_is_in_recovery(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:648
#define PG_SPLIT_WALFILE_NAME_COLS
Datum pg_split_walfile_name(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:468
Datum pg_backup_stop(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:129
#define WAITS_PER_SECOND
Datum pg_last_xact_replay_timestamp(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:633
Datum pg_log_standby_snapshot(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:207
static BackupState * backup_state
Definition: xlogfuncs.c:46
Datum pg_current_wal_lsn(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:279
Datum pg_last_wal_receive_lsn(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:343
#define PG_BACKUP_STOP_V2_COLS
Datum pg_walfile_name(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:443
Datum pg_current_wal_flush_lsn(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:321
Datum pg_walfile_name_offset(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:379
static MemoryContext backupcontext
Definition: xlogfuncs.c:50
static StringInfo tablespace_map
Definition: xlogfuncs.c:47
Datum pg_promote(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:675
Datum pg_get_wal_replay_pause_state(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:598
Datum pg_last_wal_replay_lsn(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:362
Datum pg_wal_replay_pause(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:523
Datum pg_wal_replay_resume(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:553
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