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