Re: legitimacy of using PG_TRY , PG_CATCH , PG_END_TRY in C function

From: Andres Freund <andres(at)anarazel(dot)de>
To: Craig Ringer <craig(at)2ndquadrant(dot)com>
Cc: John Lumby <johnlumby(at)hotmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: legitimacy of using PG_TRY , PG_CATCH , PG_END_TRY in C function
Date: 2017-10-23 08:22:17
Message-ID: 20171023082217.vnawqw2hw2elwzjj@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2017-10-23 16:16:10 +0800, Craig Ringer wrote:
> On 23 October 2017 at 08:30, John Lumby <johnlumby(at)hotmail(dot)com> wrote:
>
> > All works but not perfectly -- at COMMIT, resource_owner issues
> > relcache reference leak messages about relation scans not closed
> > and also about snapshot still active. I guess that the CREATE has
> > switched resource_owner and pushed a snapshot, but I did not
> > debug in detail.
>
> A lot more work is required than what's done pg PG_CATCH to return to
> a queryable state. I've been down this path myself, and it's not fun.
>
> Take a look at all the extra work done on the error handling path in
> PostgresMain.

That seems quite misleading - that's *not* what needs to be done
to catch an error inside a function. See Tom's response.

> At some point I'd really like to expose that in a more general way so
> it can be used from background workers. Right now AFAICS most
> background workers have to cope with errors with a proc_exit(1) and
> getting restarted to try again. Not ideal.

I agree that generalizing wouldn't be bad, but there's absolutely
nothing preventing you from handling errors in bgworkers without
restarting today.

Greetings,

Andres Freund

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2017-10-23 08:27:43 Re: legitimacy of using PG_TRY , PG_CATCH , PG_END_TRY in C function
Previous Message Craig Ringer 2017-10-23 08:20:14 Re: legitimacy of using PG_TRY , PG_CATCH , PG_END_TRY in C function