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