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
 
#define WAITS_PER_SECOND   10
 

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

◆ WAITS_PER_SECOND

#define WAITS_PER_SECOND   10

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:906
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:739
char * text_to_cstring(const text *t)
Definition varlena.c:215
SessionBackupState get_backup_status(void)
Definition xlog.c:9252
void register_persistent_abort_backup_handler(void)
Definition xlog.c:9572
void do_pg_backup_start(const char *backupidstr, bool fast, List **tablespaces, BackupState *state, StringInfo tblspcmapfile)
Definition xlog.c:8949
SessionBackupState
Definition xlog.h:303
@ SESSION_BACKUP_RUNNING
Definition xlog.h:305
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:187
#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:1117
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:9271
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:9586

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:9602

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 623 of file xlogfuncs.c.

624{
626
627 if (!RecoveryInProgress())
630 errmsg("recovery is not in progress"),
631 errhint("Recovery control functions can only be executed during recovery.")));
632
634
635 /* get the recovery pause state */
637}
#define PG_RETURN_TEXT_P(x)
Definition fmgr.h:374
text * cstring_to_text(const char *s)
Definition varlena.c:182
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 661 of file xlogfuncs.c.

662{
664}
#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 602 of file xlogfuncs.c.

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

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 646 of file xlogfuncs.c.

647{
649
651 if (xtime == 0)
653
655}
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:1283
#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 688 of file xlogfuncs.c.

689{
690 bool wait = PG_GETARG_BOOL(0);
693 int i;
694
695 if (!RecoveryInProgress())
698 errmsg("recovery is not in progress"),
699 errhint("Recovery control functions can only be executed during recovery.")));
700
701 if (wait_seconds <= 0)
704 errmsg("\"wait_seconds\" must not be negative or zero")));
705
706 /* create the promote signal file */
708 if (!promote_file)
711 errmsg("could not create file \"%s\": %m",
713
717 errmsg("could not write file \"%s\": %m",
719
720 /* signal the postmaster */
721 if (kill(PostmasterPid, SIGUSR1) != 0)
722 {
726 errmsg("failed to send signal to postmaster: %m")));
727 }
728
729 /* return immediately if waiting was not requested */
730 if (!wait)
731 PG_RETURN_BOOL(true);
732
733 /* wait for the amount of time wanted until promotion */
734#define WAITS_PER_SECOND 10
735 for (i = 0; i < WAITS_PER_SECOND * wait_seconds; i++)
736 {
737 int rc;
738
740
741 if (!RecoveryInProgress())
742 PG_RETURN_BOOL(true);
743
745
746 rc = WaitLatch(MyLatch,
748 1000L / WAITS_PER_SECOND,
750
751 /*
752 * Emergency bailout if postmaster has died. This is to avoid the
753 * necessity for manual cleanup of all postmaster children.
754 */
755 if (rc & WL_POSTMASTER_DEATH)
758 errmsg("terminating connection due to unexpected postmaster exit"),
759 errcontext("while waiting on promotion")));
760 }
761
763 (errmsg_plural("server did not promote within %d second",
764 "server did not promote within %d seconds",
766 wait_seconds)));
767 PG_RETURN_BOOL(false);
768}
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
int i
Definition isn.c:77
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
#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:326
#define WAITS_PER_SECOND

References AllocateFile(), CHECK_FOR_INTERRUPTS, ereport, errcode(), errcode_for_file_access(), errcontext, errhint(), errmsg, errmsg_plural(), ERROR, FATAL, fb(), FreeFile(), i, kill, MyLatch, PG_GETARG_BOOL, PG_GETARG_INT32, PG_RETURN_BOOL, PostmasterPid, promote_file, PROMOTE_SIGNAL_FILE, RecoveryInProgress(), ResetLatch(), SIGUSR1, wait_seconds, WaitLatch(), WAITS_PER_SECOND, 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 493 of file xlogfuncs.c.

