The local_preload_libraries post ended by telling you to use session_preload_libraries instead. That advice stands. This post is the fine print, and there is more of it than you would expect for a parameter whose entire job is to call dlopen() on somebody’s behalf.

The default is empty. The context is superuser, which since PostgreSQL 15 also means any role that has been granted SET on the parameter. The value is a comma-separated list of library files, and each new client session loads them once: after authentication, after the role and database settings have been applied, before the first query. That is the only time the value is read. SET session_preload_libraries = 'auto_explain' in a live session succeeds, SHOW reports the new value, and nothing has been loaded. No restart is needed at any point, which is why Peter Eisentraut added the parameter in 9.4: shared_preload_libraries wanted a restart, local_preload_libraries wanted a curated directory, and what people wanted was auto_explain.

It exists for modules that are nothing but hooks. auto_explain, pg_hint_plan and pg_overexplain (new in 18) have no SQL functions, so no query will ever cause the server to load them on demand. pg_plan_advice (new in 19) is in the same position unless pg_stash_advice loads it for you. Somebody has to say LOAD, and LOAD is superuser-only for anything outside $libdir/plugins. This parameter says it for them, and because it is an ordinary GUC, it can be scoped:

1ALTER ROLE reporting SET session_preload_libraries = 'auto_explain';
2ALTER ROLE reporting SET auto_explain.log_min_duration = '5s';

Every new session for reporting logs the plan of anything that runs longer than five seconds, and no other role is involved. On 18 and later, SELECT * FROM pg_get_loaded_modules() shows a session what it got. (The role cannot SHOW session_preload_libraries to find out; the value is visible only to superusers and members of pg_read_all_settings.)

The price is one dlopen() per library per connection. For the small hook modules it came to a few tenths of a millisecond on a 2.2 ms connection, which is at the edge of what I could measure (19.0, local socket, a two-core test machine). For PostGIS, whose postgis-3.so depends, directly or not, on fifty other shared objects, it was 4 ms: connections went from 2.2 ms to 6.2 ms whether or not the session ever saw a geometry. Leave it out, and the same 4 ms lands on the first PostGIS call in each session. Put it in shared_preload_libraries, and connections were back within noise of the baseline, because the postmaster loads it once and every backend inherits the mapping (except on Windows, where each backend loads the preload libraries again). The manual says there is “no large performance advantage” to preloading per session, and the numbers agree: the parameter moves the cost to connection time and that is all. Behind a pooler that is a fair trade, since connections are opened rarely and otherwise the first query on each new server connection pays. For anything that connects per request it is a tax. A library that every session uses belongs in shared_preload_libraries, restart and all.

Loading here is also no guarantee of working here. pg_stat_statements loads without complaint and then does nothing, because it needs shared memory that only the postmaster can set aside; you find out when you query the view and it tells you it must be loaded via shared_preload_libraries. auth_delay loads after the authentication it was meant to slow down (with a 2000 ms delay configured, a failed login came back in 0.01 s). And pgAudit checks how it is being loaded and raises an error, which at that point in backend startup is fatal:

1FATAL: pgaudit must be loaded via shared_preload_libraries

That is a login failure for every session the setting applies to, caused by a library that exists and is spelled correctly.

The reload that takes the logins away

Nothing validates the value when it is set. ALTER SYSTEM, ALTER ROLE and ALTER DATABASE accept any string, and the first process to discover whether the library can be opened is the next backend that tries to start. If it cannot, that backend exits with a FATAL and the client never gets a session. A patch to print a warning at SET time was proposed in 2021 and closed in 2024 without being committed. Refusing unknown names outright was never likely; Tom Lane’s objection in that thread was that insisting the library exist first would break dump/restore and pg_upgrade scenarios. Hold that thought.

You do not need a typo to get there. This is correct in postgresql.conf:

1session_preload_libraries = 'auto_explain, pg_hint_plan'

This is the same string given to ALTER SYSTEM, followed by a reload and a new connection:

1=# ALTER SYSTEM SET session_preload_libraries = 'auto_explain, pg_hint_plan';
2
3$ grep session_preload postgresql.auto.conf
4session_preload_libraries = '"auto_explain, pg_hint_plan"'
5
6$ psql
7psql: error: connection to server on socket "/tmp/.s.PGSQL.5419" failed: FATAL: could not access file "auto_explain, pg_hint_plan": No such file or directory

In SQL, one quoted literal is one list element, so the server is now looking for a single file with a comma in its name. ALTER ROLE and ALTER DATABASE behave the same way. The forms that work are = auto_explain, pg_hint_plan and = 'auto_explain', 'pg_hint_plan'.

The outage is quieter than that error suggests, because of everything that keeps working. Sessions that are already connected are untouched. Autovacuum workers and background workers never read the parameter. Neither do walsenders (since 15), so standbys keep streaming, a restarted standby reconnects, and pg_basebackup still runs. pg_isready prints accepting connections and exits 0, because any reply other than “cannot connect now” counts as up. And an application behind PgBouncer carries on with the server connections it already holds until they age out; server_lifetime defaults to an hour. With the lifetime turned down to six seconds, my queries through the pooler succeeded for six seconds after the reload and then failed: the first with the server’s own could not access file, the rest with the pooler’s server login has been failing, cached error. So: a configuration change at 2:00, healthy replication, a green health check, and an outage that arrives one pool slot at a time at some point before 3:00.

In postgresql.conf, where the whole string is parsed as the list, the opposite mistake fails in the opposite direction. A doubled comma, a trailing comma or an unbalanced quote makes the list unparseable, and that is not an error. The backend writes invalid list syntax in parameter "session_preload_libraries" to the log at LOG level, loads nothing from the list (the valid names included), and carries on. A misspelled name locks people out. Misplaced punctuation turns the whole setting off, and the only place that says so is the server log. (Make the same slip inside a quoted literal in ALTER SYSTEM or ALTER ROLE and it becomes part of the filename, which is the lockout again.)

Scope decides who is hit. Role settings outrank database settings, which outrank the configuration files, so a role with its own ALTER ROLE value sails through a broken global one, and a broken ALTER ROLE value locks out exactly one role. A broken ALTER DATABASE value gets everyone who connects to that database, superusers included.

A superuser can still get in, because connection options outrank all three:

1PGOPTIONS="-c session_preload_libraries=" psql -U postgres

From there it is ALTER SYSTEM RESET and a reload, or a RESET on the role or database. A role that is not a superuser gets permission denied to set parameter for trying. If there is no superuser login to be had and the bad value is in a file, delete the line (yes, from the file whose first line tells you not to edit it) and run pg_ctl reload, which needs no connection. Single-user mode helps only with the other kind: a standalone backend ignores ALTER ROLE and ALTER DATABASE settings, so it gets in past a bad one, but it reads the files and dies with the same FATAL unless you pass it the same -c.

pg_upgrade does not check

ALTER ROLE and ALTER DATABASE settings are rows in pg_db_role_setting, so they travel with pg_dumpall, with pg_dump --create, and through every pg_upgrade. The library files do not. pg_upgrade --check has a step named “Checking for presence of required libraries,” and what it examines is the libraries referenced by C-language functions. A library named only in this parameter is not among them.

I ran it both ways: 18.7 to 19.0 with pg_hint_plan missing from the new installation, and 16.15 to 18.7 with auto_explain missing. With the setting on a role, --check passes, the upgrade completes, and that role cannot log in to the new cluster. With the setting on a database, --check reports *Clusters are compatible*, and then the real run does this:

1Restoring global objects in the new cluster ok
2Restoring database schemas in the new cluster
3*failure*

The log it points you to ends with pg_restore failing to connect: FATAL: could not access file "pg_hint_plan": No such file or directory. It had created the database, restored the ALTER DATABASE ... SET, reconnected, and been refused by the setting it had just restored. The objection to requiring the library up front was that it would break restores. Leaving the value unchecked broke this one anyway. The old cluster is unharmed, but this is past the point where pg_upgrade tells you a failure means running initdb on the new cluster again, in a maintenance window that --check approved. A pg_dumpall script fed to psql stops at the same \connect and leaves the database created and empty.

Before a major upgrade, run \drds in psql on the old cluster and install every library it names on the new side. On Red Hat-family packaging auto_explain ships in the separate contrib package, which is easy to leave off the list when no extension in any database depends on it.

Use it anyway. For a small diagnostic module scoped to a role it is the right tool, and it is the use the manual describes for it. But LOAD the exact name in a superuser session first; that catches both the misspelling and the pgAudit kind of refusal while you still have a session. Keep that session open through the reload, and connect once as the target role before you walk away. Do not hand out GRANT SET ON PARAMETER session_preload_libraries casually, since it gives a role the superuser’s LOAD for any library file the server can open. The selling point of this parameter is that it takes effect without a restart. So does the outage.