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