494{
495#define PG_SPLIT_WALFILE_NAME_COLS 2
496 char *fname = text_to_cstring(PG_GETARG_TEXT_PP(0));
497 char *fname_upper;
498 char *p;
499 TimeLineID tli;
500 XLogSegNo segno;
502 bool isnull[PG_SPLIT_WALFILE_NAME_COLS] = {0};
503 TupleDesc tupdesc;
504 HeapTuple tuple;
505 char buf[256];
506 Datum result;
507
508 fname_upper = pstrdup(fname);
509
510 /* Capitalize WAL file name. */
511 for (p = fname_upper; *p; p++)
512 *p = pg_ascii_toupper((unsigned char) *p);
513
517 errmsg("invalid WAL file name \"%s\"", fname)));
518
520
521 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
522 elog(ERROR, "return type must be a row type");
523
524 /* Convert to numeric. */
525 snprintf(buf, sizeof buf, UINT64_FORMAT, segno);
529 Int32GetDatum(-1));
530
531 values[1] = Int64GetDatum(tli);
532
533 tuple = heap_form_tuple(tupdesc, values, isnull);
534 result = HeapTupleGetDatum(tuple);
535
536 PG_RETURN_DATUM(result);
537
538#undef PG_SPLIT_WALFILE_NAME_COLS
539}
Datum numeric_in(PG_FUNCTION_ARGS)
Definition numeric.c:626
#define UINT64_FORMAT
Definition c.h:598
#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:423
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
static Datum CStringGetDatum(const char *X)
Definition postgres.h:380
static Datum Int32GetDatum(int32 X)
Definition postgres.h:222
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 777 of file xlogfuncs.c.

778{
779 TupleDesc tupdesc;
780 Datum *values;
781 bool *nulls;
782
783 /* Local copies of shared state */
793
794 if (!RecoveryInProgress())
796
799
800 /* Take a lock to ensure value consistency */
812
813 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
814 elog(ERROR, "return type must be a row type");
815
816 values = palloc0_array(Datum, tupdesc->natts);
817 nulls = palloc0_array(bool, tupdesc->natts);
818
820
823 else
824 nulls[1] = true;
825
828 else
829 nulls[2] = true;
830
833 else
834 nulls[3] = true;
835
838 else
839 nulls[4] = true;
840
843 else
844 nulls[5] = true;
845
848 else
849 nulls[6] = true;
850
853 else
854 nulls[7] = true;
855
857
859}
bool has_privs_of_role(Oid member, Oid role)
Definition acl.c:5298
#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 670 of file xlogfuncs.c.

671{
672 Datum result;
673
676 PG_GETARG_DATUM(1));
677
678 PG_RETURN_DATUM(result);
679}
#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 548 of file xlogfuncs.c.

549{
550 if (!RecoveryInProgress())
553 errmsg("recovery is not in progress"),
554 errhint("Recovery control functions can only be executed during recovery.")));
555
556 if (PromoteIsTriggered())
559 errmsg("standby promotion is ongoing"),
560 errhint("%s cannot be executed after promotion is triggered.",
561 "pg_wal_replay_pause()")));
562
563 SetRecoveryPause(true);
564
565 /* wake up the recovery process so that it can process the pause request */
567
569}
#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 578 of file xlogfuncs.c.

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

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 468 of file xlogfuncs.c.

469{
473
474 if (RecoveryInProgress())
477 errmsg("recovery is in progress"),
478 errhint("%s cannot be executed during recovery.",
479 "pg_walfile_name()")));
480
484
486}
#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{
407 uint32 xrecoff;
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
434
435 /*
436 * xlogfilename
437 */
441
443 isnull[0] = false;
444
445 /*
446 * offset
447 */
449
450 values[1] = UInt32GetDatum(xrecoff);
451 isnull[1] = false;
452
453 /*
454 * Tuple jam: Having first prepared your Datums, then squash together
455 */
457
459
460 PG_RETURN_DATUM(result);
461}
int16 AttrNumber
Definition attnum.h:21
uint32_t uint32
Definition c.h:579
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
static Datum UInt32GetDatum(uint32 X)
Definition postgres.h:242
TupleDesc CreateTemplateTupleDesc(int natts)
Definition tupdesc.c:165
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition tupdesc.c:825
#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(), 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().