PostgreSQL Source Code  git master
xlogfuncs.c File Reference
#include "postgres.h"
#include <unistd.h>
#include "access/htup_details.h"
#include "access/xlog_internal.h"
#include "access/xlogrecovery.h"
#include "access/xlogutils.h"
#include "catalog/pg_type.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "replication/walreceiver.h"
#include "storage/fd.h"
#include "storage/ipc.h"
#include "storage/smgr.h"
#include "utils/builtins.h"
#include "utils/guc.h"
#include "utils/memutils.h"
#include "utils/numeric.h"
#include "utils/pg_lsn.h"
#include "utils/timestamp.h"
#include "utils/tuplestore.h"
Include dependency graph for xlogfuncs.c:

Go to the source code of this file.

Macros

#define PG_STOP_BACKUP_V2_COLS   3
 
#define WAITS_PER_SECOND   10
 

Functions

Datum pg_backup_start (PG_FUNCTION_ARGS)
 
Datum pg_backup_stop (PG_FUNCTION_ARGS)
 
Datum pg_switch_wal (PG_FUNCTION_ARGS)
 
Datum pg_create_restore_point (PG_FUNCTION_ARGS)
 
Datum pg_current_wal_lsn (PG_FUNCTION_ARGS)
 
Datum pg_current_wal_insert_lsn (PG_FUNCTION_ARGS)
 
Datum pg_current_wal_flush_lsn (PG_FUNCTION_ARGS)
 
Datum pg_last_wal_receive_lsn (PG_FUNCTION_ARGS)
 
Datum pg_last_wal_replay_lsn (PG_FUNCTION_ARGS)
 
Datum pg_walfile_name_offset (PG_FUNCTION_ARGS)
 
Datum pg_walfile_name (PG_FUNCTION_ARGS)
 
Datum pg_wal_replay_pause (PG_FUNCTION_ARGS)
 
Datum pg_wal_replay_resume (PG_FUNCTION_ARGS)
 
Datum pg_is_wal_replay_paused (PG_FUNCTION_ARGS)
 
Datum pg_get_wal_replay_pause_state (PG_FUNCTION_ARGS)
 
Datum pg_last_xact_replay_timestamp (PG_FUNCTION_ARGS)
 
Datum pg_is_in_recovery (PG_FUNCTION_ARGS)
 
Datum pg_wal_lsn_diff (PG_FUNCTION_ARGS)
 
Datum pg_promote (PG_FUNCTION_ARGS)
 

Variables

static StringInfo label_file
 
static StringInfo tblspc_map_file
 

Macro Definition Documentation

◆ PG_STOP_BACKUP_V2_COLS

#define PG_STOP_BACKUP_V2_COLS   3

◆ WAITS_PER_SECOND

#define WAITS_PER_SECOND   10

Function Documentation

◆ pg_backup_start()

Datum pg_backup_start ( PG_FUNCTION_ARGS  )

Definition at line 60 of file xlogfuncs.c.

61 {
62  text *backupid = PG_GETARG_TEXT_PP(0);
63  bool fast = PG_GETARG_BOOL(1);
64  char *backupidstr;
65  XLogRecPtr startpoint;
67  MemoryContext oldcontext;
68 
69  backupidstr = text_to_cstring(backupid);
70 
72  ereport(ERROR,
73  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
74  errmsg("a backup is already in progress in this session")));
75 
76  /*
77  * Label file and tablespace map file need to be long-lived, since they
78  * are read in pg_backup_stop.
79  */
83  MemoryContextSwitchTo(oldcontext);
84 
86 
87  startpoint = do_pg_backup_start(backupidstr, fast, NULL, label_file,
88  NULL, tblspc_map_file);
89 
90  PG_RETURN_LSN(startpoint);
91 }
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define ERROR
Definition: elog.h:33
#define ereport(elevel,...)
Definition: elog.h:143
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
MemoryContext TopMemoryContext
Definition: mcxt.c:48
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define PG_RETURN_LSN(x)
Definition: pg_lsn.h:25
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:229
StringInfo makeStringInfo(void)
Definition: stringinfo.c:41
Definition: c.h:633
char * text_to_cstring(const text *t)
Definition: varlena.c:221
XLogRecPtr do_pg_backup_start(const char *backupidstr, bool fast, TimeLineID *starttli_p, StringInfo labelfile, List **tablespaces, StringInfo tblspcmapfile)
Definition: xlog.c:8086
SessionBackupState get_backup_status(void)
Definition: xlog.c:8428
void register_persistent_abort_backup_handler(void)
Definition: xlog.c:8798
SessionBackupState
Definition: xlog.h:275
@ SESSION_BACKUP_RUNNING
Definition: xlog.h:277
uint64 XLogRecPtr
Definition: xlogdefs.h:21
static StringInfo label_file
Definition: xlogfuncs.c:44
static StringInfo tblspc_map_file
Definition: xlogfuncs.c:45

