We wrote a small tool which displays all currently running queries. We get the currently running queries from pg_stat_activity.
The problem is: We dont know the parameters which were given to the query. We can only see the placeholders $1, $2, etc.
Is there any way to get the parameters for a currently running query?
The only workaround could be to enable the query log and parse the parameters from the query log, but this would be a very dirty and slow solution.
Identify the current activity of the session by running the following command: SELECT * FROM pg_stat_activity WHERE pid = PID; Note: Replace PID with the pid that you identified in the step 1.
The most powerful tool at our disposal for understanding and optimizing SQL queries is EXPLAIN ANALYZE , which is a Postgres command that accepts a statement such as SELECT ... , UPDATE ... , or DELETE ... , executes the statement, and instead of returning the data provides a query plan detailing what approach the ...
pid: Process ID of the server process holding/waiting for this lock. Joining this column onto the pg_stat_activity view can provide all of the information above on the query / user / time etc.
I don't think it's possible. I have faced the same issue.
I use to run all the queries through stored procedures/functions. This way you can add code to make a log at the start of every function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With