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 1lttLy-0006ws-Ey for pgsql-general@arkaria.postgresql.org; Thu, 17 Jun 2021 14:50:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lttLx-0001EU-F6 for pgsql-general@arkaria.postgresql.org; Thu, 17 Jun 2021 14:50:45 +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 1lttLx-0001EK-4U for pgsql-general@lists.postgresql.org; Thu, 17 Jun 2021 14:50:45 +0000 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lttLt-0003uK-RA for pgsql-general@lists.postgresql.org; Thu, 17 Jun 2021 14:50:44 +0000 Received: by mail-pj1-x1030.google.com with SMTP id k7so3899204pjf.5 for ; Thu, 17 Jun 2021 07:50:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=6qXZw3dqh1GPEFf+eChAzsxyRtJUfxu3bKgUdl6LcNc=; b=WgG8kCjbe0mjyQJZNfzU2pCLKlXt9rnTrQg/Kx7szLwPEdezKxyqacCUpzQNRP9iOF X1jsHbzJWuuGxrIJ7DGo8Ylt5vho1RT2sReAqnmzoOgciMGDeaGooy6/ekH2NEKoLVQ1 Sf2EUxhpGjjaYXivYzEQ3BGpjn+Rr6DzVRCNnvfxWAzGnUjnhIXRFUYfgTwyszyxMKDR paRC6NIUoAYKtJclMkRGr4+ZTrPGjZVZ7cP94UI5tzuR6GczJrZ/9PLxmWIUDT9983AI MI4hHR/io+c1+wMZZumFpGhn5EF4l//XU5/vzKwpBLthulMfN8FurTphnwEqIFfV02vr uJpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6qXZw3dqh1GPEFf+eChAzsxyRtJUfxu3bKgUdl6LcNc=; b=FZuwSb7pmq0wj+S4QeSnuct0MV86p2HNZiLV4OT3ZVrK6rur+Gf2hUrthss1F5JOd2 lXzUp8FeD6YEW5Z+3A6mPQtA+5k/PJ2d9ZNRFzlf9WIegIKc8KyqKwzyrTctSkTm8fed vrYc1Lg13AaXBUBYJaUTTJN9oSWyADeQhn/kfCGw3Nqx5tYIRtKqlkotk4P+v/fW6zDV liJDsficgOAtFtM1ND+QuKo/PqnjK3W7bNiXxnWbYgBmjEh1QZ7mkgYL92hDigV1POmb gb26FSRlnrl8oP6Z7YBEF/jauQh3PWxfimOC+jOnkd5pcRc9HNV/L+2ScW0GXTjIT5Ew mfDQ== X-Gm-Message-State: AOAM532tiIfIOkJuZ1Bxahh+DU7jEtAH9k5D1xhq3KKat/RsLnk09mfI f5S1+2o/fxv+6IdnTgIuRDM= X-Google-Smtp-Source: ABdhPJxXJPrrNOu9O1ado66agbIw5pXzQ0yFFNvcu27x4lMJ9MCAPaZliQA/6VMftqvCMp28GpSq7w== X-Received: by 2002:a17:902:748c:b029:103:267f:a2b3 with SMTP id h12-20020a170902748cb0290103267fa2b3mr264383pll.23.1623941440220; Thu, 17 Jun 2021 07:50:40 -0700 (PDT) Received: from nol (2001-b011-0008-f025-d963-d051-e6ec-9ba6.dynamic-ip6.hinet.net. [2001:b011:8:f025:d963:d051:e6ec:9ba6]) by smtp.gmail.com with ESMTPSA id b195sm6299219pga.47.2021.06.17.07.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 07:50:39 -0700 (PDT) Date: Thu, 17 Jun 2021 22:50:26 +0800 From: Julien Rouhaud To: Vijaykumar Jain Cc: pgsql-general Subject: Re: compute_query_id Message-ID: <20210617145026.ypll3a5iryjbks2h@nol> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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.