References do_pg_backup_start(), ereport, errcode(), errmsg(), ERROR, get_backup_status(), label_file, makeStringInfo(), MemoryContextSwitchTo(), PG_GETARG_BOOL, PG_GETARG_TEXT_PP, PG_RETURN_LSN, register_persistent_abort_backup_handler(), SESSION_BACKUP_RUNNING, status(), tblspc_map_file, text_to_cstring(), and TopMemoryContext.

◆ pg_backup_stop()

Datum pg_backup_stop ( PG_FUNCTION_ARGS  )

Definition at line 105 of file xlogfuncs.c.

106 {
107 #define PG_STOP_BACKUP_V2_COLS 3
108  TupleDesc tupdesc;
110  bool nulls[PG_STOP_BACKUP_V2_COLS];
111 
112  bool waitforarchive = PG_GETARG_BOOL(0);
113  XLogRecPtr stoppoint;
115 
116  /* Initialize attributes information in the tuple descriptor */
117  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
118  elog(ERROR, "return type must be a row type");
119 
120  MemSet(values, 0, sizeof(values));
121  MemSet(nulls, 0, sizeof(nulls));
122 
124  ereport(ERROR,
125  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
126  errmsg("backup is not in progress"),
127  errhint("Did you call pg_backup_start()?")));
128 
129  /*
130  * Stop the backup. Return a copy of the backup label and tablespace map
131  * so they can be written to disk by the caller.
132  */
133  stoppoint = do_pg_backup_stop(label_file->data, waitforarchive, NULL);
134 
135  values[0] = LSNGetDatum(stoppoint);
138 
139  /* Free structures allocated in TopMemoryContext */
141  pfree(label_file);
142  label_file = NULL;
145  tblspc_map_file = NULL;
146 
147  /* Returns the record as Datum */
149 }
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define CStringGetTextDatum(s)
Definition: builtins.h:85
#define MemSet(start, val, len)
Definition: c.h:1019
int errhint(const char *fmt,...)
Definition: elog.c:1151
#define elog(elevel,...)
Definition: elog.h:218
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:276
@ TYPEFUNC_COMPOSITE
Definition: funcapi.h:149
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:220
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
void pfree(void *pointer)
Definition: mcxt.c:1175
#define LSNGetDatum(X)
Definition: pg_lsn.h:22
uintptr_t Datum
Definition: postgres.h:411
XLogRecPtr do_pg_backup_stop(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p)
Definition: xlog.c:8446
#define PG_STOP_BACKUP_V2_COLS

References CStringGetTextDatum, StringInfoData::data, do_pg_backup_stop(), elog, ereport, errcode(), errhint(), errmsg(), ERROR, get_backup_status(), get_call_result_type(), heap_form_tuple(), HeapTupleGetDatum, label_file, LSNGetDatum, MemSet, pfree(), PG_GETARG_BOOL, PG_RETURN_DATUM, PG_STOP_BACKUP_V2_COLS, SESSION_BACKUP_RUNNING, status(), tblspc_map_file, TYPEFUNC_COMPOSITE, and values.

◆ pg_create_restore_point()

Datum pg_create_restore_point ( PG_FUNCTION_ARGS  )

Definition at line 183 of file xlogfuncs.c.

184 {
185  text *restore_name = PG_GETARG_TEXT_PP(0);
186  char *restore_name_str;
187  XLogRecPtr restorepoint;
188 
189  if (RecoveryInProgress())
190  ereport(ERROR,
191  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
192  errmsg("recovery is in progress"),
193  errhint("WAL control functions cannot be executed during recovery.")));
194 
195  if (!XLogIsNeeded())
196  ereport(ERROR,
197  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
198  errmsg("WAL level not sufficient for creating a restore point"),
199  errhint("wal_level must be set to \"replica\" or \"logical\" at server start.")));
200 
201  restore_name_str = text_to_cstring(restore_name);
202 
203  if (strlen(restore_name_str) >= MAXFNAMELEN)
204  ereport(ERROR,
205  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
206  errmsg("value too long for restore point (maximum %d characters)", MAXFNAMELEN - 1)));
207 
208  restorepoint = XLogRestorePoint(restore_name_str);
209 
210  /*
211  * As a convenience, return the WAL location of the restore point record
212  */
213  PG_RETURN_LSN(restorepoint);
214 }
bool RecoveryInProgress(void)
Definition: xlog.c:5762
XLogRecPtr XLogRestorePoint(const char *rpName)
Definition: xlog.c:7384
#define XLogIsNeeded()
Definition: xlog.h:104
#define MAXFNAMELEN

References ereport, errcode(), errhint(), errmsg(), ERROR, MAXFNAMELEN, PG_GETARG_TEXT_PP, PG_RETURN_LSN, RecoveryInProgress(), text_to_cstring(), XLogIsNeeded, and XLogRestorePoint().

◆ pg_current_wal_flush_lsn()

Datum pg_current_wal_flush_lsn ( PG_FUNCTION_ARGS  )

Definition at line 266 of file xlogfuncs.c.

267 {
268  XLogRecPtr current_recptr;
269 
270  if (RecoveryInProgress())
271  ereport(ERROR,
272  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
273  errmsg("recovery is in progress"),
274  errhint("WAL control functions cannot be executed during recovery.")));
275 
276  current_recptr = GetFlushRecPtr(NULL);
277 
278  PG_RETURN_LSN(current_recptr);
279 }
XLogRecPtr GetFlushRecPtr(TimeLineID *insertTLI)
Definition: xlog.c:5927

References ereport, errcode(), errhint(), errmsg(), ERROR, GetFlushRecPtr(), PG_RETURN_LSN, and RecoveryInProgress().

◆ pg_current_wal_insert_lsn()

Datum pg_current_wal_insert_lsn ( PG_FUNCTION_ARGS  )

Definition at line 245 of file xlogfuncs.c.

246 {
247  XLogRecPtr current_recptr;
248 
249  if (RecoveryInProgress())
250  ereport(ERROR,
251  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
252  errmsg("recovery is in progress"),
253  errhint("WAL control functions cannot be executed during recovery.")));
254 
255  current_recptr = GetXLogInsertRecPtr();
256 
257  PG_RETURN_LSN(current_recptr);
258 }
XLogRecPtr GetXLogInsertRecPtr(void)
Definition: xlog.c:8812

References ereport, errcode(), errhint(), errmsg(), ERROR, GetXLogInsertRecPtr(), PG_RETURN_LSN, and RecoveryInProgress().

◆ pg_current_wal_lsn()

Datum pg_current_wal_lsn ( PG_FUNCTION_ARGS  )

Definition at line 224 of file xlogfuncs.c.

225 {
226  XLogRecPtr current_recptr;
227 
228  if (RecoveryInProgress())
229  ereport(ERROR,
230  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
231  errmsg("recovery is in progress"),
232  errhint("WAL control functions cannot be executed during recovery.")));
233 
234  current_recptr = GetXLogWriteRecPtr();
235 
236  PG_RETURN_LSN(current_recptr);
237 }
XLogRecPtr GetXLogWriteRecPtr(void)
Definition: xlog.c:8828

References ereport, errcode(), errhint(), errmsg(), ERROR, GetXLogWriteRecPtr(), PG_RETURN_LSN, and RecoveryInProgress().

◆ pg_get_wal_replay_pause_state()

Datum pg_get_wal_replay_pause_state ( PG_FUNCTION_ARGS  )

Definition at line 494 of file xlogfuncs.c.

