This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am sharing one of the best practice we can use in our day to day work with PostgreSQL.
pg_stat_activity – we are using this view for finding the information of running queries. In the result of this view, we can see one column which is Application_Name. Which shows the application name of database connection.
More than 90% of PostgreSQL people are not using this column or feature.
In our project, thousand of adhoc queries, DBA queries, user queries and application queries are running in PostgreSQL Server.
I defined the Application name for each group and set the rule, like for all DBA and User has to set the application name before executing their query.
So, now I can easily monitor the purpose of the query by checking the Application_name column of pg_stat_activity.
Check the demo:
Set application name in one of my session:
1 |
SET application_name = 'test_activity'; |
Check the result:
In the result, you can find the query of test_activity application.
1 |
select *from pg_Stat_activity; |