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