PostgreSQL Source Code git master
Loading...
Searching...
No Matches
xlogfuncs.c File Reference
#include "postgres.h"
#include <unistd.h>
#include "access/htup_details.h"
#include "access/xlog_internal.h"
#include "access/xlogbackup.h"
#include "access/xlogrecovery.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_type.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "utils/acl.h"
#include "replication/walreceiver.h"
#include "storage/fd.h"
#include "storage/latch.h"
#include "storage/standby.h"
#include "utils/builtins.h"
#include "utils/memutils.h"
#include "utils/pg_lsn.h"
#include "utils/timestamp.h"
#include "utils/wait_event.h"
Include dependency graph for xlogfuncs.c:

Go to the source code of this file.

Macros

#define PG_BACKUP_STOP_V2_COLS   3
 
#define PG_SPLIT_WALFILE_NAME_COLS   2
 

Functions

static const charGetRecoveryPauseStateString (RecoveryPauseState pause_state)
 
Datum pg_backup_start (PG_FUNCTION_ARGS)
 
Datum pg_backup_stop (PG_FUNCTION_ARGS)
 
Datum pg_switch_wal (PG_FUNCTION_ARGS)
 
Datum pg_log_standby_snapshot (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_split_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)
 
Datum pg_stat_get_recovery (PG_FUNCTION_ARGS)
 

Variables

static BackupStatebackup_state = NULL
 
static StringInfo tablespace_map = NULL
 
static MemoryContext backupcontext = NULL
 

Macro Definition Documentation

◆ PG_BACKUP_STOP_V2_COLS

#define PG_BACKUP_STOP_V2_COLS   3

◆ PG_SPLIT_WALFILE_NAME_COLS

#define PG_SPLIT_WALFILE_NAME_COLS   2

Function Documentation

◆ GetRecoveryPauseStateString()

static const char * GetRecoveryPauseStateString ( RecoveryPauseState  pause_state)
static

Definition at line 56 of file xlogfuncs.c.

57{
58 const char *statestr = NULL;
59
60 switch (pause_state)
61 {
63 statestr = "not paused";
64 break;
66 statestr = "pause requested";
67 break;
68 case RECOVERY_PAUSED:
69 statestr = "paused";
70 break;
71 }
72
74 return statestr;
75}
#define Assert(condition)
Definition c.h:945
static int fb(int x)
@ RECOVERY_PAUSED
@ RECOVERY_NOT_PAUSED
@ RECOVERY_PAUSE_REQUESTED

References Assert, fb(), RECOVERY_NOT_PAUSED, RECOVERY_PAUSE_REQUESTED, and RECOVERY_PAUSED.

Referenced by pg_get_wal_replay_pause_state(), and pg_stat_get_recovery().

◆ pg_backup_start()

Datum pg_backup_start ( PG_FUNCTION_ARGS  )

Definition at line 87 of file xlogfuncs.c.

88{
90 bool fast = PG_GETARG_BOOL(1);
91 char *backupidstr;
93 MemoryContext oldcontext;
94
96
97 if (status == SESSION_BACKUP_RUNNING)
100 errmsg("a backup is already in progress in this session")));
101
102 /*
103 * backup_state and tablespace_map need to be long-lived as they are used
104 * in pg_backup_stop(). These are allocated in a dedicated memory context
105 * child of TopMemoryContext, deleted at the end of pg_backup_stop(). If
106 * an error happens before ending the backup, memory would be leaked in
107 * this context until pg_backup_start() is called again.
108 */
109 if (backupcontext == NULL)
110 {
112 "on-line backup context",
114 }
115 else
116 {
120 }
121
125 MemoryContextSwitchTo(oldcontext);
126
129
131}
int errcode(int sqlerrcode)
Definition elog.c:874
#define ERROR
Definition elog.h:39
#define ereport(elevel,...)
Definition elog.h:150
#define palloc0_object(type)
Definition fe_memutils.h:75
#define PG_GETARG_TEXT_PP(n)
Definition fmgr.h:310
#define PG_GETARG_BOOL(n)
Definition fmgr.h:274
void MemoryContextReset(MemoryContext context)
Definition mcxt.c:403
MemoryContext TopMemoryContext
Definition mcxt.c:166
#define AllocSetContextCreate
Definition memutils.h:129
#define ALLOCSET_START_SMALL_SIZES
Definition memutils.h:177
static char * errmsg
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
#define PG_RETURN_LSN(x)
Definition pg_lsn.h:37
StringInfo makeStringInfo(void)
Definition stringinfo.c:72
XLogRecPtr startpoint
Definition xlogbackup.h:26
Definition c.h:778
char * text_to_cstring(const text *t)
Definition varlena.c:217
SessionBackupState get_backup_status(void)
Definition xlog.c:9280
void register_persistent_abort_backup_handler(void)
Definition xlog.c:9600
void do_pg_backup_start(const char *backupidstr, bool fast, List **tablespaces, BackupState *state, StringInfo tblspcmapfile)
Definition xlog.c:8977
SessionBackupState
Definition xlog.h:305
@ SESSION_BACKUP_RUNNING
Definition xlog.h:307
static BackupState * backup_state
Definition xlogfuncs.c:44
static MemoryContext backupcontext
Definition xlogfuncs.c:48
static StringInfo tablespace_map
Definition xlogfuncs.c:45

References ALLOCSET_START_SMALL_SIZES, AllocSetContextCreate, backup_state, backupcontext, do_pg_backup_start(), ereport, errcode(), errmsg, ERROR, fb(), get_backup_status(), makeStringInfo(), MemoryContextReset(), MemoryContextSwitchTo(), palloc0_object, PG_GETARG_BOOL, PG_GETARG_TEXT_PP, PG_RETURN_LSN, register_persistent_abort_backup_handler(), SESSION_BACKUP_RUNNING, BackupState::startpoint, tablespace_map, text_to_cstring(), and TopMemoryContext.

◆ pg_backup_stop()

Datum pg_backup_stop ( PG_FUNCTION_ARGS  )

Definition at line 154 of file xlogfuncs.c.

155{
156#define PG_BACKUP_STOP_V2_COLS 3
157 TupleDesc tupdesc;
159 bool nulls[PG_BACKUP_STOP_V2_COLS] = {0};
161 char *backup_label;
163
164 /* Initialize attributes information in the tuple descriptor */
165 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
166 elog(ERROR, "return type must be a row type");
167
168 if (status != SESSION_BACKUP_RUNNING)
171 errmsg("backup is not in progress"),
172 errhint("Did you call pg_backup_start()?")));
173
176
177 /* Stop the backup */
179
180 /* Build the contents of backup_label */
182
186
187 /* Deallocate backup-related variables */
189
190 /* Clean up the session-level state and its memory context */
195
196 /* Returns the record as Datum */
198}
static Datum values[MAXATTR]
Definition bootstrap.c:188
#define CStringGetTextDatum(s)
Definition builtins.h:98
int errhint(const char *fmt,...) pg_attribute_printf(1
#define elog(elevel,...)
Definition elog.h:226
#define PG_RETURN_DATUM(x)
Definition fmgr.h:354
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition funcapi.c:276
@ TYPEFUNC_COMPOSITE
Definition funcapi.h:149
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition funcapi.h:230
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition heaptuple.c:1037
void pfree(void *pointer)
Definition mcxt.c:1616
void MemoryContextDelete(MemoryContext context)
Definition mcxt.c:472
static Datum LSNGetDatum(XLogRecPtr X)
Definition pg_lsn.h:31
uint64_t Datum
Definition postgres.h:70
XLogRecPtr stoppoint
Definition xlogbackup.h:35
void do_pg_backup_stop(BackupState *state, bool waitforarchive)
Definition xlog.c:9299
char * build_backup_content(BackupState *state, bool ishistoryfile)
Definition xlogbackup.c:29
#define PG_BACKUP_STOP_V2_COLS

References Assert, backup_state, backupcontext, build_backup_content(), CStringGetTextDatum, StringInfoData::data, do_pg_backup_stop(), elog, ereport, errcode(), errhint(), errmsg, ERROR, fb(), get_backup_status(), get_call_result_type(), heap_form_tuple(), HeapTupleGetDatum(), LSNGetDatum(), MemoryContextDelete(), pfree(), PG_BACKUP_STOP_V2_COLS, PG_GETARG_BOOL, PG_RETURN_DATUM, SESSION_BACKUP_RUNNING, BackupState::stoppoint, tablespace_map, TYPEFUNC_COMPOSITE, and values.

◆ pg_create_restore_point()

Datum pg_create_restore_point ( PG_FUNCTION_ARGS  )

Definition at line 263 of file xlogfuncs.c.

264{
266 char *restore_name_str;
268
269 if (RecoveryInProgress())
272 errmsg("recovery is in progress"),
273 errhint("WAL control functions cannot be executed during recovery.")));
274
275 if (!XLogIsNeeded())
278 errmsg("WAL level not sufficient for creating a restore point"),
279 errhint("\"wal_level\" must be set to \"replica\" or \"logical\" at server start.")));
280
282
286 errmsg("value too long for restore point (maximum %d characters)", MAXFNAMELEN - 1)));
287
289
290 /*
291 * As a convenience, return the WAL location of the restore point record
292 */
294}
bool RecoveryInProgress(void)
Definition xlog.c:6444
XLogRecPtr XLogRestorePoint(const char *rpName)
Definition xlog.c:8207
#define XLogIsNeeded()
Definition xlog.h:111
#define MAXFNAMELEN
uint64 XLogRecPtr
Definition xlogdefs.h:21

