3 months ago
Hello Railway team,
I need to enable the pg_stat_statements extension for query performance monitoring.
The extension is installed, but I'm getting this error:
"ERROR: pg_stat_statements must be loaded via shared_preload_libraries"
Could you please add pg_stat_statements to the shared_preload_libraries
configuration for my PostgreSQL instance?
Project: travelmaster-backend
Region: europe-west4
Thank you!
Attachments
5 Replies
3 months ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
3 months ago
This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.
Status changed to Open ray-chen • 3 months ago
3 months ago
The error you're encountering is a PostgreSQL requirement: pg_stat_statements must be loaded via shared_preload_libraries before PostgreSQL starts.
Solution:
You need to configure PostgreSQL to load pg_stat_statements in the shared_preload_libraries setting before the extension can be used. Here's how:
1. Run this SQL command to modify your PostgreSQL configuration:
ALTER SYSTEM SET shared_preload_libraries = 'pg_stat_statements';Then you can run:
SELECT pg_reload_conf();2. Restart your PostgreSQL deployment by clicking the `Restart` button in your database service's 3-dot menu. Configuration changes to `shared_preload_libraries` require a full restart to take effect (not just a reload).
3. Query the statistics as needed after the restart
SELECT * FROM pg_stat_statements;Simply creating the extension without adding it to shared_preload_libraries won't work because PostgreSQL needs to load the extension module at startup time. The restart is necessary because configuration changes to preload libraries can't be applied without restarting the PostgreSQL process.
Reference: Railway PostgreSQL Configuration Guide
3 months ago
Hi @mykal,
I followed these exact steps:
1.
Ran ALTER SYSTEM SET shared_preload_libraries = 'pg_stat_statements';
2.
Ran SELECT pg_reload_conf(); (returned 't')
3.
Restarted PostgreSQL deployment
However, after restart:
- SHOW shared_preload_libraries returns empty (0 rows)
- pg_stat_statements still gives "must be loaded via shared_preload_libraries" error
It appears Railway's managed PostgreSQL resets ALTER SYSTEM changes on restart.
Could Railway support enable pg_stat_statements in shared_preload_libraries
at the server level for my PostgreSQL instance?
Project: travelmaster-v2
Environment: production
Database: Postgres (PostgreSQL 17.7)
mykal
The error you're encountering is a PostgreSQL requirement: pg_stat_statements must be loaded via shared_preload_libraries before PostgreSQL starts.Solution:You need to configure PostgreSQL to load pg_stat_statements in the shared_preload_libraries setting before the extension can be used. Here's how:1. Run this SQL command to modify your PostgreSQL configuration:ALTER SYSTEM SET shared_preload_libraries = 'pg_stat_statements';Then you can run:SELECT pg_reload_conf();2. Restart your PostgreSQL deployment by clicking the `Restart` button in your database service's 3-dot menu. Configuration changes to `shared_preload_libraries` require a full restart to take effect (not just a reload).3. Query the statistics as needed after the restartSELECT * FROM pg_stat_statements;Simply creating the extension without adding it to shared_preload_libraries won't work because PostgreSQL needs to load the extension module at startup time. The restart is necessary because configuration changes to preload libraries can't be applied without restarting the PostgreSQL process.Reference: Railway PostgreSQL Configuration Guide
3 months ago
I tried twice. Thank you for the involvement @mykal , However, after restart:
- SHOW shared_preload_libraries returns empty (0 rows)
- pg_stat_statements still gives "must be loaded via shared_preload_libraries" error
It appears Railway's managed PostgreSQL resets ALTER SYSTEM changes on restart.
Could Railway support enable pg_stat_statements in shared_preload_libraries
at the server level for my PostgreSQL instance?
Project: travelmaster-v2
Environment: production
Database: Postgres (PostgreSQL 17.7)
Attachments
danmateescu2025
I tried twice. Thank you for the involvement @mykal , However, after restart:- SHOW shared_preload_libraries returns empty (0 rows)- pg_stat_statements still gives "must be loaded via shared_preload_libraries" errorIt appears Railway's managed PostgreSQL resets ALTER SYSTEM changes on restart.Could Railway support enable pg_stat_statements in shared_preload_librariesat the server level for my PostgreSQL instance?Project: travelmaster-v2Environment: productionDatabase: Postgres (PostgreSQL 17.7)
3 months ago
You might need to run CREATE EXTENSION IF NOT EXISTS pg_stat_statements as a step 0 (before everything else) to get things working.
I didn't need to though when I used the default Railway PostgreSQL service/image.
Are you using the default PostgreSQL image?