diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2006-11-23 01:14:59 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2006-11-23 01:14:59 +0000 |
commit | 395249ecbeaaf2f2cea11b0ce128fd98c702dbde (patch) | |
tree | d33fd1c7ead48187022c32796d06fcbecc48c04c /src/backend/utils/mmgr/portalmem.c | |
parent | 2a55984162985c012ea9e26d20e88f2568d995d2 (diff) |
Several changes to reduce the probability of running out of memory during
AbortTransaction, which would lead to recursion and eventual PANIC exit
as illustrated in recent report from Jeff Davis. First, in xact.c create
a special dedicated memory context for AbortTransaction to run in. This
solves the problem as long as AbortTransaction doesn't need more than 32K
(or whatever other size we create the context with). But in corner cases
it might. Second, in trigger.c arrange to keep pending after-trigger event
records in separate contexts that can be freed near the beginning of
AbortTransaction, rather than having them persist until CleanupTransaction
as before. Third, in portalmem.c arrange to free executor state data
earlier as well. These two changes should result in backing off the
out-of-memory condition before AbortTransaction needs any significant
amount of memory, at least in typical cases such as memory overrun due
to too many trigger events or too big an executor hash table. And all
the same for subtransaction abort too, of course.
Diffstat (limited to 'src/backend/utils/mmgr/portalmem.c')
-rw-r--r-- | src/backend/utils/mmgr/portalmem.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/backend/utils/mmgr/portalmem.c b/src/backend/utils/mmgr/portalmem.c index 7fabe243ace..4f8cba9ba5a 100644 --- a/src/backend/utils/mmgr/portalmem.c +++ b/src/backend/utils/mmgr/portalmem.c @@ -12,7 +12,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.96 2006/10/04 00:30:04 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.97 2006/11/23 01:14:59 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -586,7 +586,7 @@ AtCommit_Portals(void) * Abort processing for portals. * * At this point we reset "active" status and run the cleanup hook if - * present, but we can't release memory until the cleanup call. + * present, but we can't release the portal's memory until the cleanup call. * * The reason we need to reset active is so that we can replace the unnamed * portal, else we'll fail to execute ROLLBACK when it arrives. @@ -625,6 +625,14 @@ AtAbort_Portals(void) * PortalDrop. */ portal->resowner = NULL; + + /* + * Although we can't delete the portal data structure proper, we can + * release any memory in subsidiary contexts, such as executor state. + * The cleanup hook was the last thing that might have needed data + * there. + */ + MemoryContextDeleteChildren(PortalGetHeapMemory(portal)); } } @@ -756,6 +764,14 @@ AtSubAbort_Portals(SubTransactionId mySubid, * run PortalDrop. */ portal->resowner = NULL; + + /* + * Although we can't delete the portal data structure proper, we + * can release any memory in subsidiary contexts, such as executor + * state. The cleanup hook was the last thing that might have + * needed data there. + */ + MemoryContextDeleteChildren(PortalGetHeapMemory(portal)); } } } |