References ereport, errcode(), errhint(), errmsg, ERROR, fb(), 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 346 of file xlogfuncs.c.

347{
349
350 if (RecoveryInProgress())
353 errmsg("recovery is in progress"),
354 errhint("WAL control functions cannot be executed during recovery.")));
355
357
359}
XLogRecPtr GetFlushRecPtr(TimeLineID *insertTLI)
Definition xlog.c:6609

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

◆ pg_current_wal_insert_lsn()

Datum pg_current_wal_insert_lsn ( PG_FUNCTION_ARGS  )

Definition at line 325 of file xlogfuncs.c.

326{
328
329 if (RecoveryInProgress())
332 errmsg("recovery is in progress"),
333 errhint("WAL control functions cannot be executed during recovery.")));
334
336
338}
XLogRecPtr GetXLogInsertRecPtr(void)
Definition xlog.c:9614

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

◆ pg_current_wal_lsn()

Datum pg_current_wal_lsn ( PG_FUNCTION_ARGS  )

Definition at line 304 of file xlogfuncs.c.

305{
307
308 if (RecoveryInProgress())
311 errmsg("recovery is in progress"),
312 errhint("WAL control functions cannot be executed during recovery.")));
313
315
317}
XLogRecPtr GetXLogWriteRecPtr(void)
Definition xlog.c:9646

References ereport, errcode(), errhint(), errmsg, ERROR, fb(), 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 624 of file xlogfuncs.c.

625{
627
628 if (!RecoveryInProgress())
631 errmsg("recovery is not in progress"),
632 errhint("Recovery control functions can only be executed during recovery.")));
633
635
636 /* get the recovery pause state */
638}
#define PG_RETURN_TEXT_P(x)
Definition fmgr.h:374
text * cstring_to_text(const char *s)
Definition varlena.c:184
static const char * GetRecoveryPauseStateString(RecoveryPauseState pause_state)
Definition xlogfuncs.c:56
RecoveryPauseState GetRecoveryPauseState(void)
RecoveryPauseState

References cstring_to_text(), ereport, errcode(), errhint(), errmsg, ERROR, fb(), GetRecoveryPauseState(), GetRecoveryPauseStateString(), PG_RETURN_TEXT_P, and RecoveryInProgress().

◆ pg_is_in_recovery()

Datum pg_is_in_recovery ( PG_FUNCTION_ARGS  )

Definition at line 662 of file xlogfuncs.c.

663{
665}
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360

References PG_RETURN_BOOL, and RecoveryInProgress().

◆ pg_is_wal_replay_paused()

Datum pg_is_wal_replay_paused ( PG_FUNCTION_ARGS  )

Definition at line 603 of file xlogfuncs.c.

604{
605 if (!RecoveryInProgress())
608 errmsg("recovery is not in progress"),
609 errhint("Recovery control functions can only be executed during recovery.")));
610
612}

References ereport, errcode(), errhint(), errmsg, ERROR, fb(), 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 368 of file xlogfuncs.c.

369{
371
373
376
378}
#define PG_RETURN_NULL()
Definition fmgr.h:346
XLogRecPtr GetWalRcvFlushRecPtr(XLogRecPtr *latestChunkStart, TimeLineID *receiveTLI)
#define XLogRecPtrIsValid(r)
Definition xlogdefs.h:29