495 {
496  char *statestr = NULL;
497 
498  if (!RecoveryInProgress())
499  ereport(ERROR,
500  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
501  errmsg("recovery is not in progress"),
502  errhint("Recovery control functions can only be executed during recovery.")));
503 
504  /* get the recovery pause state */
505  switch (GetRecoveryPauseState())
506  {
507  case RECOVERY_NOT_PAUSED:
508  statestr = "not paused";
509  break;
511  statestr = "pause requested";
512  break;
513  case RECOVERY_PAUSED:
514  statestr = "paused";
515  break;
516  }
517 
518  Assert(statestr != NULL);
520 }
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:372
Assert(fmt[strlen(fmt) - 1] !='\n')
text * cstring_to_text(const char *s)
Definition: varlena.c:188
RecoveryPauseState GetRecoveryPauseState(void)
@ RECOVERY_PAUSED
Definition: xlogrecovery.h:48
@ RECOVERY_NOT_PAUSED
Definition: xlogrecovery.h:46
@ RECOVERY_PAUSE_REQUESTED
Definition: xlogrecovery.h:47

References Assert(), cstring_to_text(), ereport, errcode(), errhint(), errmsg(), ERROR, GetRecoveryPauseState(), PG_RETURN_TEXT_P, RECOVERY_NOT_PAUSED, RECOVERY_PAUSE_REQUESTED, RECOVERY_PAUSED, and RecoveryInProgress().

◆ pg_is_in_recovery()

Datum pg_is_in_recovery ( PG_FUNCTION_ARGS  )

Definition at line 544 of file xlogfuncs.c.

545 {
547 }
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

References PG_RETURN_BOOL, and RecoveryInProgress().

◆ pg_is_wal_replay_paused()

Datum pg_is_wal_replay_paused ( PG_FUNCTION_ARGS  )

Definition at line 473 of file xlogfuncs.c.

474 {
475  if (!RecoveryInProgress())
476  ereport(ERROR,
477  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
478  errmsg("recovery is not in progress"),
479  errhint("Recovery control functions can only be executed during recovery.")));
480 
482 }

References ereport, errcode(), errhint(), errmsg(), ERROR, GetRecoveryPauseState(), PG_RETURN_BOOL, RECOVERY_NOT_PAUSED, and RecoveryInProgress().

◆ pg_last_wal_receive_lsn()

Datum pg_last_wal_receive_lsn ( PG_FUNCTION_ARGS  )

Definition at line 288 of file xlogfuncs.c.

289 {
290  XLogRecPtr recptr;
291 
292  recptr = GetWalRcvFlushRecPtr(NULL, NULL);
293 
294  if (recptr == 0)
295  PG_RETURN_NULL();
296 
297  PG_RETURN_LSN(recptr);
298 }
#define PG_RETURN_NULL()
Definition: fmgr.h:345
XLogRecPtr GetWalRcvFlushRecPtr(XLogRecPtr *latestChunkStart, TimeLineID *receiveTLI)

References GetWalRcvFlushRecPtr(), PG_RETURN_LSN, and PG_RETURN_NULL.

◆ pg_last_wal_replay_lsn()

Datum pg_last_wal_replay_lsn ( PG_FUNCTION_ARGS  )

Definition at line 307 of file xlogfuncs.c.

308 {
309  XLogRecPtr recptr;
310 
311  recptr = GetXLogReplayRecPtr(NULL);
312 
313  if (recptr == 0)
314  PG_RETURN_NULL();
315 
316  PG_RETURN_LSN(recptr);
317 }
XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI)

References GetXLogReplayRecPtr(), PG_RETURN_LSN, and PG_RETURN_NULL.

◆ pg_last_xact_replay_timestamp()

Datum pg_last_xact_replay_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 529 of file xlogfuncs.c.

530 {
531  TimestampTz xtime;
532 
533  xtime = GetLatestXTime();
534  if (xtime == 0)
535  PG_RETURN_NULL();
536 
537  PG_RETURN_TIMESTAMPTZ(xtime);
538 }
int64 TimestampTz
Definition: timestamp.h:39
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
TimestampTz GetLatestXTime(void)

References GetLatestXTime(), PG_RETURN_NULL, and PG_RETURN_TIMESTAMPTZ.

◆ pg_promote()

Datum pg_promote ( PG_FUNCTION_ARGS  )

Definition at line 571 of file xlogfuncs.c.

