8000 Add new user fn pg_current_xlog_flush_location() · bobby-lin/postgres@e63bb45 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e63bb45

Browse files
Add new user fn pg_current_xlog_flush_location()
Tomas Vondra, reviewed by Michael Paquier and Amit Kapila Minor edits by me
1 parent 1e29e63 commit e63bb45

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

doc/src/sgml/func.sgml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16788,6 +16788,9 @@ SELECT set_config('log_statement_stats', 'off', false);
1678816788
<indexterm>
1678916789
<primary>pg_create_restore_point</primary>
1679016790
</indexterm>
16791+
<indexterm>
16792+
<primary>pg_current_xlog_flush_location</primary>
16793+
</indexterm>
1679116794
<indexterm>
1679216795
<primary>pg_current_xlog_insert_location</primary>
1679316796
</indexterm>
@@ -16843,6 +16846,13 @@ SELECT set_config('log_statement_stats', 'off', false);
1684316846
<entry><type>pg_lsn</type></entry>
1684416847
<entry>Create a named point for performing restore (restricted to superusers)</entry>
1684516848
</row>
16849+
<row>
16850+
<entry>
16851+
<literal><function>pg_current_xlog_flush_location()</function></literal>
16852+
</entry>
16853+
<entry><type>pg_lsn</type></entry>
16854+
<entry>Get current transaction log flush location</entry>
16855+
</row>
1684616856
<row>
1684716857
<entry>
1684816858
<literal><function>pg_current_xlog_insert_location()</function></literal>
@@ -16977,13 +16987,14 @@ postgres=# select pg_start_backup('label_goes_here');
1697716987
<function>pg_current_xlog_location</> displays the current transaction log write
1697816988
location in the same format used by the above functions. Similarly,
1697916989
<function>pg_current_xlog_insert_location</> displays the current transaction log
16980-
insertion point. The insertion point is the <quote>logical</> end
16981-
of the transaction log
16982-
at any instant, while the write location is the end of what has actually
16983-
been written out from the server's internal buffers. The write location
16984-
is the end of what can be examined from outside the server, and is usually
16990+
insertion point and <function>pg_current_xlog_flush_location</> displays the
16991+
current transaction log flush point. The insertion point is the <quote>logical</>
16992+
end of the transaction log at any instant, while the write location is the end of
16993+
what has actually been written out from the server's internal buffers and flush
16994+
location is the location guaranteed to be written to durable storage. The write
16995+
location is the end of what can be examined from outside the server, and is usually
1698516996
what you want if you are interested in archiving partially-complete transaction log
16986-
files. The insertion point is made available primarily for server
16997+
files. The insertion and flush points are made available primarily for server
1698716998
debugging purposes. These are both read-only operations and do not
1698816999
require superuser permissions.
1698917000
</para>

src/backend/access/transam/xlogfuncs.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,27 @@ pg_current_xlog_insert_location(PG_FUNCTION_ARGS)
215215
PG_RETURN_LSN(current_recptr);
216216
}
217217

218+
/*
219+
* Report the current WAL flush location (same format as pg_start_backup etc)
220+
*
221+
* This function is mostly for debugging purposes.
222+
*/
223+
Datum
224+
pg_current_xlog_flush_location(PG_FUNCTION_ARGS)
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 = GetFlushRecPtr();
235+
236+
PG_RETURN_LSN(current_recptr);
237+
}
238+
218239
/*
219240
* Report the last WAL receive location (same format as pg_start_backup etc)
220241
*

src/include/access/xlog_fn.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extern Datum pg_switch_xlog(PG_FUNCTION_ARGS);
1919
extern Datum pg_create_restore_point(PG_FUNCTION_ARGS);
2020
extern Datum pg_current_xlog_location(PG_FUNCTION_ARGS);
2121
extern Datum pg_current_xlog_insert_location(PG_FUNCTION_ARGS);
22+
extern Datum pg_current_xlog_flush_location(PG_FUNCTION_ARGS);
2223
extern Datum pg_last_xlog_receive_location(PG_FUNCTION_ARGS);
2324
extern Datum pg_last_xlog_replay_location(PG_FUNCTION_ARGS);
2425
extern Datum pg_last_xact_replay_timestamp(PG_FUNCTION_ARGS);

src/include/catalog/pg_proc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3158,6 +3158,8 @@ DATA(insert OID = 2849 ( pg_current_xlog_location PGNSP PGUID 12 1 0 0 0 f f f f
31583158
DESCR("current xlog write location");
31593159
DATA(insert OID = 2852 ( pg_current_xlog_insert_location PGNSP PGUID 12 1 0 0 0 f f f f t f v s 0 0 3220 "" _null_ _null_ _null_ _null_ _null_ pg_current_xlog_insert_location _null_ _null_ _null_ ));
31603160
DESCR("current xlog insert location");
3161+
DATA(insert OID = 3330 ( pg_current_xlog_flush_location PGNSP PGUID 12 1 0 0 0 f f f f t f v s 0 0 3220 "" _null_ _null_ _null_ _null_ _null_ pg_current_xlog_flush_location _null_ _null_ _null_ ));
3162+
DESCR("current xlog flush location");
31613163
DATA(insert OID = 2850 ( pg_xlogfile_name_offset PGNSP PGUID 12 1 0 0 0 f f f f t f i s 1 0 2249 "3220" "{3220,25,23}" "{i,o,o}" "{wal_location,file_name,file_offset}" _null_ _null_ pg_xlogfile_name_offset _null_ _null_ _null_ ));
31623164
DESCR("xlog filename and byte offset, given an xlog location");
31633165
DATA(insert OID = 2851 ( pg_xlogfile_name PGNSP PGUID 12 1 0 0 0 f f f f t f i s 1 0 25 "3220" _null_ _null_ _null_ _null_ _null_ pg_xlogfile_name _null_ _null_ _null_ ));

0 commit comments

Comments
 (0)
0