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

Commit7413caa

Browse files
committed
Avoid leaking memory during large-scale REASSIGN OWNED BY operations.
The various ALTER OWNER routines tend to leak memory inCurrentMemoryContext. That's not a problem when they're only calledonce per command; but in this usage where we might be touching manyobjects, it can amount to a serious memory leak. Fix that by runningeach call in a short-lived context.(DROP OWNED BY likely has a similar issue, except that you'll probablyrun out of lock table space before noticing. REASSIGN is worth fixingsince for most non-table object types, it won't take any lock.)Back-patch to all supported branches. Unfortunately, in the backbranches this helps to only a limited extent, since the sinval messagequeue bloats quite a lot in this usage before commit3aafc03,consuming memory more or less comparable to what's actually leaked.Still, it's clearly a leak with a simple fix, so we might as well fix it.Justin Pryzby, per report from Guillaume LelargeDiscussion:https://postgr.es/m/CAECtzeW2DAoioEGBRjR=CzHP6TdL=yosGku8qZxfX9hhtrBB0Q@mail.gmail.com
1 parent64e8456 commit7413caa

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

‎src/backend/catalog/pg_shdepend.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include"storage/lmgr.h"
6666
#include"utils/acl.h"
6767
#include"utils/fmgroids.h"
68+
#include"utils/memutils.h"
6869
#include"utils/syscache.h"
6970

7071
typedefenum
@@ -1508,6 +1509,8 @@ shdepReassignOwned(List *roleids, Oid newrole)
15081509
while ((tuple=systable_getnext(scan))!=NULL)
15091510
{
15101511
Form_pg_shdependsdepForm= (Form_pg_shdepend)GETSTRUCT(tuple);
1512+
MemoryContextcxt,
1513+
oldcxt;
15111514

15121515
/*
15131516
* We only operate on shared objects and objects in the current
@@ -1525,6 +1528,18 @@ shdepReassignOwned(List *roleids, Oid newrole)
15251528
if (sdepForm->deptype!=SHARED_DEPENDENCY_OWNER)
15261529
continue;
15271530

1531+
/*
1532+
* The various ALTER OWNER routines tend to leak memory in
1533+
* CurrentMemoryContext. That's not a problem when they're only
1534+
* called once per command; but in this usage where we might be
1535+
* touching many objects, it can amount to a serious memory leak.
1536+
* Fix that by running each call in a short-lived context.
1537+
*/
1538+
cxt=AllocSetContextCreate(CurrentMemoryContext,
1539+
"shdepReassignOwned",
1540+
ALLOCSET_DEFAULT_SIZES);
1541+
oldcxt=MemoryContextSwitchTo(cxt);
1542+
15281543
/* Issue the appropriate ALTER OWNER call */
15291544
switch (sdepForm->classid)
15301545
{
@@ -1613,6 +1628,11 @@ shdepReassignOwned(List *roleids, Oid newrole)
16131628
elog(ERROR,"unexpected classid %u",sdepForm->classid);
16141629
break;
16151630
}
1631+
1632+
/* Clean up */
1633+
MemoryContextSwitchTo(oldcxt);
1634+
MemoryContextDelete(cxt);
1635+
16161636
/* Make sure the next iteration will see my changes */
16171637
CommandCounterIncrement();
16181638
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp