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-2019, 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.h"
23 #include "access/xlog_internal.h"
24 #include "access/xlogutils.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/ipc.h"
32 #include "storage/smgr.h"
33 #include "utils/builtins.h"
34 #include "utils/guc.h"
35 #include "utils/memutils.h"
36 #include "utils/numeric.h"
37 #include "utils/pg_lsn.h"
38 #include "utils/timestamp.h"
39 #include "utils/tuplestore.h"
40 
41 /*
42  * Store label file and tablespace map during non-exclusive backups.
43  */
46 
47 /*
48  * Called when the backend exits with a running non-exclusive base backup,
49  * to clean up state.
50  */
51 static void
53 {
56  (errmsg("aborting backup due to backend exiting before pg_stop_backup was called")));
57 }
58 
59 /*
60  * pg_start_backup: set up for taking an on-line backup dump
61  *
62  * Essentially what this does is to create a backup label file in $PGDATA,
63  * where it will be archived as part of the backup dump. The label file
64  * contains the user-supplied label string (typically this would be used
65  * to tell where the backup dump will be stored) and the starting time and
66  * starting WAL location for the dump.
67  *
68  * Permission checking for this function is managed through the normal
69  * GRANT system.
70  */
71 Datum
73 {
74  text *backupid = PG_GETARG_TEXT_PP(0);
75  bool fast = PG_GETARG_BOOL(1);
76  bool exclusive = PG_GETARG_BOOL(2);
77  char *backupidstr;
78  XLogRecPtr startpoint;
80 
81  backupidstr = text_to_cstring(backupid);
82 
83  if (status == SESSION_BACKUP_NON_EXCLUSIVE)
84  ereport(ERROR,
85  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
86  errmsg("a backup is already in progress in this session")));
87 
88  if (exclusive)
89  {
90  startpoint = do_pg_start_backup(backupidstr, fast, NULL, NULL,
91  NULL, NULL, false, true);
92  }
93  else
94  {
95  MemoryContext oldcontext;
96 
97  /*
98  * Label file and tablespace map file need to be long-lived, since
99  * they are read in pg_stop_backup.
100  */
102  label_file = makeStringInfo();
103  tblspc_map_file = makeStringInfo();
104  MemoryContextSwitchTo(oldcontext);
105 
106  startpoint = do_pg_start_backup(backupidstr, fast, NULL, label_file,
107  NULL, tblspc_map_file, false, true);
108 
110  }
111 
112  PG_RETURN_LSN(startpoint);
113 }
114 
115 /*
116  * pg_stop_backup: finish taking an on-line backup dump
117  *
118  * We write an end-of-backup WAL record, and remove the backup label file
119  * created by pg_start_backup, creating a backup history file in pg_wal
120  * instead (whence it will immediately be archived). The backup history file
121  * contains the same info found in the label file, plus the backup-end time
122  * and WAL location. Before 9.0, the backup-end time was read from the backup
123  * history file at the beginning of archive recovery, but we now use the WAL
124  * record for that and the file is for informational and debug purposes only.
125  *
126  * Note: different from CancelBackup which just cancels online backup mode.
127  *
128  * Note: this version is only called to stop an exclusive backup. The function
129  * pg_stop_backup_v2 (overloaded as pg_stop_backup in SQL) is called to
130  * stop non-exclusive backups.
131  *
132  * Permission checking for this function is managed through the normal
133  * GRANT system.
134  */
135 Datum
137 {
138  XLogRecPtr stoppoint;
140 
141  if (status == SESSION_BACKUP_NON_EXCLUSIVE)
142  ereport(ERROR,
143  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
144  errmsg("non-exclusive backup in progress"),
145  errhint("Did you mean to use pg_stop_backup('f')?")));
146 
147  /*
148  * Exclusive backups were typically started in a different connection, so
149  * don't try to verify that status of backup is set to
150  * SESSION_BACKUP_EXCLUSIVE in this function. Actual verification that an
151  * exclusive backup is in fact running is handled inside
152  * do_pg_stop_backup.
153  */
154  stoppoint = do_pg_stop_backup(NULL, true, NULL);
155 
156  PG_RETURN_LSN(stoppoint);
157 }
158 
159 
160 /*
161  * pg_stop_backup_v2: finish taking exclusive or nonexclusive on-line backup.
162  *
163  * Works the same as pg_stop_backup, except for non-exclusive backups it returns
164  * the backup label and tablespace map files as text fields in as part of the
165  * resultset.
166  *
167  * The first parameter (variable 'exclusive') allows the user to tell us if
168  * this is an exclusive or a non-exclusive backup.
169  *
170  * The second parameter (variable 'waitforarchive'), which is optional,
171  * allows the user to choose if they want to wait for the WAL to be archived
172  * or if we should just return as soon as the WAL record is written.
173  *
174  * Permission checking for this function is managed through the normal
175  * GRANT system.
176  */
177 Datum
179 {
180  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
181  TupleDesc tupdesc;
182  Tuplestorestate *tupstore;
183  MemoryContext per_query_ctx;
184  MemoryContext oldcontext;
185  Datum values[3];
186  bool nulls[3];
187 
188  bool exclusive = PG_GETARG_BOOL(0);
189  bool waitforarchive = PG_GETARG_BOOL(1);
190  XLogRecPtr stoppoint;
192 
193  /* check to see if caller supports us returning a tuplestore */
194  if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
195  ereport(ERROR,
196  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
197  errmsg("set-valued function called in context that cannot accept a set")));
198  if (!(rsinfo->allowedModes & SFRM_Materialize))
199  ereport(ERROR,
200  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
201  errmsg("materialize mode required, but it is not " \
202  "allowed in this context")));
203 
204  /* Build a tuple descriptor for our result type */
205  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
206  elog(ERROR, "return type must be a row type");
207 
208  per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
209  oldcontext = MemoryContextSwitchTo(per_query_ctx);
210 
211  tupstore = tuplestore_begin_heap(true, false, work_mem);
212  rsinfo->returnMode = SFRM_Materialize;
213  rsinfo->setResult = tupstore;
214  rsinfo->setDesc = tupdesc;
215 
216  MemoryContextSwitchTo(oldcontext);
217 
218  MemSet(values, 0, sizeof(values));
219  MemSet(nulls, 0, sizeof(nulls));
220 
221  if (exclusive)
222  {
223  if (status == SESSION_BACKUP_NON_EXCLUSIVE)
224  ereport(ERROR,
225  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
226  errmsg("non-exclusive backup in progress"),
227  errhint("Did you mean to use pg_stop_backup('f')?")));
228 
229  /*
230  * Stop the exclusive backup, and since we're in an exclusive backup
231  * return NULL for both backup_label and tablespace_map.
232  */
233  stoppoint = do_pg_stop_backup(NULL, waitforarchive, NULL);
234 
235  nulls[1] = true;
236  nulls[2] = true;
237  }
238  else
239  {
240  if (status != SESSION_BACKUP_NON_EXCLUSIVE)
241  ereport(ERROR,
242  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
243  errmsg("non-exclusive backup is not in progress"),
244  errhint("Did you mean to use pg_stop_backup('t')?")));
245 
246  /*
247  * Stop the non-exclusive backup. Return a copy of the backup label
248  * and tablespace map so they can be written to disk by the caller.
249  */
250  stoppoint = do_pg_stop_backup(label_file->data, waitforarchive, NULL);
252 
253  values[1] = CStringGetTextDatum(label_file->data);
254  values[2] = CStringGetTextDatum(tblspc_map_file->data);
255 
256  /* Free structures allocated in TopMemoryContext */
257  pfree(label_file->data);
258  pfree(label_file);
259  label_file = NULL;
260  pfree(tblspc_map_file->data);
261  pfree(tblspc_map_file);
262  tblspc_map_file = NULL;
263  }
264 
265  /* Stoppoint is included on both exclusive and nonexclusive backups */
266  values[0] = LSNGetDatum(stoppoint);
267 
268  tuplestore_putvalues(tupstore, tupdesc, values, nulls);
269  tuplestore_donestoring(tupstore);
270 
271  return (Datum) 0;
272 }
273 
274 /*
275  * pg_switch_wal: switch to next xlog file
276  *
277  * Permission checking for this function is managed through the normal
278  * GRANT system.
279  */
280 Datum
282 {
283  XLogRecPtr switchpoint;
284 
285  if (RecoveryInProgress())
286  ereport(ERROR,
287  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
288  errmsg("recovery is in progress"),
289  errhint("WAL control functions cannot be executed during recovery.")));
290 
291  switchpoint = RequestXLogSwitch(false);
292 
293  /*
294  * As a convenience, return the WAL location of the switch record
295  */
296  PG_RETURN_LSN(switchpoint);
297 }
298 
299 /*
300  * pg_create_restore_point: a named point for restore
301  *
302  * Permission checking for this function is managed through the normal
303  * GRANT system.
304  */
305 Datum
307 {
308  text *restore_name = PG_GETARG_TEXT_PP(0);
309  char *restore_name_str;
310  XLogRecPtr restorepoint;
311 
312  if (RecoveryInProgress())
313  ereport(ERROR,
314  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
315  (errmsg("recovery is in progress"),
316  errhint("WAL control functions cannot be executed during recovery."))));
317 
318  if (!XLogIsNeeded())
319  ereport(ERROR,
320  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
321  errmsg("WAL level not sufficient for creating a restore point"),
322  errhint("wal_level must be set to \"replica\" or \"logical\" at server start.")));
323 
324  restore_name_str = text_to_cstring(restore_name);
325 
326  if (strlen(restore_name_str) >= MAXFNAMELEN)
327  ereport(ERROR,
328  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
329  errmsg("value too long for restore point (maximum %d characters)", MAXFNAMELEN - 1)));
330 
331  restorepoint = XLogRestorePoint(restore_name_str);
332 
333  /*
334  * As a convenience, return the WAL location of the restore point record
335  */
336  PG_RETURN_LSN(restorepoint);
337 }
338 
339 /*
340  * Report the current WAL write location (same format as pg_start_backup etc)
341  *
342  * This is useful for determining how much of WAL is visible to an external
343  * archiving process. Note that the data before this point is written out
344  * to the kernel, but is not necessarily synced to disk.
345  */
346 Datum
348 {
349  XLogRecPtr current_recptr;
350 
351  if (RecoveryInProgress())
352  ereport(ERROR,
353  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
354  errmsg("recovery is in progress"),
355  errhint("WAL control functions cannot be executed during recovery.")));
356 
357  current_recptr = GetXLogWriteRecPtr();
358 
359  PG_RETURN_LSN(current_recptr);
360 }
361 
362 /*
363  * Report the current WAL insert location (same format as pg_start_backup etc)
364  *
365  * This function is mostly for debugging purposes.
366  */
367 Datum
369 {
370  XLogRecPtr current_recptr;
371 
372  if (RecoveryInProgress())
373  ereport(ERROR,
374  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
375  errmsg("recovery is in progress"),
376  errhint("WAL control functions cannot be executed during recovery.")));
377 
378  current_recptr = GetXLogInsertRecPtr();
379 
380  PG_RETURN_LSN(current_recptr);
381 }
382 
383 /*
384  * Report the current WAL flush location (same format as pg_start_backup etc)
385  *
386  * This function is mostly for debugging purposes.
387  */
388 Datum
390 {
391  XLogRecPtr current_recptr;
392 
393  if (RecoveryInProgress())
394  ereport(ERROR,
395  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
396  errmsg("recovery is in progress"),
397  errhint("WAL control functions cannot be executed during recovery.")));
398 
399  current_recptr = GetFlushRecPtr();
400 
401  PG_RETURN_LSN(current_recptr);
402 }
403 
404 /*
405  * Report the last WAL receive location (same format as pg_start_backup etc)
406  *
407  * This is useful for determining how much of WAL is guaranteed to be received
408  * and synced to disk by walreceiver.
409  */
410 Datum
412 {
413  XLogRecPtr recptr;
414 
415  recptr = GetWalRcvWriteRecPtr(NULL, NULL);
416 
417  if (recptr == 0)
418  PG_RETURN_NULL();
419 
420  PG_RETURN_LSN(recptr);
421 }
422 
423 /*
424  * Report the last WAL replay location (same format as pg_start_backup etc)
425  *
426  * This is useful for determining how much of WAL is visible to read-only
427  * connections during recovery.
428  */
429 Datum
431 {
432  XLogRecPtr recptr;
433 
434  recptr = GetXLogReplayRecPtr(NULL);
435 
436  if (recptr == 0)
437  PG_RETURN_NULL();
438 
439  PG_RETURN_LSN(recptr);
440 }
441 
442 /*
443  * Compute an xlog file name and decimal byte offset given a WAL location,
444  * such as is returned by pg_stop_backup() or pg_switch_wal().
445  *
446  * Note that a location exactly at a segment boundary is taken to be in
447  * the previous segment. This is usually the right thing, since the
448  * expected usage is to determine which xlog file(s) are ready to archive.
449  */
450 Datum
452 {
453  XLogSegNo xlogsegno;
454  uint32 xrecoff;
455  XLogRecPtr locationpoint = PG_GETARG_LSN(0);
456  char xlogfilename[MAXFNAMELEN];
457  Datum values[2];
458  bool isnull[2];
459  TupleDesc resultTupleDesc;
460  HeapTuple resultHeapTuple;
461  Datum result;
462 
463  if (RecoveryInProgress())
464  ereport(ERROR,
465  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
466  errmsg("recovery is in progress"),
467  errhint("%s cannot be executed during recovery.",
468  "pg_walfile_name_offset()")));
469 
470  /*
471  * Construct a tuple descriptor for the result row. This must match this
472  * function's pg_proc entry!
473  */
474  resultTupleDesc = CreateTemplateTupleDesc(2);
475  TupleDescInitEntry(resultTupleDesc, (AttrNumber) 1, "file_name",
476  TEXTOID, -1, 0);
477  TupleDescInitEntry(resultTupleDesc, (AttrNumber) 2, "file_offset",
478  INT4OID, -1, 0);
479 
480  resultTupleDesc = BlessTupleDesc(resultTupleDesc);
481 
482  /*
483  * xlogfilename
484  */
485  XLByteToPrevSeg(locationpoint, xlogsegno, wal_segment_size);
486  XLogFileName(xlogfilename, ThisTimeLineID, xlogsegno, wal_segment_size);
487 
488  values[0] = CStringGetTextDatum(xlogfilename);
489  isnull[0] = false;
490 
491  /*
492  * offset
493  */
494  xrecoff = XLogSegmentOffset(locationpoint, wal_segment_size);
495 
496  values[1] = UInt32GetDatum(xrecoff);
497  isnull[1] = false;
498 
499  /*
500  * Tuple jam: Having first prepared your Datums, then squash together
501  */
502  resultHeapTuple = heap_form_tuple(resultTupleDesc, values, isnull);
503 
504  result = HeapTupleGetDatum(resultHeapTuple);
505 
506  PG_RETURN_DATUM(result);
507 }
508 
509 /*
510  * Compute an xlog file name given a WAL location,
511  * such as is returned by pg_stop_backup() or pg_switch_wal().
512  */
513 Datum
515 {
516  XLogSegNo xlogsegno;
517  XLogRecPtr locationpoint = PG_GETARG_LSN(0);
518  char xlogfilename[MAXFNAMELEN];
519 
520  if (RecoveryInProgress())
521  ereport(ERROR,
522  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
523  errmsg("recovery is in progress"),
524  errhint("%s cannot be executed during recovery.",
525  "pg_walfile_name()")));
526 
527  XLByteToPrevSeg(locationpoint, xlogsegno, wal_segment_size);
528  XLogFileName(xlogfilename, ThisTimeLineID, xlogsegno, wal_segment_size);
529 
530  PG_RETURN_TEXT_P(cstring_to_text(xlogfilename));
531 }
532 
533 /*
534  * pg_wal_replay_pause - pause recovery now
535  *
536  * Permission checking for this function is managed through the normal
537  * GRANT system.
538  */
539 Datum
541 {
542  if (!RecoveryInProgress())
543  ereport(ERROR,
544  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
545  errmsg("recovery is not in progress"),
546  errhint("Recovery control functions can only be executed during recovery.")));
547 
548  SetRecoveryPause(true);
549 
550  PG_RETURN_VOID();
551 }
552 
553 /*
554  * pg_wal_replay_resume - resume recovery now
555  *
556  * Permission checking for this function is managed through the normal
557  * GRANT system.
558  */
559 Datum
561 {
562  if (!RecoveryInProgress())
563  ereport(ERROR,
564  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
565  errmsg("recovery is not in progress"),
566  errhint("Recovery control functions can only be executed during recovery.")));
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  * Returns timestamp of latest processed commit/abort record.
590  *
591  * When the server has been started normally without recovery the function
592  * returns NULL.
593  */
594 Datum
596 {
597  TimestampTz xtime;
598 
599  xtime = GetLatestXTime();
600  if (xtime == 0)
601  PG_RETURN_NULL();
602 
603  PG_RETURN_TIMESTAMPTZ(xtime);
604 }
605 
606 /*
607  * Returns bool with current recovery mode, a global state.
608  */
609 Datum
611 {
613 }
614 
615 /*
616  * Compute the difference in bytes between two WAL locations.
617  */
618 Datum
620 {
621  Datum result;
622 
624  PG_GETARG_DATUM(0),
625  PG_GETARG_DATUM(1));
626 
627  PG_RETURN_NUMERIC(result);
628 }
629 
630 /*
631  * Returns bool with current on-line backup mode, a global state.
632  */
633 Datum
635 {
637 }
638 
639 /*
640  * Returns start time of an online exclusive backup.
641  *
642  * When there's no exclusive backup in progress, the function
643  * returns NULL.
644  */
645 Datum
647 {
648  Datum xtime;
649  FILE *lfp;
650  char fline[MAXPGPATH];
651  char backup_start_time[30];
652 
653  /*
654  * See if label file is present
655  */
656  lfp = AllocateFile(BACKUP_LABEL_FILE, "r");
657  if (lfp == NULL)
658  {
659  if (errno != ENOENT)
660  ereport(ERROR,
662  errmsg("could not read file \"%s\": %m",
664  PG_RETURN_NULL();
665  }
666 
667  /*
668  * Parse the file to find the START TIME line.
669  */
670  backup_start_time[0] = '\0';
671  while (fgets(fline, sizeof(fline), lfp) != NULL)
672  {
673  if (sscanf(fline, "START TIME: %25[^\n]\n", backup_start_time) == 1)
674  break;
675  }
676 
677  /* Check for a read error. */
678  if (ferror(lfp))
679  ereport(ERROR,
681  errmsg("could not read file \"%s\": %m", BACKUP_LABEL_FILE)));
682 
683  /* Close the backup label file. */
684  if (FreeFile(lfp))
685  ereport(ERROR,
687  errmsg("could not close file \"%s\": %m", BACKUP_LABEL_FILE)));
688 
689  if (strlen(backup_start_time) == 0)
690  ereport(ERROR,
691  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
692  errmsg("invalid data in file \"%s\"", BACKUP_LABEL_FILE)));
693 
694  /*
695  * Convert the time string read from file to TimestampTz form.
696  */
698  CStringGetDatum(backup_start_time),
700  Int32GetDatum(-1));
701 
702  PG_RETURN_DATUM(xtime);
703 }
704 
705 /*
706  * Promotes a standby server.
707  *
708  * A result of "true" means that promotion has been completed if "wait" is
709  * "true", or initiated if "wait" is false.
710  */
711 Datum
713 {
714  bool wait = PG_GETARG_BOOL(0);
715  int wait_seconds = PG_GETARG_INT32(1);
716  FILE *promote_file;
717  int i;
718 
719  if (!RecoveryInProgress())
720  ereport(ERROR,
721  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
722  errmsg("recovery is not in progress"),
723  errhint("Recovery control functions can only be executed during recovery.")));
724 
725  if (wait_seconds <= 0)
726  ereport(ERROR,
727  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
728  errmsg("\"wait_seconds\" must not be negative or zero")));
729 
730  /* create the promote signal file */
731  promote_file = AllocateFile(PROMOTE_SIGNAL_FILE, "w");
732  if (!promote_file)
733  ereport(ERROR,
735  errmsg("could not create file \"%s\": %m",
737 
738  if (FreeFile(promote_file))
739  ereport(ERROR,
741  errmsg("could not write file \"%s\": %m",
743 
744  /* signal the postmaster */
745  if (kill(PostmasterPid, SIGUSR1) != 0)
746  {
748  (errmsg("failed to send signal to postmaster: %m")));
749  (void) unlink(PROMOTE_SIGNAL_FILE);
750  PG_RETURN_BOOL(false);
751  }
752 
753  /* return immediately if waiting was not requested */
754  if (!wait)
755  PG_RETURN_BOOL(true);
756 
757  /* wait for the amount of time wanted until promotion */
758 #define WAITS_PER_SECOND 10
759  for (i = 0; i < WAITS_PER_SECOND * wait_seconds; i++)
760  {
761  int rc;
762 
764 
765  if (!RecoveryInProgress())
766  PG_RETURN_BOOL(true);
767 
769 
770  rc = WaitLatch(MyLatch,
772  1000L / WAITS_PER_SECOND,
774 
775  /*
776  * Emergency bailout if postmaster has died. This is to avoid the
777  * necessity for manual cleanup of all postmaster children.
778  */
779  if (rc & WL_POSTMASTER_DEATH)
780  PG_RETURN_BOOL(false);
781  }
782 
784  (errmsg("server did not promote within %d seconds", wait_seconds)));
785  PG_RETURN_BOOL(false);
786 }
#define PG_RETURN_NUMERIC(x)
Definition: numeric.h:54
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
Definition: tuplestore.c:750
Datum pg_last_wal_receive_lsn(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:411
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
Datum pg_promote(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:712
Datum pg_switch_wal(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:281
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
XLogRecPtr RequestXLogSwitch(bool mark_unimportant)
Definition: xlog.c:9414
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:196
static StringInfo label_file
Definition: xlogfuncs.c:44
int errhint(const char *fmt,...)
Definition: elog.c:1069
XLogRecPtr GetWalRcvWriteRecPtr(XLogRecPtr *latestChunkStart, TimeLineID *receiveTLI)
static int wait_seconds
Definition: pg_ctl.c:80
#define WL_TIMEOUT
Definition: latch.h:127
int wal_segment_size
Definition: xlog.c:112
Datum pg_start_backup(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:72
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:44
Datum pg_is_in_backup(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:634
#define SIGUSR1
Definition: win32_port.h:166
int64 TimestampTz
Definition: timestamp.h:39
#define XLByteToPrevSeg(xlrp, logSegNo, wal_segsz_bytes)
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:263
SessionBackupState get_backup_status(void)
Definition: xlog.c:10718
#define PROMOTE_SIGNAL_FILE
Definition: xlog.h:365
Datum pg_lsn_mi(PG_FUNCTION_ARGS)
Definition: pg_lsn.c:230
#define XLogIsNeeded()
Definition: xlog.h:181
StringInfo makeStringInfo(void)
Definition: stringinfo.c:41
#define tuplestore_donestoring(state)
Definition: tuplestore.h:60
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Datum pg_last_wal_replay_lsn(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:430
int errcode(int sqlerrcode)
Definition: elog.c:608
#define LSNGetDatum(X)
Definition: pg_lsn.h:22
#define MemSet(start, val, len)
Definition: c.h:962
#define kill(pid, sig)
Definition: win32_port.h:426
XLogRecPtr GetFlushRecPtr(void)
Definition: xlog.c:8267
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
TimestampTz GetLatestXTime(void)
Definition: xlog.c:6074
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:269
bool BackupInProgress(void)
Definition: xlog.c:11468
bool RecoveryInProgress(void)
Definition: xlog.c:7935
Datum pg_wal_lsn_diff(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:619
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
void ResetLatch(Latch *latch)
Definition: latch.c:519
XLogRecPtr do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p, StringInfo labelfile, List **tablespaces, StringInfo tblspcmapfile, bool infotbssize, bool needtblspcmapfile)
Definition: xlog.c:10220
static void nonexclusive_base_backup_cleanup(int code, Datum arg)
Definition: xlogfuncs.c:52
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition: latch.c:344
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
bool RecoveryIsPaused(void)
Definition: xlog.c:5936
#define PG_RETURN_LSN(x)
Definition: pg_lsn.h:25
void pfree(void *pointer)
Definition: mcxt.c:1056
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
XLogRecPtr do_pg_stop_backup(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p)
Definition: xlog.c:10739
XLogRecPtr GetXLogInsertRecPtr(void)
Definition: xlog.c:11191
#define MAXPGPATH
XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI)
Definition: xlog.c:11172
SessionBackupState
Definition: xlog.h:339
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2052
void cancel_before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:390
Datum pg_wal_replay_resume(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:560
Datum pg_stop_backup(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:136
uint64 XLogSegNo
Definition: xlogdefs.h:41
int errcode_for_file_access(void)
Definition: elog.c:631
#define CStringGetDatum(X)
Definition: postgres.h:578
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2242
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:333
unsigned int uint32
Definition: c.h:359
#define UInt32GetDatum(X)
Definition: postgres.h:493
Datum pg_create_restore_point(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:306
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:603
#define ereport(elevel, rest)
Definition: elog.h:141
MemoryContext TopMemoryContext
Definition: mcxt.c:44
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:619
Datum pg_is_wal_replay_paused(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:577
pid_t PostmasterPid
Definition: globals.c:95
#define WARNING
Definition: elog.h:40
#define MAXFNAMELEN
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
Definition: tuplestore.c:318
#define WL_POSTMASTER_DEATH
Definition: latch.h:128
#define PG_GETARG_LSN(n)
Definition: pg_lsn.h:24
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
uintptr_t Datum
Definition: postgres.h:367
Datum pg_wal_replay_pause(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:540
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:343
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)
int work_mem
Definition: globals.c:121
#define InvalidOid
Definition: postgres_ext.h:36
TimeLineID ThisTimeLineID
Definition: xlog.c:187
Datum pg_walfile_name_offset(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:451
int allowedModes
Definition: execnodes.h:302
#define PG_RETURN_VOID()
Definition: fmgr.h:339
static StringInfo tblspc_map_file
Definition: xlogfuncs.c:45
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:361
XLogRecPtr GetXLogWriteRecPtr(void)
Definition: xlog.c:11207
SetFunctionReturnMode returnMode
Definition: execnodes.h:304
text * cstring_to_text(const char *s)
Definition: varlena.c:171
uint64 XLogRecPtr
Definition: xlogdefs.h:21
Datum pg_current_wal_flush_lsn(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:389
XLogRecPtr XLogRestorePoint(const char *rpName)
Definition: xlog.c:9432
Datum pg_current_wal_lsn(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:347
#define XLogFileName(fname, tli, logSegNo, wal_segsz_bytes)
Datum pg_walfile_name(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:514
void SetRecoveryPause(bool recoveryPause)
Definition: xlog.c:5948
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:220
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:230
Tuplestorestate * setResult
Definition: execnodes.h:307
static char promote_file[MAXPGPATH]
Definition: pg_ctl.c:105
int FreeFile(FILE *file)
Definition: fd.c:2441
static Datum values[MAXATTR]
Definition: bootstrap.c:167
char * text_to_cstring(const text *t)
Definition: varlena.c:204
ExprContext * econtext
Definition: execnodes.h:300
#define WAITS_PER_SECOND
#define Int32GetDatum(X)
Definition: postgres.h:479
Datum timestamptz_in(PG_FUNCTION_ARGS)
Definition: timestamp.c:400
TupleDesc setDesc
Definition: execnodes.h:308
int errmsg(const char *fmt,...)
Definition: elog.c:822
Datum pg_stop_backup_v2(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:178
#define elog(elevel,...)
Definition: elog.h:228
int i
Datum pg_current_wal_insert_lsn(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:368
void do_pg_abort_backup(void)
Definition: xlog.c:11144
#define CStringGetTextDatum(s)
Definition: builtins.h:83
void * arg
struct Latch * MyLatch
Definition: globals.c:54
#define BACKUP_LABEL_FILE
Definition: xlog.h:358
Definition: c.h:556
#define PG_FUNCTION_ARGS
Definition: fmgr.h:188
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:99
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:226
Datum pg_is_in_recovery(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:610
Datum pg_last_xact_replay_timestamp(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:595
#define WL_LATCH_SET
Definition: latch.h:124
int16 AttrNumber
Definition: attnum.h:21
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:617
#define PG_RETURN_NULL()
Definition: fmgr.h:335
Datum pg_backup_start_time(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:646