Skip to content

Commit 3e0ae46

Browse files
committed
Move SLRU_PAGES_PER_SEGMENT to pg_config_manual.h
It seems plausible that someone might want to experiment with different values. The pressing reason though is that I'm reviewing a patch that requires pg_upgrade to manipulate SLRU files. That patch needs to access SLRU_PAGES_PER_SEGMENT from pg_upgrade code, and slru.h, where SLRU_PAGES_PER_SEGMENT is currently defined, cannot be included from frontend code. Moving it to pg_config_manual.h makes it accessible. Now that it's a little more likely that someone might change SLRU_PAGES_PER_SEGMENT, add a cluster compatibility check for it. Bump catalog version because of the new field in the control file. Reviewed-by: Daniel Gustafsson <daniel@yesql.se> Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de> Discussion: https://www.postgresql.org/message-id/c7a4ea90-9f7b-4953-81be-b3fcb47db057@iki.fi
1 parent 3a872dd commit 3e0ae46

File tree

5 files changed

+24
-16
lines changed

5 files changed

+24
-16
lines changed

src/backend/access/transam/xlog.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4271,6 +4271,7 @@ WriteControlFile(void)
42714271

42724272
ControlFile->blcksz = BLCKSZ;
42734273
ControlFile->relseg_size = RELSEG_SIZE;
4274+
ControlFile->slru_pages_per_segment = SLRU_PAGES_PER_SEGMENT;
42744275
ControlFile->xlog_blcksz = XLOG_BLCKSZ;
42754276
ControlFile->xlog_seg_size = wal_segment_size;
42764277

@@ -4490,6 +4491,16 @@ ReadControlFile(void)
44904491
"RELSEG_SIZE", ControlFile->relseg_size,
44914492
"RELSEG_SIZE", RELSEG_SIZE),
44924493
errhint("It looks like you need to recompile or initdb.")));
4494+
if (ControlFile->slru_pages_per_segment != SLRU_PAGES_PER_SEGMENT)
4495+
ereport(FATAL,
4496+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
4497+
errmsg("database files are incompatible with server"),
4498+
/* translator: %s is a variable name and %d is its value */
4499+
errdetail("The database cluster was initialized with %s %d,"
4500+
" but the server was compiled with %s %d.",
4501+
"SLRU_PAGES_PER_SEGMENT", ControlFile->slru_pages_per_segment,
4502+
"SLRU_PAGES_PER_SEGMENT", SLRU_PAGES_PER_SEGMENT),
4503+
errhint("It looks like you need to recompile or initdb.")));
44934504
if (ControlFile->xlog_blcksz != XLOG_BLCKSZ)
44944505
ereport(FATAL,
44954506
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),

src/include/access/slru.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,6 @@
2323
*/
2424
#define SLRU_MAX_ALLOWED_BUFFERS ((1024 * 1024 * 1024) / BLCKSZ)
2525

26-
/*
27-
* Define SLRU segment size. A page is the same BLCKSZ as is used everywhere
28-
* else in Postgres. The segment size can be chosen somewhat arbitrarily;
29-
* we make it 32 pages by default, or 256Kb, i.e. 1M transactions for CLOG
30-
* or 64K transactions for SUBTRANS.
31-
*
32-
* Note: because TransactionIds are 32 bits and wrap around at 0xFFFFFFFF,
33-
* page numbering also wraps around at 0xFFFFFFFF/xxxx_XACTS_PER_PAGE (where
34-
* xxxx is CLOG or SUBTRANS, respectively), and segment numbering at
35-
* 0xFFFFFFFF/xxxx_XACTS_PER_PAGE/SLRU_PAGES_PER_SEGMENT. We need
36-
* take no explicit notice of that fact in slru.c, except when comparing
37-
* segment and page numbers in SimpleLruTruncate (see PagePrecedes()).
38-
*/
39-
#define SLRU_PAGES_PER_SEGMENT 32
40-
4126
/*
4227
* Page status codes. Note that these do not include the "dirty" bit.
4328
* page_dirty can be true only in the VALID or WRITE_IN_PROGRESS states;

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
*/
5858

5959
/* yyyymmddN */
60-
#define CATALOG_VERSION_NO 202511071
60+
#define CATALOG_VERSION_NO 202511101
6161

6262
#endif

src/include/catalog/pg_control.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ typedef struct ControlFileData
207207
uint32 blcksz; /* data block size for this DB */
208208
uint32 relseg_size; /* blocks per segment of large relation */
209209

210+
uint32 slru_pages_per_segment; /* size of each SLRU segment */
211+
210212
uint32 xlog_blcksz; /* block size within WAL files */
211213
uint32 xlog_seg_size; /* size of each WAL segment */
212214

src/include/pg_config_manual.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
1919
*/
2020
#define DEFAULT_XLOG_SEG_SIZE (16*1024*1024)
2121

22+
/*
23+
* SLRU segment size. A page is the same BLCKSZ as is used everywhere else in
24+
* Postgres. The segment size can be chosen somewhat arbitrarily; we make it
25+
* 32 pages by default, or 256Kb, i.e. 1M transactions for CLOG or 64K
26+
* transactions for SUBTRANS.
27+
*
28+
* Changing this requires an initdb.
29+
*/
30+
#define SLRU_PAGES_PER_SEGMENT 32
31+
2232
/*
2333
* Maximum length for identifiers (e.g. table names, column names,
2434
* function names). Names actually are limited to one fewer byte than this,

0 commit comments

Comments
 (0)