On Thu, Jun 17, 2021 at 08:09:54PM +0530, Vijaykumar Jain wrote: > how is the compute_query_id actually calculated? It's the exact same implementation that was extracted from pg_stat_statements. You have some implementation details at https://www.postgresql.org/docs/current/pgstatstatements.html. > why does it show 0 in logs for random sql queries. > log_line_prefix = '%Q :' > 0 :LOG: statement: select * from pg_stat_activity; It means that you haven't enabled it: 2021-06-17 22:46:16.231 CST [11246] queryid=0 LOG: duration: 4.971 ms statement: select * from pg_stat_activity ; 2021-06-17 22:46:25.383 CST [11246] queryid=0 LOG: duration: 0.284 ms statement: set compute_query_id = on; 2021-06-17 22:46:28.744 CST [11246] queryid=941978042436931562 LOG: duration: 1.725 ms statement: select * from pg_stat_activity ; > i mean pid already was doing the job to identify the query and its children > even it logs, > but i know pid will get recycled. I'm not sure that I understand that question. The pid will identify a backend, and that backend can execute 0, 1 or a lot of different queries. The query_id will uniquely identify statements after some normalization and removing the constant parts (so for instance "select 1;" and "Select 2 ;" will have the same identifier). Having only that information in the log can be useful on its own, but you usually get way more benefit using additional modules like pg_stat_statements.