1

I am trying to associate slow queries on PostgreSQL to applications that cause them. I have set rudimentary application_name tracking.

Some applications contain several independent tasks running concurrently. Would it be possible to update application_name in the middle of a session to reflect the task the connection is currently processing? This way pinning down the source of problematic queries would be easier, as I could read from pg_stat_activity directly something human-readable for the root cause of slow queries.

(Alternative I can make clients to reconnect with different name, but this is a bit painful.)

1 Answer 1

2
testdb=# set application_name='myapp_pid12345';
SET
testdb=# select application_name from pg_stat_activity where pid=pg_backend_pid();
 application_name 
------------------
 myapp_pid12345
(1 row)

testdb=# set application_name='myapp_pid54321';
SET
testdb=# select application_name from pg_stat_activity where pid=pg_backend_pid();
 application_name 
------------------
 myapp_pid54321
(1 row)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.