References fb(), GetWalRcvFlushRecPtr(), PG_RETURN_LSN, PG_RETURN_NULL, and XLogRecPtrIsValid.

◆ pg_last_wal_replay_lsn()

Datum pg_last_wal_replay_lsn ( PG_FUNCTION_ARGS  )

Definition at line 387 of file xlogfuncs.c.

388{
390
392
395
397}
XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI)

References fb(), GetXLogReplayRecPtr(), PG_RETURN_LSN, PG_RETURN_NULL, and XLogRecPtrIsValid.

◆ pg_last_xact_replay_timestamp()

Datum pg_last_xact_replay_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 647 of file xlogfuncs.c.

648{
650
652 if (xtime == 0)
654
656}
int64 TimestampTz
Definition timestamp.h:39
#define PG_RETURN_TIMESTAMPTZ(x)
Definition timestamp.h:68
TimestampTz GetLatestXTime(void)

References fb(), GetLatestXTime(), PG_RETURN_NULL, and PG_RETURN_TIMESTAMPTZ.

◆ pg_log_standby_snapshot()

Datum pg_log_standby_snapshot ( PG_FUNCTION_ARGS  )

Definition at line 232 of file xlogfuncs.c.

233{
235
236 if (RecoveryInProgress())
239 errmsg("recovery is in progress"),
240 errhint("%s cannot be executed during recovery.",
241 "pg_log_standby_snapshot()")));
242
246 errmsg("pg_log_standby_snapshot() can only be used if \"wal_level\" >= \"replica\"")));
247
249
250 /*
251 * As a convenience, return the WAL location of the last inserted record
252 */
254}
XLogRecPtr LogStandbySnapshot(void)
Definition standby.c:1284
#define XLogStandbyInfoActive()
Definition xlog.h:125

References ereport, errcode(), errhint(), errmsg, ERROR, fb(), LogStandbySnapshot(), PG_RETURN_LSN, RecoveryInProgress(), and XLogStandbyInfoActive.

◆ pg_promote()

Datum pg_promote ( PG_FUNCTION_ARGS  )

Definition at line 689 of file xlogfuncs.c.

690{
691 bool wait = PG_GETARG_BOOL(0);
695
696 if (!RecoveryInProgress())
699 errmsg("recovery is not in progress"),
700 errhint("Recovery control functions can only be executed during recovery.")));
701
702 if (wait_seconds <= 0)
705 errmsg("\"wait_seconds\" must not be negative or zero")));
706
707 /* create the promote signal file */
709 if (!promote_file)
712 errmsg("could not create file \"%s\": %m",
714
718 errmsg("could not write file \"%s\": %m",
720
721 /* signal the postmaster */
722 if (kill(PostmasterPid, SIGUSR1) != 0)
723 {
727 errmsg("failed to send signal to postmaster: %m")));
728 }
729
730 /* return immediately if waiting was not requested */
731 if (!wait)
732 PG_RETURN_BOOL(true);
733
734 /* wait for the amount of time wanted until promotion */
736 while (GetCurrentTimestamp() < end_time)
737 {
738 int rc;
739
741
742 if (!RecoveryInProgress())
743 PG_RETURN_BOOL(true);
744
746
747 rc = WaitLatch(MyLatch,
749 100L,
751
752 /*
753 * Emergency bailout if postmaster has died. This is to avoid the
754 * necessity for manual cleanup of all postmaster children.
755 */
756 if (rc & WL_POSTMASTER_DEATH)
759 errmsg("terminating connection due to unexpected postmaster exit"),
760 errcontext("while waiting on promotion")));
761 }
762
764 (errmsg_plural("server did not promote within %d second",
765 "server did not promote within %d seconds",
767 wait_seconds)));
768 PG_RETURN_BOOL(false);
769}
TimestampTz GetCurrentTimestamp(void)
Definition timestamp.c:1639
int errcode_for_file_access(void)
Definition elog.c:897
#define errcontext
Definition elog.h:198
#define FATAL
Definition elog.h:41
#define WARNING
Definition elog.h:36
int int int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...) pg_attribute_printf(1
int FreeFile(FILE *file)
Definition fd.c:2827
FILE * AllocateFile(const char *name, const char *mode)
Definition fd.c:2628
#define PG_GETARG_INT32(n)
Definition fmgr.h:269
pid_t PostmasterPid
Definition globals.c:106
struct Latch * MyLatch
Definition globals.c:63
void ResetLatch(Latch *latch)
Definition latch.c:374
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition latch.c:172
#define CHECK_FOR_INTERRUPTS()
Definition miscadmin.h:123
static char promote_file[MAXPGPATH]
Definition pg_ctl.c:101
static int wait_seconds
Definition pg_ctl.c:77
static int64 end_time
Definition pgbench.c:176
#define TimestampTzPlusSeconds(tz, s)
Definition timestamp.h:86
#define WL_TIMEOUT
#define WL_LATCH_SET
#define WL_POSTMASTER_DEATH
#define kill(pid, sig)
Definition win32_port.h:490
#define SIGUSR1
Definition win32_port.h:170
#define PROMOTE_SIGNAL_FILE
Definition xlog.h:328

References AllocateFile(), CHECK_FOR_INTERRUPTS, end_time, ereport, errcode(), errcode_for_file_access(), errcontext, errhint(), errmsg, errmsg_plural(), ERROR, FATAL, fb(), FreeFile(), GetCurrentTimestamp(), kill, MyLatch, PG_GETARG_BOOL, PG_GETARG_INT32, PG_RETURN_BOOL, PostmasterPid, promote_file, PROMOTE_SIGNAL_FILE, RecoveryInProgress(), ResetLatch(), SIGUSR1, TimestampTzPlusSeconds, wait_seconds, WaitLatch(), WARNING, WL_LATCH_SET, WL_POSTMASTER_DEATH, and WL_TIMEOUT.

◆ pg_split_walfile_name()

Datum pg_split_walfile_name ( PG_FUNCTION_ARGS  )

Definition at line 494 of file xlogfuncs.c.

495{
496#define PG_SPLIT_WALFILE_NAME_COLS 2
497 char *fname = text_to_cstring(PG_GETARG_TEXT_PP(0));
498 char *fname_upper;
499 char *p;
500 TimeLineID tli;
501 XLogSegNo segno;
503 bool isnull[PG_SPLIT_WALFILE_NAME_COLS] = {0};
504 TupleDesc tupdesc;
505 HeapTuple tuple;
506 char buf[256];
507 Datum result;
508
509 fname_upper = pstrdup(fname);
510
511 /* Capitalize WAL file name. */
512 for (p = fname_upper; *p; p++)
513 *p = pg_ascii_toupper((unsigned char) *p);
514
518 errmsg("invalid WAL file name \"%s\"", fname)));
519
521
522 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
523 elog(ERROR, "return type must be a row type");
524
525 /* Convert to numeric. */
526 snprintf(buf, sizeof buf, UINT64_FORMAT, segno);
530 Int32GetDatum(-1));
531
532 values[1] = Int64GetDatum(tli);
533
534 tuple = heap_form_tuple(tupdesc, values, isnull);
535 result = HeapTupleGetDatum(tuple);
536
537 PG_RETURN_DATUM(result);
538
539#undef PG_SPLIT_WALFILE_NAME_COLS
540}
Datum numeric_in(PG_FUNCTION_ARGS)
Definition numeric.c:626
#define UINT64_FORMAT
Definition c.h:637
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition fmgr.h:688
char * pstrdup(const char *in)
Definition mcxt.c:1781
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define snprintf
Definition port.h:260
static unsigned char pg_ascii_toupper(unsigned char ch)
Definition port.h:177
static Datum Int64GetDatum(int64 X)
Definition postgres.h:413
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
static Datum CStringGetDatum(const char *X)
Definition postgres.h:370
static Datum Int32GetDatum(int32 X)
Definition postgres.h:212
int wal_segment_size
Definition xlog.c:147
static bool IsXLogFileName(const char *fname)
static void XLogFromFileName(const char *fname, TimeLineID *tli, XLogSegNo *logSegNo, int wal_segsz_bytes)
uint32 TimeLineID
Definition xlogdefs.h:63
uint64 XLogSegNo
Definition xlogdefs.h:52
#define PG_SPLIT_WALFILE_NAME_COLS

References buf, CStringGetDatum(), DirectFunctionCall3, elog, ereport, errcode(), errmsg, ERROR, fb(), get_call_result_type(), heap_form_tuple(), HeapTupleGetDatum(), Int32GetDatum(), Int64GetDatum(), IsXLogFileName(), numeric_in(), ObjectIdGetDatum(), pg_ascii_toupper(), PG_GETARG_TEXT_PP, PG_RETURN_DATUM, PG_SPLIT_WALFILE_NAME_COLS, pstrdup(), snprintf, text_to_cstring(), TYPEFUNC_COMPOSITE, UINT64_FORMAT, values, wal_segment_size, and XLogFromFileName().

◆ pg_stat_get_recovery()

Datum pg_stat_get_recovery ( PG_FUNCTION_ARGS  )

Definition at line 778 of file xlogfuncs.c.

779{
780 TupleDesc tupdesc;
781 Datum *values;
782 bool *nulls;
783
784 /* Local copies of shared state */
794
795 if (!RecoveryInProgress())
797
800
801 /* Take a lock to ensure value consistency */
813
814 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
815 elog(ERROR, "return type must be a row type");
816
817 values = palloc0_array(Datum, tupdesc->natts);
818 nulls = palloc0_array(bool, tupdesc->natts);
819
821
824 else
825 nulls[1] = true;
826
829 else
830 nulls[2] = true;
831
834 else
835 nulls[3] = true;
836
839 else
840 nulls[4] = true;
841
844 else
845 nulls[5] = true;
846
849 else
850 nulls[6] = true;
851
854 else
855 nulls[7] = true;
856
858
860}
bool has_privs_of_role(Oid member, Oid role)
Definition acl.c:5314
#define palloc0_array(type, count)
Definition fe_memutils.h:77
Oid GetUserId(void)
Definition miscinit.c:470
static Datum BoolGetDatum(bool X)
Definition postgres.h:112
static void SpinLockRelease(volatile slock_t *lock)
Definition spin.h:62
static void SpinLockAcquire(volatile slock_t *lock)
Definition spin.h:56
XLogRecPtr lastReplayedEndRecPtr
TimeLineID replayEndTLI
TimeLineID lastReplayedTLI
TimestampTz currentChunkStartTime
XLogRecPtr replayEndRecPtr
TimestampTz recoveryLastXTime
RecoveryPauseState recoveryPauseState
XLogRecPtr lastReplayedReadRecPtr
static Datum TimestampTzGetDatum(TimestampTz X)
Definition timestamp.h:52
XLogRecoveryCtlData * XLogRecoveryCtl

References BoolGetDatum(), CStringGetTextDatum, XLogRecoveryCtlData::currentChunkStartTime, elog, ERROR, fb(), get_call_result_type(), GetRecoveryPauseStateString(), GetUserId(), has_privs_of_role(), heap_form_tuple(), HeapTupleGetDatum(), XLogRecoveryCtlData::info_lck, Int32GetDatum(), XLogRecoveryCtlData::lastReplayedEndRecPtr, XLogRecoveryCtlData::lastReplayedReadRecPtr, XLogRecoveryCtlData::lastReplayedTLI, LSNGetDatum(), TupleDescData::natts, palloc0_array, PG_RETURN_DATUM, PG_RETURN_NULL, RecoveryInProgress(), XLogRecoveryCtlData::recoveryLastXTime, XLogRecoveryCtlData::recoveryPauseState, XLogRecoveryCtlData::replayEndRecPtr, XLogRecoveryCtlData::replayEndTLI, XLogRecoveryCtlData::SharedPromoteIsTriggered, SpinLockAcquire(), SpinLockRelease(), TimestampTzGetDatum(), TYPEFUNC_COMPOSITE, values, XLogRecoveryCtl, and XLogRecPtrIsValid.

◆ pg_switch_wal()

Datum pg_switch_wal ( PG_FUNCTION_ARGS  )

Definition at line 207 of file xlogfuncs.c.

208{
210
211 if (RecoveryInProgress())
214 errmsg("recovery is in progress"),
215 errhint("WAL control functions cannot be executed during recovery.")));
216
218
219 /*
220 * As a convenience, return the WAL location of the switch record
221 */
223}
XLogRecPtr RequestXLogSwitch(bool mark_unimportant)
Definition xlog.c:8189

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

◆ pg_wal_lsn_diff()

Datum pg_wal_lsn_diff ( PG_FUNCTION_ARGS  )

Definition at line 671 of file xlogfuncs.c.

672{
673 Datum result;
674
677 PG_GETARG_DATUM(1));
678
679 PG_RETURN_DATUM(result);
680}
#define DirectFunctionCall2(func, arg1, arg2)
Definition fmgr.h:686
#define PG_GETARG_DATUM(n)
Definition fmgr.h:268
Datum pg_lsn_mi(PG_FUNCTION_ARGS)
Definition pg_lsn.c:219

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

◆ pg_wal_replay_pause()

Datum pg_wal_replay_pause ( PG_FUNCTION_ARGS  )

Definition at line 549 of file xlogfuncs.c.

550{
551 if (!RecoveryInProgress())
554 errmsg("recovery is not in progress"),
555 errhint("Recovery control functions can only be executed during recovery.")));
556
557 if (PromoteIsTriggered())
560 errmsg("standby promotion is ongoing"),
561 errhint("%s cannot be executed after promotion is triggered.",
562 "pg_wal_replay_pause()")));
563
564 SetRecoveryPause(true);
565
566 /* wake up the recovery process so that it can process the pause request */
568
570}
#define PG_RETURN_VOID()
Definition fmgr.h:350
void SetRecoveryPause(bool recoveryPause)
void WakeupRecovery(void)
bool PromoteIsTriggered(void)

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

◆ pg_wal_replay_resume()

Datum pg_wal_replay_resume ( PG_FUNCTION_ARGS  )

Definition at line 579 of file xlogfuncs.c.

580{
581 if (!RecoveryInProgress())
584 errmsg("recovery is not in progress"),
585 errhint("Recovery control functions can only be executed during recovery.")));
586
587 if (PromoteIsTriggered())
590 errmsg("standby promotion is ongoing"),
591 errhint("%s cannot be executed after promotion is triggered.",
592 "pg_wal_replay_resume()")));
593
594 SetRecoveryPause(false);
595
597}

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

◆ pg_walfile_name()

Datum pg_walfile_name ( PG_FUNCTION_ARGS  )

Definition at line 469 of file xlogfuncs.c.

470{
474
475 if (RecoveryInProgress())
478 errmsg("recovery is in progress"),
479 errhint("%s cannot be executed during recovery.",
480 "pg_walfile_name()")));
481
485
487}
#define PG_GETARG_LSN(n)
Definition pg_lsn.h:36
TimeLineID GetWALInsertionTimeLine(void)
Definition xlog.c:6630
#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes)
static void XLogFileName(char *fname, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)

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

◆ pg_walfile_name_offset()

Datum pg_walfile_name_offset ( PG_FUNCTION_ARGS  )

Definition at line 404 of file xlogfuncs.c.

405{
410 Datum values[2];
411 bool isnull[2];
414 Datum result;
415
416 if (RecoveryInProgress())
419 errmsg("recovery is in progress"),
420 errhint("%s cannot be executed during recovery.",
421 "pg_walfile_name_offset()")));
422
423 /*
424 * Construct a tuple descriptor for the result row. This must match this
425 * function's pg_proc entry!
426 */
429 TEXTOID, -1, 0);
431 INT4OID, -1, 0);
432
435
436 /*
437 * xlogfilename
438 */
442
444 isnull[0] = false;
445
446 /*
447 * offset
448 */
450
452 isnull[1] = false;
453
454 /*
455 * Tuple jam: Having first prepared your Datums, then squash together
456 */
458
460
461 PG_RETURN_DATUM(result);
462}
int16 AttrNumber
Definition attnum.h:21
uint32_t uint32
Definition c.h:618
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
static Datum UInt32GetDatum(uint32 X)
Definition postgres.h:232
TupleDesc CreateTemplateTupleDesc(int natts)
Definition tupdesc.c:165
void TupleDescFinalize(TupleDesc tupdesc)
Definition tupdesc.c:511
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition tupdesc.c:900
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)

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

Variable Documentation

◆ backup_state

BackupState* backup_state = NULL
static

◆ backupcontext

MemoryContext backupcontext = NULL
static

Definition at line 48 of file xlogfuncs.c.

Referenced by pg_backup_start(), and pg_backup_stop().

◆ tablespace_map

StringInfo tablespace_map = NULL
static

Definition at line 45 of file xlogfuncs.c.

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