Skip to content

Commit 45a607d

Browse files
committed
Drop no-longer-needed buffers during ALTER DATABASE SET TABLESPACE.
The previous coding assumed that we could just let buffers for the database's old tablespace age out of the buffer arena naturally. The folly of that is exposed by bug #11867 from Marc Munro: the user could later move the database back to its original tablespace, after which any still-surviving buffers would match lookups again and appear to contain valid data. But they'd be missing any changes applied while the database was in the new tablespace. This has been broken since ALTER SET TABLESPACE was introduced, so back-patch to all supported branches.
1 parent 12a9d64 commit 45a607d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/backend/commands/dbcommands.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,23 @@ movedb(const char *dbname, const char *tblspcname)
11221122
*/
11231123
RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_FORCE | CHECKPOINT_WAIT);
11241124

1125+
/*
1126+
* Now drop all buffers holding data of the target database; they should
1127+
* no longer be dirty so DropDatabaseBuffers is safe.
1128+
*
1129+
* It might seem that we could just let these buffers age out of shared
1130+
* buffers naturally, since they should not get referenced anymore. The
1131+
* problem with that is that if the user later moves the database back to
1132+
* its original tablespace, any still-surviving buffers would appear to
1133+
* contain valid data again --- but they'd be missing any changes made in
1134+
* the database while it was in the new tablespace. In any case, freeing
1135+
* buffers that should never be used again seems worth the cycles.
1136+
*
1137+
* Note: it'd be sufficient to get rid of buffers matching db_id and
1138+
* src_tblspcoid, but bufmgr.c presently provides no API for that.
1139+
*/
1140+
DropDatabaseBuffers(db_id);
1141+
11251142
/*
11261143
* Check for existence of files in the target directory, i.e., objects of
11271144
* this database that are already in the target tablespace. We can't

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy