BackgroundWorkerInitializeConnection(NULL, ...) doesn't work

Поиск
Список
Период
Сортировка
От Andrew Tipton
Тема BackgroundWorkerInitializeConnection(NULL, ...) doesn't work
Дата
Msg-id CA+M2pVU4GoHW2wwvE1jd32pYKYwXUpEuT=s1Ji7YAgnLFFARzA@mail.gmail.com
обсуждение исходный текст
Ответы Re: BackgroundWorkerInitializeConnection(NULL, ...) doesn't work
Re: BackgroundWorkerInitializeConnection(NULL, ...) doesn't work
Список pgsql-hackers
The documentation for 9.4 says, in the "Background Worker Processes" section:

Once running, the process can connect to a database by calling BackgroundWorkerInitializeConnection(char *dbname, char *username). This allows the process to run transactions and queries using the SPI interface. If dbname is NULL, the session is not connected to any particular database, but shared catalogs can be accessed. If username is NULL, the process will run as the superuser created during initdb.

However, should one attempt to pass NULL for the dbname parameter, the process will die with:

FATAL: database 0 does not exist

BackgroundWorkerInitializeConnection() is essentially just a wrapper around InitPostgres(), passing it the supplied dbname and username.  (And passing InvalidOid for the dboid parameter.)  When InitPostgres() finds that dbname is null, it falls back on dboid.  GetDatabaseTupleByOid() returns NULL when given InvalidOid, resulting in the aforementioned elog(FATAL).

Based on my quick read through InitPostgres() and postinit.c, it's not even clear that there's a way to access the shared catalogs without connecting to a specific database.  Certainly the rest of the code in InitPostgres expects MyDatabaseId to be set to something useful.


Regards,
Andrew Tipton

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

Предыдущее
От: Tatsuo Ishii
Дата:
Сообщение: Re: killing pg_dump leaves backend process
Следующее
От: Tom Lane
Дата:
Сообщение: Re: proposal: lob conversion functionality