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

Commiteff027c

Browse files
committed
Add CheckTableNotInUse calls in DROP TABLE and DROP INDEX.
Recent releases had a check on rel->rd_refcnt in heap_drop_with_catalog,but failed to cover the possibility of pending trigger events at DROP time.(Before 8.4 we didn't even check the refcnt.) When the trigger events wereeventually fired, you'd get "could not open relation with OID nnn" errors,as in recent report from strk. Better to throw a suitable error when theDROP is attempted.Also add a similar check in DROP INDEX.Back-patch to all supported branches.
1 parentfe8f15d commiteff027c

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

‎src/backend/catalog/heap.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,14 +1603,10 @@ heap_drop_with_catalog(Oid relid)
16031603

16041604
/*
16051605
* There can no longer be anyone *else* touching the relation, but we
1606-
* might still have open queries or cursors in our own session.
1606+
* might still have open queries or cursors, or pending trigger events,
1607+
* in our own session.
16071608
*/
1608-
if (rel->rd_refcnt!=1)
1609-
ereport(ERROR,
1610-
(errcode(ERRCODE_OBJECT_IN_USE),
1611-
errmsg("cannot drop \"%s\" because "
1612-
"it is being used by active queries in this session",
1613-
RelationGetRelationName(rel))));
1609+
CheckTableNotInUse(rel,"DROP TABLE");
16141610

16151611
/*
16161612
* Delete pg_foreign_table tuple first.

‎src/backend/catalog/index.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,12 @@ index_drop(Oid indexId)
12981298

12991299
userIndexRelation=index_open(indexId,AccessExclusiveLock);
13001300

1301+
/*
1302+
* There can no longer be anyone *else* touching the index, but we
1303+
* might still have open queries using it in our own session.
1304+
*/
1305+
CheckTableNotInUse(userIndexRelation,"DROP INDEX");
1306+
13011307
/*
13021308
* Schedule physical removal of the files
13031309
*/

‎src/interfaces/ecpg/test/expected/sql-fetch.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@
138138
[NO_PID]: sqlca: code: 0, state: 00000
139139
[NO_PID]: ecpg_execute on line 53: using PQexec
140140
[NO_PID]: sqlca: code: 0, state: 00000
141-
[NO_PID]: ecpg_check_PQresult on line 53: bad response - ERROR: cannotdrop "my_table" because it is being used by active queries in this session
141+
[NO_PID]: ecpg_check_PQresult on line 53: bad response - ERROR: cannotDROP TABLE "my_table" because it is being used by active queries in this session
142142
[NO_PID]: sqlca: code: 0, state: 00000
143-
[NO_PID]: raising sqlstate 55006 (sqlcode -400): cannotdrop "my_table" because it is being used by active queries in this session on line 53
143+
[NO_PID]: raising sqlstate 55006 (sqlcode -400): cannotDROP TABLE "my_table" because it is being used by active queries in this session on line 53
144144
[NO_PID]: sqlca: code: -400, state: 55006
145-
SQL error: cannotdrop "my_table" because it is being used by active queries in this session on line 53
145+
SQL error: cannotDROP TABLE "my_table" because it is being used by active queries in this session on line 53
146146
[NO_PID]: ecpg_finish: connection regress1 closed
147147
[NO_PID]: sqlca: code: 0, state: 00000

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp