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