Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q19Zd-0004rQ-NR for pgsql-admin@arkaria.postgresql.org; Mon, 22 May 2023 17:43:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q19Zc-0005Rw-DG for pgsql-admin@arkaria.postgresql.org; Mon, 22 May 2023 17:43:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q19Zc-0005Rm-2J for pgsql-admin@lists.postgresql.org; Mon, 22 May 2023 17:43:56 +0000 Received: from mout-u-204.mailbox.org ([2001:67c:2050:101:465::204]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1q19ZV-001FSF-1V for pgsql-admin@postgresql.org; Mon, 22 May 2023 17:43:54 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-204.mailbox.org (Postfix) with ESMTPS id 4QQ4Yk4jrBz9sPl; Mon, 22 May 2023 19:43:38 +0200 (CEST) Date: Mon, 22 May 2023 19:43:38 +0200 (CEST) From: Erik Wienhold To: kaido vaikla Cc: pgsql-admin@postgresql.org Message-ID: <1391613709.939460.1684777418070@office.mailbox.org> In-Reply-To: References: <472115375.225506.1683812791906@office.mailbox.org> <1279536236.296763.1683901055904@office.mailbox.org> Subject: Re: pg_stat_activity query_id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Priority: 3 Importance: Normal List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 22/05/2023 15:44 CEST kaido vaikla wrote: > > I asked from pg jdbc community. Answer was : > "One thing to note is that the driver uses extended query protocol so the > queries are not identical.". > I don't know, is it this now key to understand this issue? > https://github.com/pgjdbc/pgjdbc/discussions/2902#discussioncomment-5917360 Look's like the extended query protocol is the reason for that. Testing with psycopg 3.1 (which added pipeline mode to use the extended query protocol) confirms this: from psycopg import connect from psycopg.rows import dict_row conninfo = 'dbname=postgres' query = 'SELECT 1' with connect(conninfo) as con0: backend_pid = con0.info.backend_pid server_version = con0.info.server_version print(f"{backend_pid=} {server_version=}") con0.execute('SET compute_query_id = on') print("=> simple query") con0.execute(query) with connect(conninfo, row_factory=dict_row) as con1: with con1.execute(''' SELECT pid, query, query_id FROM pg_stat_activity WHERE pid = %s ''', (backend_pid,)) as cur: for row in cur.fetchall(): print(row) print("=> extended query") with con0.pipeline(): con0.execute(query) with connect(conninfo, row_factory=dict_row) as con1: with con1.execute(''' SELECT pid, query, query_id FROM pg_stat_activity WHERE pid = %s ''', (backend_pid,)) as cur: for row in cur.fetchall(): print(row) Gives me: backend_pid=800121 server_version=150002 => simple query {'pid': 800121, 'query': 'SELECT 1', 'query_id': 1147616880456321454} => extended query {'pid': 800121, 'query': 'SELECT 1', 'query_id': None} I wonder if this is a limitation of the extended query protocol. Computing the query identifier for a prepared statement with placeholders is not very useful. But I would think that a useful query identifier can be calculated once the placeholders are bound to concrete values and the query is executed. -- Erik