Log all postgres statements - #36
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: jancervenka The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Statement log example Claude also recommends to add Log example I tested the change and it works but I found out that if you have an existing Lightspeed postgres pod and want to make changes to the postgres config, you need to delete the pod's PVC for the changes to take effect. Is that okay? |
3e36763 to
0b56997
Compare
Add log_statement = all to postgres.conf to log all statements executed by postgres (DDL, DML, DQL). Add log_lock_waits = on to log when a session is blocked waiting for a lock longer than deadlock_timeout (1s default). This can show suspicious behavior like someone holding locks to cause a denial of service.
0b56997 to
10556fb
Compare
| # ssl_ca_file = '<none>' | ||
| log_connections = on | ||
| log_disconnections = on | ||
| log_statement = all |
There was a problem hiding this comment.
I was reading about the log_statement = all and I'm not sure if it's a good idea to keep it always enabled, specially in production. See 0 or 1.
Setting log_statement = all in production is rarely worth it. It produces enormous volumes of logs and can measurably slow the server down, so most teams leave it off and reach for slow-query logging instead.
and
Warning: This setting can generate very large log files, especially in read-heavy workloads. Use with caution in production environments.
I wonder if we could add "postgres" to be part of the logging section and when it's set to debug we then inject this configuration: https://github.com/openstack-k8s-operators/lightspeed-operator/blob/main/api/v1beta1/openstacklightspeed_types.go#L116-L137
There was a problem hiding this comment.
Thank you @umago that is a good point! I am looking into it and it is possible. One issue is that right now changing postgresLoglevel for example from INFO to DEBUG and running oc apply -f cr.yaml will not automatically reflect the change in the postgres pod. It requires deleting the postgres' PVC for the change to take effect. Is that okay?
If it is worth it to be able to apply changes without deleting the PVC, I will need to investigate a little bit more how to do it.
52540c3 to
8f11c03
Compare
8f11c03 to
8b1408a
Compare
Add log_statement = all to postgres.conf to log all statements
executed by postgres (DDL, DML, DQL).
Add log_lock_waits = on to log when a session is blocked waiting
for a lock longer than deadlock_timeout (1s default). This can
show suspicious behavior like someone holding locks to cause a
denial of service.