35{
40 bool throw = true;
43 const char *result = "<unset>";
47
48
51
53 {
55 {
57
61
63
72 else
75 errmsg(
"unrecognized value for %s option \"%s\": \"%s\"",
78 }
80 {
83 double result;
84
88
90
92 {
97 }
98
99
100
101
102
103
104 result =
rint(result);
105
106
110 errmsg(
"timeout value is out of range"));
111
112 if (result < 0)
115 errmsg(
"timeout cannot be negative"));
116
118 }
120 {
123
125
127 }
128 else
129 {
132 errmsg(
"option \"%s\" not recognized",
135 }
136 }
137
138
139
140
141
142
143
144
145
146
147
148
149
152
153
154
155
156
158
159
163 errmsg(
"WAIT FOR must be called without an active or registered snapshot"),
164 errdetail(
"WAIT FOR cannot be executed from a function or procedure, nor within a transaction with an isolation level higher than READ COMMITTED."));
165
166
167
168
169
171
172
173
174
175
177 {
181 errmsg(
"recovery is in progress"),
182 errhint(
"Waiting for primary_flush can only be done on a primary server. "
183 "Use standby_flush mode on a standby server.")));
184 }
185
186
188
189
190
191
193 {
195
196 result = "success";
197 break;
198
200 if (throw)
201 {
203
204 switch (lsnType)
205 {
209 errmsg(
"timed out while waiting for target LSN %X/%08X to be replayed; current standby_replay LSN %X/%08X",
212 break;
213
217 errmsg(
"timed out while waiting for target LSN %X/%08X to be written; current standby_write LSN %X/%08X",
220 break;
221
225 errmsg(
"timed out while waiting for target LSN %X/%08X to be flushed; current standby_flush LSN %X/%08X",
228 break;
229
233 errmsg(
"timed out while waiting for target LSN %X/%08X to be flushed; current primary_flush LSN %X/%08X",
236 break;
237
238 default:
239 elog(
ERROR,
"unexpected wait LSN type %d", lsnType);
240 }
241 }
242 else
243 result = "timeout";
244 break;
245
247 if (throw)
248 {
250 {
252
253 switch (lsnType)
254 {
258 errmsg(
"recovery is not in progress"),
259 errdetail(
"Recovery ended before target LSN %X/%08X was replayed; last standby_replay LSN %X/%08X.",
262 break;
263
267 errmsg(
"recovery is not in progress"),
268 errdetail(
"Recovery ended before target LSN %X/%08X was written; last standby_write LSN %X/%08X.",
271 break;
272
276 errmsg(
"recovery is not in progress"),
277 errdetail(
"Recovery ended before target LSN %X/%08X was flushed; last standby_flush LSN %X/%08X.",
280 break;
281
282 default:
283 elog(
ERROR,
"unexpected wait LSN type %d", lsnType);
284 }
285 }
286 else
287 {
288 switch (lsnType)
289 {
293 errmsg(
"recovery is not in progress"),
294 errhint(
"Waiting for the standby_replay LSN can only be executed during recovery."));
295 break;
296
300 errmsg(
"recovery is not in progress"),
301 errhint(
"Waiting for the standby_write LSN can only be executed during recovery."));
302 break;
303
307 errmsg(
"recovery is not in progress"),
308 errhint(
"Waiting for the standby_flush LSN can only be executed during recovery."));
309 break;
310
311 default:
312 elog(
ERROR,
"unexpected wait LSN type %d", lsnType);
313 }
314 }
315 }
316 else
317 result = "not in recovery";
318 break;
319 }
320
321
323
324
326
327
329
331}
#define Assert(condition)
#define FLOAT8_FITS_IN_INT64(num)
char * defGetString(DefElem *def)
bool defGetBoolean(DefElem *def)
void errorConflictingDefElem(DefElem *defel, ParseState *pstate)
int errcode(int sqlerrcode)
int errhint(const char *fmt,...) pg_attribute_printf(1
int errdetail(const char *fmt,...) pg_attribute_printf(1
#define ereport(elevel,...)
const TupleTableSlotOps TTSOpsVirtual
void end_tup_output(TupOutputState *tstate)
TupOutputState * begin_tup_output_tupdesc(DestReceiver *dest, TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
#define do_text_output_oneline(tstate, str_to_emit)
#define DirectFunctionCall1(func, arg1)
bool parse_real(const char *value, double *result, int flags, const char **hintmsg)
int parser_errposition(ParseState *pstate, int location)
#define foreach_node(type, var, lst)
Datum pg_lsn_in(PG_FUNCTION_ARGS)
static XLogRecPtr DatumGetLSN(Datum X)
int pg_strcasecmp(const char *s1, const char *s2)
static Datum CStringGetDatum(const char *X)
bool ActiveSnapshotSet(void)
bool HaveRegisteredOrActiveSnapshot(void)
void PopActiveSnapshot(void)
void InvalidateCatalogSnapshot(void)
#define InvalidTransactionId
TupleDesc WaitStmtResultDesc(WaitStmt *stmt)
bool RecoveryInProgress(void)
#define LSN_FORMAT_ARGS(lsn)
bool PromoteIsTriggered(void)
XLogRecPtr GetCurrentLSNForWaitType(WaitLSNType lsnType)
WaitLSNResult WaitForLSN(WaitLSNType lsnType, XLogRecPtr targetLSN, int64 timeout)
@ WAIT_LSN_RESULT_NOT_IN_RECOVERY
@ WAIT_LSN_RESULT_TIMEOUT
@ WAIT_LSN_RESULT_SUCCESS
@ WAIT_LSN_TYPE_PRIMARY_FLUSH
@ WAIT_LSN_TYPE_STANDBY_REPLAY
@ WAIT_LSN_TYPE_STANDBY_FLUSH
@ WAIT_LSN_TYPE_STANDBY_WRITE