Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0f92b23

Browse files
committed
Fix DROP DATABASE for databases with many ACLs
Commitc66a7d7 modified DROP DATABASE so that if interrupted, thedatabase is known to be in an invalid state and can only be dropped.This is done by setting a flag using an in-place update, so that it'snot lost in case of rollback.For databases with many ACLs, this may however fail like this: ERROR: wrong tuple lengthThis happens because with many ACLs, the pg_database.datacl attributegets TOASTed. The dropdb() code reads the tuple from the syscache, whichmeans it's detoasted. But the in-place update expects the tuple lengthto match the on-disk tuple.Fixed by reading the tuple from the catalog directly, not from syscache.Report and fix by Ayush Tiwari. Backpatch to 12. The DROP DATABASE fixwas backpatched to 11, but 11 is EOL at this point.Reported-by: Ayush TiwariAuthor: Ayush TiwariReviewed-by: Tomas VondraBackpatch-through: 12Discussion:https://postgr.es/m/CAJTYsWWNkCt+-UnMhg=BiCD3Mh8c2JdHLofPxsW3m2dkDFw8RA@mail.gmail.com
1 parentd426718 commit0f92b23

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

‎src/backend/commands/dbcommands.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,8 @@ dropdb(const char *dbname, bool missing_ok, bool force)
16501650
booldb_istemplate;
16511651
Relationpgdbrel;
16521652
HeapTupletup;
1653+
ScanKeyDatascankey;
1654+
SysScanDescscan;
16531655
Form_pg_databasedatform;
16541656
intnotherbackends;
16551657
intnpreparedxacts;
@@ -1787,7 +1789,18 @@ dropdb(const char *dbname, bool missing_ok, bool force)
17871789
*/
17881790
pgstat_drop_database(db_id);
17891791

1790-
tup=SearchSysCacheCopy1(DATABASEOID,ObjectIdGetDatum(db_id));
1792+
/*
1793+
* Update the database's pg_database tuple
1794+
*/
1795+
ScanKeyInit(&scankey,
1796+
Anum_pg_database_datname,
1797+
BTEqualStrategyNumber,F_NAMEEQ,
1798+
CStringGetDatum(dbname));
1799+
1800+
scan=systable_beginscan(pgdbrel,DatabaseNameIndexId, true,
1801+
NULL,1,&scankey);
1802+
1803+
tup=systable_getnext(scan);
17911804
if (!HeapTupleIsValid(tup))
17921805
elog(ERROR,"cache lookup failed for database %u",db_id);
17931806
datform= (Form_pg_database)GETSTRUCT(tup);
@@ -1813,6 +1826,8 @@ dropdb(const char *dbname, bool missing_ok, bool force)
18131826
*/
18141827
CatalogTupleDelete(pgdbrel,&tup->t_self);
18151828

1829+
systable_endscan(scan);
1830+
18161831
/*
18171832
* Drop db-specific replication slots.
18181833
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp