Skip to content

Commit da5ffbc

Browse files
melanieplagemanCommitfest Bot
authored and
Commitfest Bot
committed
Fix autoprewarm neglect of tablespaces
While prewarming blocks from a dump file, autoprewarm_database_main() mistakenly ignored tablespace when detecting the beginning of the next relation to prewarm. Because RelFileNumbers are only unique within a tablespace, autoprewarm could miss prewarming blocks from a relation with the same RelFileNumber in a different tablespace. Though this situation is likely rare in practice, it's best to make the code correct. Do so by explicitly checking for the RelFileNumber when detecting a new relation. Reported-by: Heikki Linnakangas <[email protected]> Discussion: https://postgr.es/m/97c36982-603b-494a-95f4-aaf2a12ac27e%40iki.fi
1 parent dbd437e commit da5ffbc

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

contrib/pg_prewarm/autoprewarm.c

+12-4
Original file line numberDiff line numberDiff line change
@@ -472,10 +472,15 @@ autoprewarm_database_main(Datum main_arg)
472472

473473
/*
474474
* As soon as we encounter a block of a new relation, close the old
475-
* relation. Note that rel will be NULL if try_relation_open failed
476-
* previously; in that case, there is nothing to close.
475+
* relation. RelFileNumbers are only guaranteed to be unique within a
476+
* tablespace, so check that too.
477+
*
478+
* Note that rel will be NULL if try_relation_open failed previously;
479+
* in that case, there is nothing to close.
477480
*/
478-
if (old_blk != NULL && old_blk->filenumber != blk->filenumber &&
481+
if (old_blk != NULL &&
482+
(old_blk->tablespace != blk->tablespace ||
483+
old_blk->filenumber != blk->filenumber) &&
479484
rel != NULL)
480485
{
481486
relation_close(rel, AccessShareLock);
@@ -487,7 +492,9 @@ autoprewarm_database_main(Datum main_arg)
487492
* Try to open each new relation, but only once, when we first
488493
* encounter it. If it's been dropped, skip the associated blocks.
489494
*/
490-
if (old_blk == NULL || old_blk->filenumber != blk->filenumber)
495+
if (old_blk == NULL ||
496+
old_blk->tablespace != blk->tablespace ||
497+
old_blk->filenumber != blk->filenumber)
491498
{
492499
Oid reloid;
493500

@@ -508,6 +515,7 @@ autoprewarm_database_main(Datum main_arg)
508515

509516
/* Once per fork, check for fork existence and size. */
510517
if (old_blk == NULL ||
518+
old_blk->tablespace != blk->tablespace ||
511519
old_blk->filenumber != blk->filenumber ||
512520
old_blk->forknum != blk->forknum)
513521
{

0 commit comments

Comments
 (0)