Skip site navigation (1) Skip section navigation (2)

Re: BUG #5066: plperl issues with perl_destruct() and ENDblocks

From: Tim Bunce <Tim(dot)Bunce(at)pobox(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Tim Bunce <Tim(dot)Bunce(at)pobox(dot)com>,pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #5066: plperl issues with perl_destruct() and ENDblocks
Date: 2009-09-20 20:45:14
Message-ID: 20090920204514.GC89676@timac.local (view raw, whole thread or download thread mbox)
Lists: pgsql-bugs
On Sat, Sep 19, 2009 at 11:43:26PM -0400, Tom Lane wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> > On Sat, Sep 19, 2009 at 3:53 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> >> "Tim Bunce" <Tim(dot)Bunce(at)pobox(dot)com> writes:
> >>> The plperl implementation doesn't call perl_destruct() during server
> >>> shutdown.
> >> 
> >> Who cares? The process is going away anyway.
> > END {} blocks can execute arbitrary code.  Perl users will expect them
> > to be executed.
> [ shrug... ]  As a database geek I find the lack of guarantees about
> that to be entirely unsatisfying.  What exactly are you going to put
> in that block?  If it's actually important, are you going to trust
> a mechanism that doesn't have any crash safeness?

Can you expand on what you mean by 'guarantees' and 'crash safeness'?

I my particular case I'm trying to enable Devel::NYTProf, the perl
source code performance profiler, to profile PL/Perl code.

NYTProf uses an END block to finish up the profile and write final
details to the data file.  One of the first problems I ran into was that
Postgres was executing the END block before the first plperl sub was
even executed. Very counter intuitive. Since NYTProf is implemented in C
(XS) I've worked around that problem by adding an option to enable

But because postgres doesn't call perl_destruct() the problem has just
moved from END blocks being called too early to END blocks not being
called at all. The effect is that the profile data file is unterminated
and so corrupt and unusable.

To finish the profiling users currently have to execute a SQL statement
to trigger a plperl sub that calls an NYTProf sub that finializes the
profile.  Ideally I'd like users to be able to finish the profiling
cleanly with a shutdown (to then restart with profiling disabled).

Calling perl_destruct() during shutdown would fix that.


p.s. As a random data point, google code search finds about 7000
perl modules containing an END block:

In response to


pgsql-bugs by date

Next:From: ThibautDate: 2009-09-20 23:08:32
Subject: erreur postgresql
Previous:From: Craig RingerDate: 2009-09-20 20:09:38
Subject: Re: BUG #5069: Segfault

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group