How do I use shared_preload_libraries in my PostgreSQL Database?

Some PostgreSQL extensions need to be added to shared_preload_libraries before they can be used in your Database. pg_stat_statements is one commonly-used library with this property. You can use ALTER SYSTEM SET in your Database to make this change - for example using libraries foo and bar:

ALTER SYSTEM SET shared_preload_libraries = foo,bar;

Attempting to run CREATE EXTENSION foo before adding foo to shared_preload_libraries will return the following: ERROR: foo is not in shared_preload_libraries.

Changes made with ALTER SYSTEM SET will persist through aptible db:restart operations.

Warning

When specifying more than one library in shared_preload_libraries, the values must be unquoted or quoted individually:

-- These are valid options:
ALTER SYSTEM SET shared_preload_libraries = foo,bar;
ALTER SYSTEM SET shared_preload_libraries = 'foo','bar';
-- This will result in an error:
ALTER SYSTEM SET shared_preload_libraries = 'foo,bar';

This is because PostgreSQL supports library names containing commas, so it interprets the final line as a single library ‘“foo,bar”’.