572 {
573  bool wait = PG_GETARG_BOOL(0);
574  int wait_seconds = PG_GETARG_INT32(1);
575  FILE *promote_file;
576  int i;
577 
578  if (!RecoveryInProgress())
579  ereport(ERROR,
580  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
581  errmsg("recovery is not in progress"),
582  errhint("Recovery control functions can only be executed during recovery.")));
583 
584  if (wait_seconds <= 0)
585  ereport(ERROR,
586  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
587  errmsg("\"wait_seconds\" must not be negative or zero")));
588 
589  /* create the promote signal file */
591  if (!promote_file)
592  ereport(ERROR,
594  errmsg("could not create file \"%s\": %m",
596 
597  if (FreeFile(promote_file))
598  ereport(ERROR,
600  errmsg("could not write file \"%s\": %m",
602 
603  /* signal the postmaster */
604  if (kill(PostmasterPid, SIGUSR1) != 0)
605  {
607  (errmsg("failed to send signal to postmaster: %m")));
608  (void) unlink(PROMOTE_SIGNAL_FILE);
609  PG_RETURN_BOOL(false);
610  }
611 
612  /* return immediately if waiting was not requested */
613  if (!wait)
614  PG_RETURN_BOOL(true);
615 
616  /* wait for the amount of time wanted until promotion */
617 #define WAITS_PER_SECOND 10
618  for (i = 0; i < WAITS_PER_SECOND * wait_seconds; i++)
619  {
620  int rc;
621 
623 
624  if (!RecoveryInProgress())
625  PG_RETURN_BOOL(true);
626 
628 
629  rc = WaitLatch(MyLatch,
631  1000L / WAITS_PER_SECOND,
633 
634  /*
635  * Emergency bailout if postmaster has died. This is to avoid the
636  * necessity for manual cleanup of all postmaster children.
637  */
638  if (rc & WL_POSTMASTER_DEATH)
639  PG_RETURN_BOOL(false);
640  }
641 
643  (errmsg_plural("server did not promote within %d second",
644  "server did not promote within %d seconds",
645  wait_seconds,
646  wait_seconds)));
647  PG_RETURN_BOOL(false);
648 }
int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:1014
int errcode_for_file_access(void)
Definition: elog.c:716
#define WARNING
Definition: elog.h:30
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2461
int FreeFile(FILE *file)
Definition: fd.c:2660
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
pid_t PostmasterPid
Definition: globals.c:99
struct Latch * MyLatch
Definition: globals.c:58
int i
Definition: isn.c:73
void ResetLatch(Latch *latch)
Definition: latch.c:683
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition: latch.c:476
#define WL_TIMEOUT
Definition: latch.h:128
#define WL_LATCH_SET
Definition: latch.h:125
#define WL_POSTMASTER_DEATH
Definition: latch.h:129
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:121
static char promote_file[MAXPGPATH]
Definition: pg_ctl.c:105
static int wait_seconds
Definition: pg_ctl.c:80
@ WAIT_EVENT_PROMOTE
Definition: wait_event.h:119
#define kill(pid, sig)
Definition: win32_port.h:464
#define SIGUSR1
Definition: win32_port.h:179
#define PROMOTE_SIGNAL_FILE
Definition: xlog.h:299
#define WAITS_PER_SECOND

References AllocateFile(), CHECK_FOR_INTERRUPTS, ereport, errcode(), errcode_for_file_access(), errhint(), errmsg(), errmsg_plural(), ERROR, FreeFile(), i, kill, MyLatch, PG_GETARG_BOOL, PG_GETARG_INT32, PG_RETURN_BOOL, PostmasterPid, promote_file, PROMOTE_SIGNAL_FILE, RecoveryInProgress(), ResetLatch(), SIGUSR1, WAIT_EVENT_PROMOTE, wait_seconds, WaitLatch(), WAITS_PER_SECOND, WARNING, WL_LATCH_SET, WL_POSTMASTER_DEATH, and WL_TIMEOUT.

◆ pg_switch_wal()

Datum pg_switch_wal ( PG_FUNCTION_ARGS  )

Definition at line 158 of file xlogfuncs.c.

159 {
160  XLogRecPtr switchpoint;
161 
162  if (RecoveryInProgress())
163  ereport(ERROR,
164  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
165  errmsg("recovery is in progress"),
166  errhint("WAL control functions cannot be executed during recovery.")));
167 
168  switchpoint = RequestXLogSwitch(false);
169 
170  /*
171  * As a convenience, return the WAL location of the switch record
172  */
173  PG_RETURN_LSN(switchpoint);
174 }
XLogRecPtr RequestXLogSwitch(bool mark_unimportant)
Definition: xlog.c:7366

References ereport, errcode(), errhint(), errmsg(), ERROR, PG_RETURN_LSN, RecoveryInProgress(), and RequestXLogSwitch().

◆ pg_wal_lsn_diff()

Datum pg_wal_lsn_diff ( PG_FUNCTION_ARGS  )

Definition at line 553 of file xlogfuncs.c.

554 {
555  Datum result;
556 
558  PG_GETARG_DATUM(0),
559  PG_GETARG_DATUM(1));
560 
561  PG_RETURN_NUMERIC(result);
562 }
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:633
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
#define PG_RETURN_NUMERIC(x)
Definition: numeric.h:64
Datum pg_lsn_mi(PG_FUNCTION_ARGS)
Definition: pg_lsn.c:225

