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

Commitbabe545

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 parent3d858af commitbabe545

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
@@ -1497,6 +1498,8 @@ shdepReassignOwned(List *roleids, Oid newrole)
14971498
while ((tuple=systable_getnext(scan))!=NULL)
14981499
{
14991500
Form_pg_shdependsdepForm= (Form_pg_shdepend)GETSTRUCT(tuple);
1501+
MemoryContextcxt,
1502+
oldcxt;
15001503

15011504
/*
15021505
* We only operate on shared objects and objects in the current
@@ -1510,6 +1513,18 @@ shdepReassignOwned(List *roleids, Oid newrole)
15101513
if (sdepForm->deptype!=SHARED_DEPENDENCY_OWNER)
15111514
continue;
15121515

1516+
/*
1517+
* The various ALTER OWNER routines tend to leak memory in
1518+
* CurrentMemoryContext. That's not a problem when they're only
1519+
* called once per command; but in this usage where we might be
1520+
* touching many objects, it can amount to a serious memory leak.
1521+
* Fix that by running each call in a short-lived context.
1522+
*/
1523+
cxt=AllocSetContextCreate(CurrentMemoryContext,
1524+
"shdepReassignOwned",
1525+
ALLOCSET_DEFAULT_SIZES);
1526+
oldcxt=MemoryContextSwitchTo(cxt);
1527+
15131528
/* Issue the appropriate ALTER OWNER call */
15141529
switch (sdepForm->classid)
15151530
{
@@ -1598,6 +1613,11 @@ shdepReassignOwned(List *roleids, Oid newrole)
15981613
elog(ERROR,"unexpected classid %u",sdepForm->classid);
15991614
break;
16001615
}
1616+
1617+
/* Clean up */
1618+
MemoryContextSwitchTo(oldcxt);
1619+
MemoryContextDelete(cxt);
1620+
16011621
/* Make sure the next iteration will see my changes */
16021622
CommandCounterIncrement();
16031623
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp