Re: [HACKERS] Vacuum analyze bug CAUGHT

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michael Simms <grim(at)argh(dot)demon(dot)co(dot)uk>, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] Vacuum analyze bug CAUGHT
Date: 1999-09-09 16:36:59
Message-ID: 8284.936895019@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I wrote:
> appears to be the same bug I alluded to before: memory allocation isn't
> cleaned up properly if elog(ERROR) is executed outside a transaction.
> I know how to fix this, and will do so before 6.5.2, but fixing it will
> just prevent a coredump after an error has already occurred.

Here is the patch to fix that problem; line numbers are for current,
but it should apply to 6.5.1 with small offsets.

Also: have you applied the vc_abort patch discussed a month ago (see
my post in pgsql-patches, 11 Aug)? If not, that could well be the
source of your troubles. You might want to just grab the 6.5.2-beta
tarball and apply this patch, or even better pull the current state
of the REL6_5_PATCHES branch from the CVS server.

regards, tom lane

*** src/include/utils/portal.h.orig Thu Jul 15 21:11:26 1999
--- src/include/utils/portal.h Thu Sep 9 11:59:00 1999
***************
*** 75,80 ****
--- 75,81 ----
extern void PortalDestroy(Portal *portalP);
extern void StartPortalAllocMode(AllocMode mode, Size limit);
extern void EndPortalAllocMode(void);
+ extern void PortalResetHeapMemory(Portal portal);
extern PortalVariableMemory PortalGetVariableMemory(Portal portal);
extern PortalHeapMemory PortalGetHeapMemory(Portal portal);

*** src/backend/utils/mmgr/portalmem.c.orig Sat Jul 17 23:20:03 1999
--- src/backend/utils/mmgr/portalmem.c Thu Sep 9 11:59:36 1999
***************
*** 83,89 ****
static void CollectNamedPortals(Portal *portalP, int destroy);
static Portal PortalHeapMemoryGetPortal(PortalHeapMemory context);
static PortalVariableMemory PortalHeapMemoryGetVariableMemory(PortalHeapMemory context);
- static void PortalResetHeapMemory(Portal portal);
static Portal PortalVariableMemoryGetPortal(PortalVariableMemory context);

/* ----------------
--- 83,88 ----
***************
*** 838,844 ****
* BadArg if mode is invalid.
* ----------------
*/
! static void
PortalResetHeapMemory(Portal portal)
{
PortalHeapMemory context;
--- 837,843 ----
* BadArg if mode is invalid.
* ----------------
*/
! void
PortalResetHeapMemory(Portal portal)
{
PortalHeapMemory context;
*** src/backend/access/transam/xact.c.orig Sun Sep 5 13:12:34 1999
--- src/backend/access/transam/xact.c Thu Sep 9 12:00:23 1999
***************
*** 694,712 ****
AtCommit_Memory()
{
Portal portal;
- MemoryContext portalContext;

/* ----------------
! * Release memory in the blank portal.
! * Since EndPortalAllocMode implicitly works on the current context,
! * first make real sure that the blank portal is the selected context.
! * (This is probably not necessary, but seems like a good idea...)
* ----------------
*/
portal = GetPortalByName(NULL);
! portalContext = (MemoryContext) PortalGetHeapMemory(portal);
! MemoryContextSwitchTo(portalContext);
! EndPortalAllocMode();

/* ----------------
* Now that we're "out" of a transaction, have the
--- 694,706 ----
AtCommit_Memory()
{
Portal portal;

/* ----------------
! * Release all heap memory in the blank portal.
* ----------------
*/
portal = GetPortalByName(NULL);
! PortalResetHeapMemory(portal);

/* ----------------
* Now that we're "out" of a transaction, have the
***************
*** 784,802 ****
AtAbort_Memory()
{
Portal portal;
- MemoryContext portalContext;

/* ----------------
! * Release memory in the blank portal.
! * Since EndPortalAllocMode implicitly works on the current context,
! * first make real sure that the blank portal is the selected context.
! * (This is ESSENTIAL in case we aborted from someplace where it wasn't.)
* ----------------
*/
portal = GetPortalByName(NULL);
! portalContext = (MemoryContext) PortalGetHeapMemory(portal);
! MemoryContextSwitchTo(portalContext);
! EndPortalAllocMode();

/* ----------------
* Now that we're "out" of a transaction, have the
--- 778,790 ----
AtAbort_Memory()
{
Portal portal;

/* ----------------
! * Release all heap memory in the blank portal.
* ----------------
*/
portal = GetPortalByName(NULL);
! PortalResetHeapMemory(portal);

/* ----------------
* Now that we're "out" of a transaction, have the

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 1999-09-09 16:49:25 Re: [HACKERS] PG_UPGRADE status
Previous Message Bruce Momjian 1999-09-09 16:26:15 Re: [HACKERS] PG_UPGRADE status?