Parameter · Client Connection Defaults / Shared Library Preloading
session_preload_libraries
Lists shared libraries to preload into each backend.
- Default:
'' (empty) - Type: string
- Applies: Session (superuser)
In plain words
A list of libraries every new connection loads when it starts. It is the easy way to turn on a module like auto_explain for some users or databases without restarting the server.
For DBAs and operators
Loaded at backend start, after authentication. Changing it requires no restart, but only new sessions are affected; a SET inside an existing session does nothing. Only superusers or roles granted SET can change it. If a library is missing, the connection attempt fails, so test with a new session before logging out of your only superuser connection.
Typical uses:
ALTER DATABASE app SET session_preload_libraries = 'auto_explain';
ALTER ROLE reporting SET session_preload_libraries = 'auto_explain';
Libraries that allocate shared memory or start background workers (pg_stat_statements, pg_cron, pg_prewarm autoprewarm) cannot work this way; they must be in shared_preload_libraries. Loading at session start costs a little connection time, which matters with very short-lived connections.
How to change it
A superuser (or a role granted SET) can change it per session with SET.
See it in context
Related parameters
shared_preload_libraries local_preload_libraries dynamic_library_path