pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Julien Rouhaud <rjuju123@gmail.com>
To: Vijaykumar Jain <vijaykumarjain.github@gmail.com>
Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: compute_query_id
Date: Thu, 17 Jun 2021 22:50:26 +0800
Message-ID: <20210617145026.ypll3a5iryjbks2h@nol> (raw)
In-Reply-To: <CAM+6J945dckHgp7f_nvuOpcOxJLoXsKRtPH6zhFFJZ8f7Ox_ag@mail.gmail.com>
References: <CAM+6J945dckHgp7f_nvuOpcOxJLoXsKRtPH6zhFFJZ8f7Ox_ag@mail.gmail.com>

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.





view thread (4+ messages)  latest in thread

Message-ID: <20210617145026.ypll3a5iryjbks2h@nol>
Permalink:  ../20210617145026.ypll3a5iryjbks2h@nol/
Also on:    postgresql.org/message-id/20210617145026.ypll3a5iryjbks2h@nol

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: rjuju123@gmail.com, vijaykumarjain.github@gmail.com
  Subject: Re: compute_query_id
  In-Reply-To: <20210617145026.ypll3a5iryjbks2h@nol>
  References: <CAM+6J945dckHgp7f_nvuOpcOxJLoXsKRtPH6zhFFJZ8f7Ox_ag@mail.gmail.com> <20210617145026.ypll3a5iryjbks2h@nol>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox