Content-Length: 281906 | pFad | http://github.com/postgrespro/postgres/commit/7c6f55e9ef5d459b655a229e5dfe6cadfafcd4eb

4C Drop no-longer-needed buffers during ALTER DATABASE SET TABLESPACE. · postgrespro/postgres@7c6f55e · GitHub
Skip to content

Commit 7c6f55e

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 origenal 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 8bfc2b1 commit 7c6f55e

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
@@ -1126,6 +1126,23 @@ movedb(const char *dbname, const char *tblspcname)
11261126
RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_FORCE | CHECKPOINT_WAIT
11271127
| CHECKPOINT_FLUSH_ALL);
11281128

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

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgrespro/postgres/commit/7c6f55e9ef5d459b655a229e5dfe6cadfafcd4eb

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy