mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-02-17 19:30:00 +08:00
modify segno. for pg_walfile_name() and pg_walfile_name_offset()
Previously these functions returned the previous segment number if the LSN was on a segment boundary. We now always return the current segment number for an LSN. Docs updated to reflect this change. Regression tests added, author Andres Freund. Also mentioned in thread https://postgr.es/m/flat/20220204225057.GA1535307%40nathanxps13#d964275c9540d8395e138efc0a75f7e8 BACKWARD INCOMPATIBILITY Reported-by: Kyotaro Horiguchi Discussion: https://postgr.es/m/20190726.172120.101752680.horikyota.ntt@gmail.com Co-authored-by: Kyotaro Horiguchi Backpatch-through: master
This commit is contained in:
parent
5c4c7efadd
commit
344afc7769
@ -27075,11 +27075,6 @@ postgres=# SELECT * FROM pg_walfile_name_offset((pg_backup_stop()).lsn);
|
||||
(1 row)
|
||||
</programlisting>
|
||||
Similarly, <function>pg_walfile_name</function> extracts just the write-ahead log file name.
|
||||
When the given write-ahead log location is exactly at a write-ahead log file boundary, both
|
||||
these functions return the name of the preceding write-ahead log file.
|
||||
This is usually the desired behavior for managing write-ahead log archiving
|
||||
behavior, since the preceding file is the last one that currently
|
||||
needs to be archived.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
|
@ -374,10 +374,6 @@ pg_last_wal_replay_lsn(PG_FUNCTION_ARGS)
|
||||
/*
|
||||
* Compute an xlog file name and decimal byte offset given a WAL location,
|
||||
* such as is returned by pg_backup_stop() or pg_switch_wal().
|
||||
*
|
||||
* Note that a location exactly at a segment boundary is taken to be in
|
||||
* the previous segment. This is usually the right thing, since the
|
||||
* expected usage is to determine which xlog file(s) are ready to archive.
|
||||
*/
|
||||
Datum
|
||||
pg_walfile_name_offset(PG_FUNCTION_ARGS)
|
||||
@ -414,7 +410,7 @@ pg_walfile_name_offset(PG_FUNCTION_ARGS)
|
||||
/*
|
||||
* xlogfilename
|
||||
*/
|
||||
XLByteToPrevSeg(locationpoint, xlogsegno, wal_segment_size);
|
||||
XLByteToSeg(locationpoint, xlogsegno, wal_segment_size);
|
||||
XLogFileName(xlogfilename, GetWALInsertionTimeLine(), xlogsegno,
|
||||
wal_segment_size);
|
||||
|
||||
@ -457,7 +453,7 @@ pg_walfile_name(PG_FUNCTION_ARGS)
|
||||
errhint("%s cannot be executed during recovery.",
|
||||
"pg_walfile_name()")));
|
||||
|
||||
XLByteToPrevSeg(locationpoint, xlogsegno, wal_segment_size);
|
||||
XLByteToSeg(locationpoint, xlogsegno, wal_segment_size);
|
||||
XLogFileName(xlogfilename, GetWALInsertionTimeLine(), xlogsegno,
|
||||
wal_segment_size);
|
||||
|
||||
|
@ -619,7 +619,7 @@ SELECT count(*) > 0 AS ok FROM pg_control_system();
|
||||
t
|
||||
(1 row)
|
||||
|
||||
-- pg_split_walfile_name
|
||||
-- pg_split_walfile_name, pg_walfile_name & pg_walfile_name_offset
|
||||
SELECT * FROM pg_split_walfile_name(NULL);
|
||||
segment_number | timeline_id
|
||||
----------------+-------------
|
||||
@ -642,3 +642,31 @@ SELECT segment_number > 0 AS ok_segment_number, timeline_id
|
||||
t | 4294967295
|
||||
(1 row)
|
||||
|
||||
SELECT setting::int8 AS segment_size
|
||||
FROM pg_settings
|
||||
WHERE name = 'wal_segment_size'
|
||||
\gset
|
||||
SELECT segment_number, file_offset
|
||||
FROM pg_walfile_name_offset('0/0'::pg_lsn + :segment_size),
|
||||
pg_split_walfile_name(file_name);
|
||||
segment_number | file_offset
|
||||
----------------+-------------
|
||||
1 | 0
|
||||
(1 row)
|
||||
|
||||
SELECT segment_number, file_offset
|
||||
FROM pg_walfile_name_offset('0/0'::pg_lsn + :segment_size + 1),
|
||||
pg_split_walfile_name(file_name);
|
||||
segment_number | file_offset
|
||||
----------------+-------------
|
||||
1 | 1
|
||||
(1 row)
|
||||
|
||||
SELECT segment_number, file_offset = :segment_size - 1
|
||||
FROM pg_walfile_name_offset('0/0'::pg_lsn + :segment_size - 1),
|
||||
pg_split_walfile_name(file_name);
|
||||
segment_number | ?column?
|
||||
----------------+----------
|
||||
0 | t
|
||||
(1 row)
|
||||
|
||||
|
@ -230,10 +230,23 @@ SELECT count(*) > 0 AS ok FROM pg_control_init();
|
||||
SELECT count(*) > 0 AS ok FROM pg_control_recovery();
|
||||
SELECT count(*) > 0 AS ok FROM pg_control_system();
|
||||
|
||||
-- pg_split_walfile_name
|
||||
-- pg_split_walfile_name, pg_walfile_name & pg_walfile_name_offset
|
||||
SELECT * FROM pg_split_walfile_name(NULL);
|
||||
SELECT * FROM pg_split_walfile_name('invalid');
|
||||
SELECT segment_number > 0 AS ok_segment_number, timeline_id
|
||||
FROM pg_split_walfile_name('000000010000000100000000');
|
||||
SELECT segment_number > 0 AS ok_segment_number, timeline_id
|
||||
FROM pg_split_walfile_name('ffffffFF00000001000000af');
|
||||
SELECT setting::int8 AS segment_size
|
||||
FROM pg_settings
|
||||
WHERE name = 'wal_segment_size'
|
||||
\gset
|
||||
SELECT segment_number, file_offset
|
||||
FROM pg_walfile_name_offset('0/0'::pg_lsn + :segment_size),
|
||||
pg_split_walfile_name(file_name);
|
||||
SELECT segment_number, file_offset
|
||||
FROM pg_walfile_name_offset('0/0'::pg_lsn + :segment_size + 1),
|
||||
pg_split_walfile_name(file_name);
|
||||
SELECT segment_number, file_offset = :segment_size - 1
|
||||
FROM pg_walfile_name_offset('0/0'::pg_lsn + :segment_size - 1),
|
||||
pg_split_walfile_name(file_name);
|
||||
|
Loading…
Reference in New Issue
Block a user