pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Process session_preload_libraries within InitPostgres's transact
2+ messages / 1 participants
[nested] [flat]

* pgsql: Process session_preload_libraries within InitPostgres's transact
@ 2022-07-25 14:27  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2022-07-25 14:27 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Process session_preload_libraries within InitPostgres's transaction.

Previously we did this after InitPostgres, at a somewhat randomly chosen
place within PostgresMain.  However, since commit a0ffa885e doing this
outside a transaction can cause a crash, if we need to check permissions
while replacing a placeholder GUC.  (Besides which, a preloaded library
could itself want to do database access within _PG_init.)

To avoid needing an additional transaction start/end in every session,
move the process_session_preload_libraries call to within InitPostgres's
transaction.  That requires teaching the code not to call it when
InitPostgres is called from somewhere other than PostgresMain, since
we don't want session_preload_libraries to affect background workers.
The most future-proof solution here seems to be to add an additional
flag parameter to InitPostgres; fortunately, we're not yet very worried
about API stability for v15.

Doing this also exposed the fact that we're currently honoring
session_preload_libraries in walsenders, even those not connected to
any database.  This seems, at minimum, a POLA violation: walsenders
are not interactive sessions.  Let's stop doing that.

(All these comments also apply to local_preload_libraries, of course.)

Per report from Gurjeet Singh (thanks also to Nathan Bossart and Kyotaro
Horiguchi for review).  Backpatch to v15 where a0ffa885e came in.

Discussion: https://postgr.es/m/CABwTF4VEpwTHhRQ+q5MiC5ucngN-whN-PdcKeufX7eLSoAfbZA@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/b35617de37870756bdb0e00ffc0a42441e56eefa

Modified Files
--------------
src/backend/bootstrap/bootstrap.c   |  2 +-
src/backend/postmaster/autovacuum.c |  7 +++---
src/backend/postmaster/postmaster.c | 12 +++++++--
src/backend/tcop/postgres.c         | 12 ++++-----
src/backend/utils/init/postinit.c   | 49 +++++++++++++++++++++++++++++--------
src/include/miscadmin.h             |  7 ++++--
6 files changed, 64 insertions(+), 25 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Process session_preload_libraries within InitPostgres's transact
@ 2022-07-25 14:27  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2022-07-25 14:27 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Process session_preload_libraries within InitPostgres's transaction.

Previously we did this after InitPostgres, at a somewhat randomly chosen
place within PostgresMain.  However, since commit a0ffa885e doing this
outside a transaction can cause a crash, if we need to check permissions
while replacing a placeholder GUC.  (Besides which, a preloaded library
could itself want to do database access within _PG_init.)

To avoid needing an additional transaction start/end in every session,
move the process_session_preload_libraries call to within InitPostgres's
transaction.  That requires teaching the code not to call it when
InitPostgres is called from somewhere other than PostgresMain, since
we don't want session_preload_libraries to affect background workers.
The most future-proof solution here seems to be to add an additional
flag parameter to InitPostgres; fortunately, we're not yet very worried
about API stability for v15.

Doing this also exposed the fact that we're currently honoring
session_preload_libraries in walsenders, even those not connected to
any database.  This seems, at minimum, a POLA violation: walsenders
are not interactive sessions.  Let's stop doing that.

(All these comments also apply to local_preload_libraries, of course.)

Per report from Gurjeet Singh (thanks also to Nathan Bossart and Kyotaro
Horiguchi for review).  Backpatch to v15 where a0ffa885e came in.

Discussion: https://postgr.es/m/CABwTF4VEpwTHhRQ+q5MiC5ucngN-whN-PdcKeufX7eLSoAfbZA@mail.gmail.com

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/31ed3cf746a61538876c66a778ec8a372a3b4ffb

Modified Files
--------------
src/backend/bootstrap/bootstrap.c   |  2 +-
src/backend/postmaster/autovacuum.c |  7 +++---
src/backend/postmaster/postmaster.c | 12 +++++++--
src/backend/tcop/postgres.c         | 12 ++++-----
src/backend/utils/init/postinit.c   | 49 +++++++++++++++++++++++++++++--------
src/include/miscadmin.h             |  7 ++++--
6 files changed, 64 insertions(+), 25 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2022-07-25 14:27 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-07-25 14:27 pgsql: Process session_preload_libraries within InitPostgres's transact Tom Lane <tgl@sss.pgh.pa.us>
2022-07-25 14:27 pgsql: Process session_preload_libraries within InitPostgres's transact Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox