Re: Memory leak with CALL to Procedure with COMMIT. - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: Memory leak with CALL to Procedure with COMMIT.
Date
Msg-id 2532d5a4-c2c2-fe10-b49d-4a46d6f7e24a@2ndquadrant.com
Whole thread Raw
In response to Re: Memory leak with CALL to Procedure with COMMIT.  (Peter Eisentraut <peter.eisentraut@2ndquadrant.com>)
Responses Re: Memory leak with CALL to Procedure with COMMIT.
List pgsql-hackers
I think I've found a reasonable fix for this.

The problem arises with the combination of CALL with output parameters
and doing a COMMIT inside the procedure.  When a CALL has output
parameters, the portal uses the strategy PORTAL_UTIL_SELECT instead of
PORTAL_MULTI_QUERY.  Using PORTAL_UTIL_SELECT causes the portal's
snapshot to be registered with the current resource
owner (portal->holdSnapshot); see
9ee1cf04ab6bcefe03a11837b53f29ca9dc24c7a for the reason.

Normally, PortalDrop() unregisters the snapshot.  If not, then
ResourceOwnerRelease() will print a warning about a snapshot leak on
transaction commit.  A transaction commit normally drops all
portals (PreCommit_Portals()), except the active portal.  So in case of
the active portal, we need to manually release the snapshot to avoid the
warning.

PreCommit_Portals() already contains some code that deals specially with
the active portal versus resource owners, so it seems reasonable to add
there.

I think this problem could theoretically apply to any
multiple-transaction utility command.  For example, if we had a variant
of VACUUM that returned tuples, it would produce the same warning.
(This patch would fix that as well.)

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachment

pgsql-hackers by date:

Previous
From: Jim Finnerty
Date:
Subject: Re: Removing useless DISTINCT clauses
Next
From: Surafel Temesgen
Date:
Subject: Re: Conflict handling for COPY FROM