Re: get_database_name() from background worker

Поиск
Список
Период
Сортировка
От Michael Paquier
Тема Re: get_database_name() from background worker
Дата
Msg-id 20191211110645.GM72921@paquier.xyz
обсуждение исходный текст
Ответ на Re: get_database_name() from background worker  (Koichi Suzuki <koichi@2ndquadrant.com>)
Список pgsql-hackers
On Wed, Dec 11, 2019 at 05:17:00PM +0900, Koichi Suzuki wrote:
> Not using this extension, sorry.

I have no idea what you are trying to do, but get_database_name()
accesses the system cache, which means two things:
- The access needs to be done in the context of a transaction.  That's
a trick we use in a couple of places in core, see for example
IdentifySystem() in walsender.c which looks for the database name.  In
this case, you need to do the call in-between StartTransactionCommand
and CommitTransactionCommand, and you should make sure that the memory
context does not point to the one of the transaction to have an access
to the syscache data after committing the inner transaction used for
the lookup.
- Your background worker needs a database access, so bgw_flags needs
to be BGWORKER_SHMEM_ACCESS | BGWORKER_BACKEND_DATABASE_CONNECTION,
and also make sure to use BackgroundWorkerInitializeConnection at the
beginning of the main loop of your worker.

Hope that helps.
--
Michael

Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Amit Khandekar
Дата:
Сообщение: Re: logical decoding : exceeded maxAllocatedDescs for .spill files
Следующее
От: Michael Paquier
Дата:
Сообщение: Re: Start Walreceiver completely before shut down it on standbyserver.