Re: get_database_name() from background worker

From: Craig Ringer <craig(at)2ndquadrant(dot)com>
To: Koichi Suzuki <koichi(at)2ndquadrant(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: get_database_name() from background worker
Date: 2019-12-12 01:20:29
Message-ID: CAMsr+YHuDcV1VvGGSudDwQqs6KRyXWuhLrm04=0a3a6WLh84Xw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, 11 Dec 2019 at 14:38, Koichi Suzuki <koichi(at)2ndquadrant(dot)com> wrote:

> Hello PG hackers;
>
> I'm writing an extension running on background workers and found
> get_database_name() causes SEGV and found internally resource owner was wet
> to NULL. Could anybody let me know how it happens and how I can use this
> function. Argument to get_database_name() looks correct.
>
>
I think the main question is answered; if the advice given does not help
please supply your code and a backtrace from the crash obtained from a core
file.

However, this reminds me of something. I'd like to make our
syscache/relcache/catcache and all snapshot access functions
Assert(IsTransactionState()); directly or at key locations. That'd make
these mistakes much more obvious - and as bgworkers become a more popular
way to write code for PostgreSQL that's going to be important.

Similarly, it might make sense to assert that we have a valid snapshot in
the SPI, which we don't presently do for read-only SPI calls. I recall that
one biting me repeatedly when I was learning this stuff.

--
Craig Ringer http://www.2ndQuadrant.com/
2ndQuadrant - PostgreSQL Solutions for the Enterprise

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Craig Ringer 2019-12-12 01:31:22 Re: Session WAL activity
Previous Message tsunakawa.takay@fujitsu.com 2019-12-12 01:04:28 RE: get_database_name() from background worker