References DirectFunctionCall2, PG_GETARG_DATUM, pg_lsn_mi(), and PG_RETURN_NUMERIC.

◆ pg_wal_replay_pause()

Datum pg_wal_replay_pause ( PG_FUNCTION_ARGS  )

Definition at line 419 of file xlogfuncs.c.

420 {
421  if (!RecoveryInProgress())
422  ereport(ERROR,
423  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
424  errmsg("recovery is not in progress"),
425  errhint("Recovery control functions can only be executed during recovery.")));
426 
427  if (PromoteIsTriggered())
428  ereport(ERROR,
429  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
430  errmsg("standby promotion is ongoing"),
431  errhint("%s cannot be executed after promotion is triggered.",
432  "pg_wal_replay_pause()")));
433 
434  SetRecoveryPause(true);
435 
436  /* wake up the recovery process so that it can process the pause request */
437  WakeupRecovery();
438 
439  PG_RETURN_VOID();
440 }
#define PG_RETURN_VOID()
Definition: fmgr.h:349
void SetRecoveryPause(bool recoveryPause)
void WakeupRecovery(void)
bool PromoteIsTriggered(void)

References ereport, errcode(), errhint(), errmsg(), ERROR, PG_RETURN_VOID, PromoteIsTriggered(), RecoveryInProgress(), SetRecoveryPause(), and WakeupRecovery().

◆ pg_wal_replay_resume()

Datum pg_wal_replay_resume ( PG_FUNCTION_ARGS  )

Definition at line 449 of file xlogfuncs.c.

450 {
451  if (!RecoveryInProgress())
452  ereport(ERROR,
453  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
454  errmsg("recovery is not in progress"),
455  errhint("Recovery control functions can only be executed during recovery.")));
456 
457  if (PromoteIsTriggered())
458  ereport(ERROR,
459  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
460  errmsg("standby promotion is ongoing"),
461  errhint("%s cannot be executed after promotion is triggered.",
462  "pg_wal_replay_resume()")));
463 
464  SetRecoveryPause(false);
465 
466  PG_RETURN_VOID();
467 }

References ereport, errcode(), errhint(), errmsg(), ERROR, PG_RETURN_VOID, PromoteIsTriggered(), RecoveryInProgress(), and SetRecoveryPause().

◆ pg_walfile_name()

Datum pg_walfile_name ( PG_FUNCTION_ARGS  )

Definition at line 392 of file xlogfuncs.c.

393 {
394  XLogSegNo xlogsegno;
395  XLogRecPtr locationpoint = PG_GETARG_LSN(0);
396  char xlogfilename[MAXFNAMELEN];
397 
398  if (RecoveryInProgress())
399  ereport(ERROR,
400  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
401  errmsg("recovery is in progress"),
402  errhint("%s cannot be executed during recovery.",
403  "pg_walfile_name()")));
404 
405  XLByteToPrevSeg(locationpoint, xlogsegno, wal_segment_size);
406  XLogFileName(xlogfilename, GetWALInsertionTimeLine(), xlogsegno,
408 
409  PG_RETURN_TEXT_P(cstring_to_text(xlogfilename));
410 }
#define PG_GETARG_LSN(n)
Definition: pg_lsn.h:24
TimeLineID GetWALInsertionTimeLine(void)
Definition: xlog.c:5950
int wal_segment_size
Definition: xlog.c:144
#define XLogFileName(fname, tli, logSegNo, wal_segsz_bytes)
#define XLByteToPrevSeg(xlrp, logSegNo, wal_segsz_bytes)
uint64 XLogSegNo
Definition: xlogdefs.h:48

References cstring_to_text(), ereport, errcode(), errhint(), errmsg(), ERROR, GetWALInsertionTimeLine(), MAXFNAMELEN, PG_GETARG_LSN, PG_RETURN_TEXT_P, RecoveryInProgress(), wal_segment_size, XLByteToPrevSeg, and XLogFileName.

◆ pg_walfile_name_offset()

Datum pg_walfile_name_offset ( PG_FUNCTION_ARGS  )

Definition at line 328 of file xlogfuncs.c.

329 {
330  XLogSegNo xlogsegno;
331  uint32 xrecoff;
332  XLogRecPtr locationpoint = PG_GETARG_LSN(0);
333  char xlogfilename[MAXFNAMELEN];
334  Datum values[2];
335  bool isnull[2];
336  TupleDesc resultTupleDesc;
337  HeapTuple resultHeapTuple;
338  Datum result;
339 
340  if (RecoveryInProgress())
341  ereport(ERROR,
342  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
343  errmsg("recovery is in progress"),
344  errhint("%s cannot be executed during recovery.",
345  "pg_walfile_name_offset()")));
346 
347  /*
348  * Construct a tuple descriptor for the result row. This must match this
349  * function's pg_proc entry!
350  */
351  resultTupleDesc = CreateTemplateTupleDesc(2);
352  TupleDescInitEntry(resultTupleDesc, (AttrNumber) 1, "file_name",
353  TEXTOID, -1, 0);
354  TupleDescInitEntry(resultTupleDesc, (AttrNumber) 2, "file_offset",
355  INT4OID, -1, 0);
356 
357  resultTupleDesc = BlessTupleDesc(resultTupleDesc);
358 
359  /*
360  * xlogfilename
361  */
362  XLByteToPrevSeg(locationpoint, xlogsegno, wal_segment_size);
363  XLogFileName(xlogfilename, GetWALInsertionTimeLine(), xlogsegno,
365 
366  values[0] = CStringGetTextDatum(xlogfilename);
367  isnull[0] = false;
368 
369  /*
370  * offset
371  */
372  xrecoff = XLogSegmentOffset(locationpoint, wal_segment_size);
373 
374  values[1] = UInt32GetDatum(xrecoff);
375  isnull[1] = false;
376 
377  /*
378  * Tuple jam: Having first prepared your Datums, then squash together
379  */
380  resultHeapTuple = heap_form_tuple(resultTupleDesc, values, isnull);
381 
382  result = HeapTupleGetDatum(resultHeapTuple);
383 
384  PG_RETURN_DATUM(result);
385 }
int16 AttrNumber
Definition: attnum.h:21
unsigned int uint32
Definition: c.h:452
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2071
#define UInt32GetDatum(X)
Definition: postgres.h:537
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:45
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:583
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)

References BlessTupleDesc(), CreateTemplateTupleDesc(), CStringGetTextDatum, ereport, errcode(), errhint(), errmsg(), ERROR, GetWALInsertionTimeLine(), heap_form_tuple(), HeapTupleGetDatum, MAXFNAMELEN, PG_GETARG_LSN, PG_RETURN_DATUM, RecoveryInProgress(), TupleDescInitEntry(), UInt32GetDatum, values, wal_segment_size, XLByteToPrevSeg, XLogFileName, and XLogSegmentOffset.

Variable Documentation

◆ label_file

StringInfo label_file
static

Definition at line 44 of file xlogfuncs.c.

Referenced by pg_backup_start(), and pg_backup_stop().

◆ tblspc_map_file

StringInfo tblspc_map_file
static

Definition at line 45 of file xlogfuncs.c.

Referenced by perform_base_backup(), pg_backup_start(), and pg_backup_stop().