A quick question regarding the use of the pg_stat_statements extension on Fly’s Postgres. I can enable the extension without issue but when attempting to use it, however further configuration needs to be in place to use the extension:
pg_stat_statements must be loaded via shared_preload_libraries
It would seem a change to the postgresql.conf needs to be in place to make the extension work. Namely, shared_preload_libraries = 'pg_stat_statements'
My (vague) understanding of Postgres on Fly is that it’s more of a recipe then it is a full managed service. If this is the case, what is the best approach to modifying the Postgres config?
You also don’t have to modify the config, startup switches appear to be enough to enable the shared library, i.e something like: postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all
You can clone it, change the name in fly.toml, make changes, and then deploy over your app. Just make sure you pass in the version arg for Postgres 13 if you need it. Postgres 14 is the default:
Thanks for that, I’ll give it a try shortly and report back.
Re: your non forked method, I assume it will persist after restarts but what about upgrades to the Postgres service? I.e. looking at my image:
fly image show --app=vodon-db
Current image details
Registry = registry-1.docker.io
Repository = flyio/postgres
Tag = 14.1
Version = v0.0.8
Digest = sha256:83d4f540dc2a1c7936e421a75b333ed8a04050093c7cfaf81f24607d9e1b793f
Latest image details
Registry = registry-1.docker.io
Repository = flyio/postgres
Tag = 14.1
Version = v0.0.9
Digest = sha256:ea54d08a4e97a772ca033cd02d852d4a96d023978669ee148a9d439f30d50685
I’m one point version behind latest. If I make the change above then update the image, does it persists (you can tell me to pound sand and test it myself if you’d like )
Once for the shared_preload_libraries and a second for pg_stat_statements.track?
Would greatly appreciate a step by step guide unless there is an easier way now @kurt ?
We are looking to get query stats working with PG Hero.
Also, any plans to have this automatically enabled in the future? Taking a look at Heroku PG and it might automatically include this for non hobby dbs?
I think, don’t quite me on this, that it was just:
CREATE EXTENSION pg_stat_statements
then the patch command that I ran. I believe once the patch was in place I may have had to reboot the DB instance (as @kurt mentions with the “deploy”). I think instead I just scaled it to 0 then back up again. After that everything seemed to work (I was using this with Elixir’s Live Dashboard library so it may have issued some other commands behind the scenes).
Can this now be done using the fly postgres config update command, or does that do something else?
Edit: this command seems specific to log-min-duration-statement, log-statement, max-connections, and wal-level configuration. I was able to do it with ssh + stolonctl as described above.
Updating the config to load pg_stat_statements is silently failing.
Update command:
fly postgres config update -a chat-pg --shared-preload-libraries pg_stat_statements
Before and after I run the update command, the config view command shows that the shared-preload-libraries has no value.
fly postgres config view -a chat-pg
NAME VALUE UNIT DESCRIPTION PENDING RESTART
...
shared-preload-libraries Lists shared libraries to preload into server. false
I am on the latest image
fly image show -a chat-pg
Image Details
MACHINE ID REGISTRY REPOSITORY TAG VERSION DIGEST
d568352a74e18e registry-1.docker.io flyio/postgres 14.4 v0.0.33 sha256:0aa49da884754d5e46d3d465738a20952d86f75970bc2fd0ef3f654669b9f2e4
For what it’s worth, I also tried update max-connections to see if it was shared-preload-libraries specifically or config updates in general, the max-connections also failed to update.
There don’t seem to be any relevant logs, just this message:
ewr [info]sentinel | 2022-12-22T04:11:24.509Z WARN cmd/sentinel.go:276 no keeper info available {"db": "8dac5307", "keeper": "7d18175c36a2"}
> fly postgres config view -a chat-pg
Update available 0.0.441 -> 0.0.442.
Run "fly version update" to upgrade.
NAME VALUE UNIT DESCRIPTION PENDING RESTART
...
shared-preload-libraries -> (pg_stat_statements) Lists shared libraries to preload into server. true
...
Some changes are awaiting a restart!
To apply changes, run: `fly postgres restart --app chat-pg`
Then I followed the instructions in that last command to restart the server. Done!