Re: get_database_name() from background worker - Mailing list pgsql-hackers

From Craig Ringer
Subject Re: get_database_name() from background worker
Date
Msg-id CAMsr+YHuDcV1VvGGSudDwQqs6KRyXWuhLrm04=0a3a6WLh84Xw@mail.gmail.com
Whole thread Raw
In response to get_database_name() from background worker  (Koichi Suzuki <koichi@2ndquadrant.com>)
List pgsql-hackers
On Wed, 11 Dec 2019 at 14:38, Koichi Suzuki <koichi@2ndquadrant.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

pgsql-hackers by date:

Previous
From: "tsunakawa.takay@fujitsu.com"
Date:
Subject: RE: get_database_name() from background worker
Next
From: Craig Ringer
Date:
Subject: Re: Session WAL activity