| From: | Hannu Krosing <hannuk(at)google(dot)com> |
|---|---|
| To: | Ayush Vatsa <ayushvatsa1810(at)gmail(dot)com> |
| Cc: | Rahila Syed <rahilasyed90(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: Clarification on when _PG_init() is invoked for extensions |
| Date: | 2025-11-20 21:33:00 |
| Message-ID: | CAMT0RQTqxY2FSOjVjPzdAG5mxfrp3Xx8o364rpvd8c085uB4=g@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
You probably can do the LOAD in the GUC callback functions and then set
that GUC only for specific databases using ALTER DATABASE SET
<my-extension-loading-guc>=true;
On Thu, Nov 20, 2025 at 6:53 PM Ayush Vatsa <ayushvatsa1810(at)gmail(dot)com>
wrote:
> Hi,
>
> CREATE extension does not automatically load or ensure that _PG_init() is
>> run.
>> It mainly runs the .sql script in your extension.
>>
> Thanks for the clarification. However, in my testing, _PG_init() did run
> when I executed
> CREATE EXTENSION. I suspect this might be happening because the SQL
> script defines
> C functions using MODULE_PATHNAME, which triggers the library load.
> In a new session, _PG_init() seems to run again when any of those C
> functions are executed.
>
> *My use case:*
> My use case is that I’m building an experimental extension that will be
> installed only in a few
> databases. I want the hooks initialized by this extension to apply only to
> those specific
> databases, while all other databases should continue with the default
> PostgreSQL behavior.
>
> Thank you,
> Ayush
>
>>
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Nathan Bossart | 2025-11-20 21:46:42 | Re: vacuumdb: add --dry-run |
| Previous Message | Bruce Momjian | 2025-11-20 21:26:06 | Re: 10% drop in code line count in PG 17 |