PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
xlogfuncs.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * xlogfuncs.c
4  *
5  * PostgreSQL transaction log manager user interface functions
6  *
7  * This file contains WAL control and information functions.
8  *
9  *
10  * Portions Copyright (c) 1996-2017, 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 "access/htup_details.h"
20 #include "access/xlog.h"
21 #include "access/xlog_internal.h"
22 #include "access/xlogutils.h"
23 #include "catalog/catalog.h"
24 #include "catalog/pg_type.h"
25 #include "funcapi.h"
26 #include "miscadmin.h"
28 #include "storage/smgr.h"
29 #include "utils/builtins.h"
30 #include "utils/memutils.h"
31 #include "utils/numeric.h"
32 #include "utils/guc.h"
33 #include "utils/pg_lsn.h"
34 #include "utils/timestamp.h"
35 #include "utils/tuplestore.h"
36 #include "storage/fd.h"
37 #include "storage/ipc.h"
38 
39 
40 /*
41  * Store label file and tablespace map during non-exclusive backups.
42  */
45 static bool exclusive_backup_running = false;
46 static bool nonexclusive_backup_running = false;
47 
48 /*
49  * Called when the backend exits with a running non-exclusive base backup,
50  * to clean up state.
51  */
52 static void
54 {
57  (errmsg("aborting backup due to backend exiting before pg_stop_backup was called")));
58 }
59 
60 /*
61  * pg_start_backup: set up for taking an on-line backup dump
62  *
63  * Essentially what this does is to create a backup label file in $PGDATA,
64  * where it will be archived as part of the backup dump. The label file
65  * contains the user-supplied label string (typically this would be used
66  * to tell where the backup dump will be stored) and the starting time and
67  * starting WAL location for the dump.
68  *
69  * Permission checking for this function is managed through the normal
70  * GRANT system.
71  */
72 Datum
74 {
75  text *backupid = PG_GETARG_TEXT_P(0);
76  bool fast = PG_GETARG_BOOL(1);
77  bool exclusive = PG_GETARG_BOOL(2);
78  char *backupidstr;
79  XLogRecPtr startpoint;
80  DIR *dir;
81 
82  backupidstr = text_to_cstring(backupid);
83 
85  ereport(ERROR,
86  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
87  errmsg("a backup is already in progress in this session")));
88 
89  /* Make sure we can open the directory with tablespaces in it */
90  dir = AllocateDir("pg_tblspc");
91  if (!dir)
92  ereport(ERROR,
93  (errmsg("could not open directory \"%s\": %m", "pg_tblspc")));
94 
95  if (exclusive)
96  {
97  startpoint = do_pg_start_backup(backupidstr, fast, NULL, NULL,
98  dir, NULL, NULL, false, true);
100  }
101  else
102  {
103  MemoryContext oldcontext;
104 
105  /*
106  * Label file and tablespace map file need to be long-lived, since
107  * they are read in pg_stop_backup.
108  */
110  label_file = makeStringInfo();
111  tblspc_map_file = makeStringInfo();
112  MemoryContextSwitchTo(oldcontext);
113 
114  startpoint = do_pg_start_backup(backupidstr, fast, NULL, label_file,
115  dir, NULL, tblspc_map_file, false, true);
117 
119  }
120 
121  FreeDir(dir);
122 
123  PG_RETURN_LSN(startpoint);
124 }
125 
126 /*
127  * pg_stop_backup: finish taking an on-line backup dump
128  *
129  * We write an end-of-backup WAL record, and remove the backup label file
130  * created by pg_start_backup, creating a backup history file in pg_wal
131  * instead (whence it will immediately be archived). The backup history file
132  * contains the same info found in the label file, plus the backup-end time
133  * and WAL location. Before 9.0, the backup-end time was read from the backup
134  * history file at the beginning of archive recovery, but we now use the WAL
135  * record for that and the file is for informational and debug purposes only.
136  *
137  * Note: different from CancelBackup which just cancels online backup mode.
138  *
139  * Note: this version is only called to stop an exclusive backup. The function
140  * pg_stop_backup_v2 (overloaded as pg_stop_backup in SQL) is called to
141  * stop non-exclusive backups.
142  *
143  * Permission checking for this function is managed through the normal
144  * GRANT system.
145  */
146 Datum
148 {
149  XLogRecPtr stoppoint;
150 
152  ereport(ERROR,
153  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
154  errmsg("non-exclusive backup in progress"),
155  errhint("Did you mean to use pg_stop_backup('f')?")));
156 
157  /*
158  * Exclusive backups were typically started in a different connection, so
159  * don't try to verify that exclusive_backup_running is set in this one.
160  * Actual verification that an exclusive backup is in fact running is
161  * handled inside do_pg_stop_backup.
162  */
163  stoppoint = do_pg_stop_backup(NULL, true, NULL);
164 
165  exclusive_backup_running = false;
166 
167  PG_RETURN_LSN(stoppoint);
168 }
169 
170 
171 /*
172  * pg_stop_backup_v2: finish taking exclusive or nonexclusive on-line backup.
173  *
174  * Works the same as pg_stop_backup, except for non-exclusive backups it returns
175  * the backup label and tablespace map files as text fields in as part of the
176  * resultset.
177  *
178  * Permission checking for this function is managed through the normal
179  * GRANT system.
180  */
181 Datum
183 {
184  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
185  TupleDesc tupdesc;
186  Tuplestorestate *tupstore;
187  MemoryContext per_query_ctx;
188  MemoryContext oldcontext;
189  Datum values[3];
190  bool nulls[3];
191 
192  bool exclusive = PG_GETARG_BOOL(0);
193  XLogRecPtr stoppoint;
194 
195  /* check to see if caller supports us returning a tuplestore */
196  if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
197  ereport(ERROR,
198  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
199  errmsg("set-valued function called in context that cannot accept a set")));
200  if (!(rsinfo->allowedModes & SFRM_Materialize))
201  ereport(ERROR,
202  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
203  errmsg("materialize mode required, but it is not " \
204  "allowed in this context")));
205 
206  /* Build a tuple descriptor for our result type */
207  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
208  elog(ERROR, "return type must be a row type");
209 
210  per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
211  oldcontext = MemoryContextSwitchTo(per_query_ctx);
212 
213  tupstore = tuplestore_begin_heap(true, false, work_mem);
214  rsinfo->returnMode = SFRM_Materialize;
215  rsinfo->setResult = tupstore;
216  rsinfo->setDesc = tupdesc;
217 
218  MemoryContextSwitchTo(oldcontext);
219 
220  MemSet(values, 0, sizeof(values));
221  MemSet(nulls, 0, sizeof(nulls));
222 
223  if (exclusive)
224  {
226  ereport(ERROR,
227  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
228  errmsg("non-exclusive backup in progress"),
229  errhint("Did you mean to use pg_stop_backup('f')?")));
230 
231  /*
232  * Stop the exclusive backup, and since we're in an exclusive backup
233  * return NULL for both backup_label and tablespace_map.
234  */
235  stoppoint = do_pg_stop_backup(NULL, true, NULL);
236  exclusive_backup_running = false;
237 
238  nulls[1] = true;
239  nulls[2] = true;
240  }
241  else
242  {
244  ereport(ERROR,
245  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
246  errmsg("non-exclusive backup is not in progress"),
247  errhint("Did you mean to use pg_stop_backup('t')?")));
248 
249  /*
250  * Stop the non-exclusive backup. Return a copy of the backup label
251  * and tablespace map so they can be written to disk by the caller.
252  */
253  stoppoint = do_pg_stop_backup(label_file->data, true, NULL);
256 
257  values[1] = CStringGetTextDatum(label_file->data);
258  values[2] = CStringGetTextDatum(tblspc_map_file->data);
259 
260  /* Free structures allocated in TopMemoryContext */
261  pfree(label_file->data);
262  pfree(label_file);
263  label_file = NULL;
264  pfree(tblspc_map_file->data);
265  pfree(tblspc_map_file);
266  tblspc_map_file = NULL;
267  }
268 
269  /* Stoppoint is included on both exclusive and nonexclusive backups */
270  values[0] = LSNGetDatum(stoppoint);
271 
272  tuplestore_putvalues(tupstore, tupdesc, values, nulls);
273  tuplestore_donestoring(typstore);
274 
275  return (Datum) 0;
276 }
277 
278 /*
279  * pg_switch_wal: switch to next xlog file
280  *
281  * Permission checking for this function is managed through the normal
282  * GRANT system.
283  */
284 Datum
286 {
287  XLogRecPtr switchpoint;
288 
289  if (RecoveryInProgress())
290  ereport(ERROR,
291  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
292  errmsg("recovery is in progress"),
293  errhint("WAL control functions cannot be executed during recovery.")));
294 
295  switchpoint = RequestXLogSwitch(false);
296 
297  /*
298  * As a convenience, return the WAL location of the switch record
299  */
300  PG_RETURN_LSN(switchpoint);
301 }
302 
303 /*
304  * pg_create_restore_point: a named point for restore
305  *
306  * Permission checking for this function is managed through the normal
307  * GRANT system.
308  */
309 Datum
311 {
312  text *restore_name = PG_GETARG_TEXT_P(0);
313  char *restore_name_str;
314  XLogRecPtr restorepoint;
315 
316  if (RecoveryInProgress())
317  ereport(ERROR,
318  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
319  (errmsg("recovery is in progress"),
320  errhint("WAL control functions cannot be executed during recovery."))));
321 
322  if (!XLogIsNeeded())
323  ereport(ERROR,
324  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
325  errmsg("WAL level not sufficient for creating a restore point"),
326  errhint("wal_level must be set to \"replica\" or \"logical\" at server start.")));
327 
328  restore_name_str = text_to_cstring(restore_name);
329 
330  if (strlen(restore_name_str) >= MAXFNAMELEN)
331  ereport(ERROR,
332  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
333  errmsg("value too long for restore point (maximum %d characters)", MAXFNAMELEN - 1)));
334 
335  restorepoint = XLogRestorePoint(restore_name_str);
336 
337  /*
338  * As a convenience, return the WAL location of the restore point record
339  */
340  PG_RETURN_LSN(restorepoint);
341 }
342 
343 /*
344  * Report the current WAL write location (same format as pg_start_backup etc)
345  *
346  * This is useful for determining how much of WAL is visible to an external
347  * archiving process. Note that the data before this point is written out
348  * to the kernel, but is not necessarily synced to disk.
349  */
350 Datum
352 {
353  XLogRecPtr current_recptr;
354 
355  if (RecoveryInProgress())
356  ereport(ERROR,
357  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
358  errmsg("recovery is in progress"),
359  errhint("WAL control functions cannot be executed during recovery.")));
360 
361  current_recptr = GetXLogWriteRecPtr();
362 
363  PG_RETURN_LSN(current_recptr);
364 }
365 
366 /*
367  * Report the current WAL insert location (same format as pg_start_backup etc)
368  *
369  * This function is mostly for debugging purposes.
370  */
371 Datum
373 {
374  XLogRecPtr current_recptr;
375 
376  if (RecoveryInProgress())
377  ereport(ERROR,
378  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
379  errmsg("recovery is in progress"),
380  errhint("WAL control functions cannot be executed during recovery.")));
381 
382  current_recptr = GetXLogInsertRecPtr();
383 
384  PG_RETURN_LSN(current_recptr);
385 }
386 
387 /*
388  * Report the current WAL flush location (same format as pg_start_backup etc)
389  *
390  * This function is mostly for debugging purposes.
391  */
392 Datum
394 {
395  XLogRecPtr current_recptr;
396 
397  if (RecoveryInProgress())
398  ereport(ERROR,
399  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
400  errmsg("recovery is in progress"),
401  errhint("WAL control functions cannot be executed during recovery.")));
402 
403  current_recptr = GetFlushRecPtr();
404 
405  PG_RETURN_LSN(current_recptr);
406 }
407 
408 /*
409  * Report the last WAL receive location (same format as pg_start_backup etc)
410  *
411  * This is useful for determining how much of WAL is guaranteed to be received
412  * and synced to disk by walreceiver.
413  */
414 Datum
416 {
417  XLogRecPtr recptr;
418 
419  recptr = GetWalRcvWriteRecPtr(NULL, NULL);
420 
421  if (recptr == 0)
422  PG_RETURN_NULL();
423 
424  PG_RETURN_LSN(recptr);
425 }
426 
427 /*
428  * Report the last WAL replay location (same format as pg_start_backup etc)
429  *
430  * This is useful for determining how much of WAL is visible to read-only
431  * connections during recovery.
432  */
433 Datum
435 {
436  XLogRecPtr recptr;
437 
438  recptr = GetXLogReplayRecPtr(NULL);
439 
440  if (recptr == 0)
441  PG_RETURN_NULL();
442 
443  PG_RETURN_LSN(recptr);
444 }
445 
446 /*
447  * Compute an xlog file name and decimal byte offset given a WAL location,
448  * such as is returned by pg_stop_backup() or pg_xlog_switch().
449  *
450  * Note that a location exactly at a segment boundary is taken to be in
451  * the previous segment. This is usually the right thing, since the
452  * expected usage is to determine which xlog file(s) are ready to archive.
453  */
454 Datum
456 {
457  XLogSegNo xlogsegno;
458  uint32 xrecoff;
459  XLogRecPtr locationpoint = PG_GETARG_LSN(0);
460  char xlogfilename[MAXFNAMELEN];
461  Datum values[2];
462  bool isnull[2];
463  TupleDesc resultTupleDesc;
464  HeapTuple resultHeapTuple;
465  Datum result;
466 
467  if (RecoveryInProgress())
468  ereport(ERROR,
469  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
470  errmsg("recovery is in progress"),
471  errhint("pg_walfile_name_offset() cannot be executed during recovery.")));
472 
473  /*
474  * Construct a tuple descriptor for the result row. This must match this
475  * function's pg_proc entry!
476  */
477  resultTupleDesc = CreateTemplateTupleDesc(2, false);
478  TupleDescInitEntry(resultTupleDesc, (AttrNumber) 1, "file_name",
479  TEXTOID, -1, 0);
480  TupleDescInitEntry(resultTupleDesc, (AttrNumber) 2, "file_offset",
481  INT4OID, -1, 0);
482 
483  resultTupleDesc = BlessTupleDesc(resultTupleDesc);
484 
485  /*
486  * xlogfilename
487  */
488  XLByteToPrevSeg(locationpoint, xlogsegno);
489  XLogFileName(xlogfilename, ThisTimeLineID, xlogsegno);
490 
491  values[0] = CStringGetTextDatum(xlogfilename);
492  isnull[0] = false;
493 
494  /*
495  * offset
496  */
497  xrecoff = locationpoint % XLogSegSize;
498 
499  values[1] = UInt32GetDatum(xrecoff);
500  isnull[1] = false;
501 
502  /*
503  * Tuple jam: Having first prepared your Datums, then squash together
504  */
505  resultHeapTuple = heap_form_tuple(resultTupleDesc, values, isnull);
506 
507  result = HeapTupleGetDatum(resultHeapTuple);
508 
509  PG_RETURN_DATUM(result);
510 }
511 
512 /*
513  * Compute an xlog file name given a WAL location,
514  * such as is returned by pg_stop_backup() or pg_xlog_switch().
515  */
516 Datum
518 {
519  XLogSegNo xlogsegno;
520  XLogRecPtr locationpoint = PG_GETARG_LSN(0);
521  char xlogfilename[MAXFNAMELEN];
522 
523  if (RecoveryInProgress())
524  ereport(ERROR,
525  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
526  errmsg("recovery is in progress"),
527  errhint("pg_walfile_name() cannot be executed during recovery.")));
528 
529  XLByteToPrevSeg(locationpoint, xlogsegno);
530  XLogFileName(xlogfilename, ThisTimeLineID, xlogsegno);
531 
532  PG_RETURN_TEXT_P(cstring_to_text(xlogfilename));
533 }
534 
535 /*
536  * pg_wal_replay_pause - pause recovery now
537  *
538  * Permission checking for this function is managed through the normal
539  * GRANT system.
540  */
541 Datum
543 {
544  if (!RecoveryInProgress())
545  ereport(ERROR,
546  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
547  errmsg("recovery is not in progress"),
548  errhint("Recovery control functions can only be executed during recovery.")));
549 
550  SetRecoveryPause(true);
551 
552  PG_RETURN_VOID();
553 }
554 
555 /*
556  * pg_wal_replay_resume - resume recovery now
557  *
558  * Permission checking for this function is managed through the normal
559  * GRANT system.
560  */
561 Datum
563 {
564  if (!RecoveryInProgress())
565  ereport(ERROR,
566  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
567  errmsg("recovery is not in progress"),
568  errhint("Recovery control functions can only be executed during recovery.")));
569 
570  SetRecoveryPause(false);
571 
572  PG_RETURN_VOID();
573 }
574 
575 /*
576  * pg_is_wal_replay_paused
577  */
578 Datum
580 {
581  if (!RecoveryInProgress())
582  ereport(ERROR,
583  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
584  errmsg("recovery is not in progress"),
585  errhint("Recovery control functions can only be executed during recovery.")));
586 
588 }
589 
590 /*
591  * Returns timestamp of latest processed commit/abort record.
592  *
593  * When the server has been started normally without recovery the function
594  * returns NULL.
595  */
596 Datum
598 {
599  TimestampTz xtime;
600 
601  xtime = GetLatestXTime();
602  if (xtime == 0)
603  PG_RETURN_NULL();
604 
605  PG_RETURN_TIMESTAMPTZ(xtime);
606 }
607 
608 /*
609  * Returns bool with current recovery mode, a global state.
610  */
611 Datum
613 {
615 }
616 
617 /*
618  * Compute the difference in bytes between two WAL locations.
619  */
620 Datum
622 {
623  Datum result;
624 
626  PG_GETARG_DATUM(0),
627  PG_GETARG_DATUM(1));
628 
629  PG_RETURN_NUMERIC(result);
630 }
631 
632 /*
633  * Returns bool with current on-line backup mode, a global state.
634  */
635 Datum
637 {
639 }
640 
641 /*
642  * Returns start time of an online exclusive backup.
643  *
644  * When there's no exclusive backup in progress, the function
645  * returns NULL.
646  */
647 Datum
649 {
650  Datum xtime;
651  FILE *lfp;
652  char fline[MAXPGPATH];
653  char backup_start_time[30];
654 
655  /*
656  * See if label file is present
657  */
658  lfp = AllocateFile(BACKUP_LABEL_FILE, "r");
659  if (lfp == NULL)
660  {
661  if (errno != ENOENT)
662  ereport(ERROR,
664  errmsg("could not read file \"%s\": %m",
666  PG_RETURN_NULL();
667  }
668 
669  /*
670  * Parse the file to find the START TIME line.
671  */
672  backup_start_time[0] = '\0';
673  while (fgets(fline, sizeof(fline), lfp) != NULL)
674  {
675  if (sscanf(fline, "START TIME: %25[^\n]\n", backup_start_time) == 1)
676  break;
677  }
678 
679  /* Check for a read error. */
680  if (ferror(lfp))
681  ereport(ERROR,
683  errmsg("could not read file \"%s\": %m", BACKUP_LABEL_FILE)));
684 
685  /* Close the backup label file. */
686  if (FreeFile(lfp))
687  ereport(ERROR,
689  errmsg("could not close file \"%s\": %m", BACKUP_LABEL_FILE)));
690 
691  if (strlen(backup_start_time) == 0)
692  ereport(ERROR,
693  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
694  errmsg("invalid data in file \"%s\"", BACKUP_LABEL_FILE)));
695 
696  /*
697  * Convert the time string read from file to TimestampTz form.
698  */
700  CStringGetDatum(backup_start_time),
702  Int32GetDatum(-1));
703 
704  PG_RETURN_DATUM(xtime);
705 }
#define PG_RETURN_NUMERIC(x)
Definition: numeric.h:54
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
Definition: tuplestore.c:735
#define XLogSegSize
Definition: xlog_internal.h:92
static bool exclusive_backup_running
Definition: xlogfuncs.c:45
Datum pg_switch_wal(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:285
#define IsA(nodeptr, _type_)
Definition: nodes.h:559
XLogRecPtr RequestXLogSwitch(bool mark_unimportant)
Definition: xlog.c:9322
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:211
static StringInfo label_file
Definition: xlogfuncs.c:43
int errhint(const char *fmt,...)
Definition: elog.c:987
XLogRecPtr GetWalRcvWriteRecPtr(XLogRecPtr *latestChunkStart, TimeLineID *receiveTLI)
static bool nonexclusive_backup_running
Definition: xlogfuncs.c:46
Datum pg_start_backup(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:73
Datum pg_is_in_backup(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:636
Datum pg_last_wal_replay_location(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:434
#define TEXTOID
Definition: pg_type.h:324
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:224
Datum pg_lsn_mi(PG_FUNCTION_ARGS)
Definition: pg_lsn.c:188
#define XLogIsNeeded()
Definition: xlog.h:145
StringInfo makeStringInfo(void)
Definition: stringinfo.c:29
#define tuplestore_donestoring(state)
Definition: tuplestore.h:60
#define XLogFileName(fname, tli, logSegNo)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define INT4OID
Definition: pg_type.h:316
int errcode(int sqlerrcode)
Definition: elog.c:575
#define LSNGetDatum(X)
Definition: pg_lsn.h:22
#define MemSet(start, val, len)
Definition: c.h:853
XLogRecPtr GetFlushRecPtr(void)
Definition: xlog.c:8154
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:692
TimestampTz GetLatestXTime(void)
Definition: xlog.c:6004
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:230
bool BackupInProgress(void)
Definition: xlog.c:11240
bool RecoveryInProgress(void)
Definition: xlog.c:7805
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
static void nonexclusive_base_backup_cleanup(int code, Datum arg)
Definition: xlogfuncs.c:53
bool RecoveryIsPaused(void)
Definition: xlog.c:5873
#define PG_RETURN_LSN(x)
Definition: pg_lsn.h:25
void pfree(void *pointer)
Definition: mcxt.c:992
Definition: dirent.c:25
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
XLogRecPtr do_pg_stop_backup(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p)
Definition: xlog.c:10581
XLogRecPtr GetXLogInsertRecPtr(void)
Definition: xlog.c:11003
#define MAXPGPATH
XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI)
Definition: xlog.c:10984
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:1031
void cancel_before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:377
Datum pg_wal_replay_resume(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:562
Datum pg_stop_backup(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:147
uint64 XLogSegNo
Definition: xlogdefs.h:34
int errcode_for_file_access(void)
Definition: elog.c:598
#define CStringGetDatum(X)
Definition: postgres.h:586
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2043
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:320
unsigned int uint32
Definition: c.h:265
DIR * AllocateDir(const char *dirname)
Definition: fd.c:2284
#define UInt32GetDatum(X)
Definition: postgres.h:501
Datum pg_create_restore_point(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:310
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:493
#define XLByteToPrevSeg(xlrp, logSegNo)
#define ereport(elevel, rest)
Definition: elog.h:122
MemoryContext TopMemoryContext
Definition: mcxt.c:43
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:559
Datum pg_is_wal_replay_paused(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:579
#define WARNING
Definition: elog.h:40
#define MAXFNAMELEN
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
Definition: tuplestore.c:316
#define PG_GETARG_LSN(n)
Definition: pg_lsn.h:24
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
uintptr_t Datum
Definition: postgres.h:374
Datum pg_wal_replay_pause(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:542
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:297
int work_mem
Definition: globals.c:112
#define InvalidOid
Definition: postgres_ext.h:36
TimeLineID ThisTimeLineID
Definition: xlog.c:178
Datum pg_walfile_name_offset(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:455
int allowedModes
Definition: execnodes.h:199
#define PG_RETURN_VOID()
Definition: fmgr.h:293
static StringInfo tblspc_map_file
Definition: xlogfuncs.c:44
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:314
XLogRecPtr GetXLogWriteRecPtr(void)
Definition: xlog.c:11019
SetFunctionReturnMode returnMode
Definition: execnodes.h:201
text * cstring_to_text(const char *s)
Definition: varlena.c:151
#define NULL
Definition: c.h:226
uint64 XLogRecPtr
Definition: xlogdefs.h:21
XLogRecPtr XLogRestorePoint(const char *rpName)
Definition: xlog.c:9340
Datum pg_last_wal_receive_location(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:415
Datum pg_walfile_name(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:517
void SetRecoveryPause(bool recoveryPause)
Definition: xlog.c:5885
Datum pg_current_wal_location(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:351
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:222
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:133
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:41
Tuplestorestate * setResult
Definition: execnodes.h:204
int FreeFile(FILE *file)
Definition: fd.c:2226
static Datum values[MAXATTR]
Definition: bootstrap.c:162
char * text_to_cstring(const text *t)
Definition: varlena.c:184
ExprContext * econtext
Definition: execnodes.h:197
#define Int32GetDatum(X)
Definition: postgres.h:487
Datum timestamptz_in(PG_FUNCTION_ARGS)
Definition: timestamp.c:382
TupleDesc setDesc
Definition: execnodes.h:205
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_GETARG_TEXT_P(n)
Definition: fmgr.h:269
Datum pg_stop_backup_v2(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:182
void do_pg_abort_backup(void)
Definition: xlog.c:10964
#define CStringGetTextDatum(s)
Definition: builtins.h:90
void * arg
#define BACKUP_LABEL_FILE
Definition: xlog.h:301
Definition: c.h:435
#define PG_FUNCTION_ARGS
Definition: fmgr.h:150
#define elog
Definition: elog.h:219
Datum pg_is_in_recovery(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:612
Datum pg_last_xact_replay_timestamp(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:597
int16 AttrNumber
Definition: attnum.h:21
Datum pg_current_wal_insert_location(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:372
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:557
#define PG_RETURN_NULL()
Definition: fmgr.h:289
int FreeDir(DIR *dir)
Definition: fd.c:2393
XLogRecPtr do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p, StringInfo labelfile, DIR *tblspcdir, List **tablespaces, StringInfo tblspcmapfile, bool infotbssize, bool needtblspcmapfile)
Definition: xlog.c:10087
Datum pg_wal_location_diff(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:621
Datum pg_current_wal_flush_location(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:393
Datum pg_backup_start_time(PG_FUNCTION_ARGS)
Definition: xlogfuncs.c:648