Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tsfE8-004DKt-TF for pgsql-general@arkaria.postgresql.org; Thu, 13 Mar 2025 09:51:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tsfE7-009Kr9-FT for pgsql-general@arkaria.postgresql.org; Thu, 13 Mar 2025 09:51:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tsfE7-009Kr1-25 for pgsql-general@lists.postgresql.org; Thu, 13 Mar 2025 09:51:43 +0000 Received: from mail-ej1-x644.google.com ([2a00:1450:4864:20::644]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tsfE3-002crB-2M for pgsql-general@lists.postgresql.org; Thu, 13 Mar 2025 09:51:42 +0000 Received: by mail-ej1-x644.google.com with SMTP id a640c23a62f3a-abbd96bef64so132904466b.3 for ; Thu, 13 Mar 2025 02:51:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741859499; x=1742464299; darn=lists.postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=zA2aGaKusCkldpxeWq/eFGNxAKbaBb8dXmUb0cDcYEg=; b=nAzeOwwXstzMx9yO+GLcpcaNmPHaTv6TfJZ4dGfpQ2hXfouaSLLBWf3B/8rh2cqDFo +O9OnembzdZLo/KHqpSiPbFvS88c9R40mBT9/tp/7419F/8bDcLI7Wz8LTbtiSQV25Pf sul2Orrap1wFIyBMJl5gI7kHPsDDmO+mM7BLih+66QjCrEqphe5ciYEApb/NRZm2PMV3 8C3lJPUIcjKMVcqMJjwFx1wdacEFBLQP8eYiNjzNowq0FwzMS+RQaKzUkrtTrrryg3iy 4XgEY+B/EnRYCYQZc/MachHfKUWt5nqfKISVZHau6TmSYXM9N0TPMCA8fa6XF/X/VoGH 9Hyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741859499; x=1742464299; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=zA2aGaKusCkldpxeWq/eFGNxAKbaBb8dXmUb0cDcYEg=; b=UL8k6Tlq6KGMqwZL3gPHaskKIE75Sg+9jZ/elVxMz92fRuyMRk04NyKJjBqQ1VCWvw seRxtc8mNxgHap6Z1M7zBzlMiLNPbCM3nJ0/gLkixMvxxa1sPZ/yAZyy9iJfo9Cfg0s7 XSKHWEZgd+OpOo7SiQRzvRtdOw8M0gG3GoaoK+edbWNTY1QZo3zLEEMw1u0loFW3iy2/ trqo1fcMZC+wdQy/zHoMG2sVphwynsV8Vcsqbzy7pZMLauBoP9S6t788tsPqPFJF8STq dIml6wKmKgb5X/7jyI5jM/olKEsuki5IoEQDvsSx1Fq6wQhAQN9oEPMnrBp5iuj9Ci5d DesQ== X-Gm-Message-State: AOJu0Yy3FdfbGRkNfeH5MtmqhTwWbA65KFbFm0gC5/sqZvh+UzAesBWe blj0ID4vFlYG4NiE+MYAZq5ELtcrkGl5EyHsIkE0OCafbAek7yyFCqq/UTPd8Lma/CkOgKqSVeC wQYtS9FR8iKzEtKJHLz5GC7tWoZS30Axt5hrQYw== X-Gm-Gg: ASbGncus6laRxyjvUoBjipMbpsaISk95Pz8jLtX7rp196fLQzc1X0YFM33WA9GG+6Vi lXgnTTfX/0H1mnL9im02XthUxCJ/m2S+sN0gORbGbvPPfigP/sZfyC1mnmG9h7eq8VNg4SW6Zgm 7P8eR3LK76cWVnMQGQ1BNhAS0RRg== X-Google-Smtp-Source: AGHT+IFriGWKYgXH1/xvn6yoDYhFltZTTjKQoh6I5aSNxEQu9dIuEZN6TMnVZl78dOLuHIwf2QAl2rnCHL2901xla/8= X-Received: by 2002:a17:907:3e09:b0:abf:5266:6542 with SMTP id a640c23a62f3a-ac252ef911bmr3126338366b.55.1741859498931; Thu, 13 Mar 2025 02:51:38 -0700 (PDT) MIME-Version: 1.0 From: Prasanna Thirugnanasambandam Date: Thu, 13 Mar 2025 15:21:27 +0530 X-Gm-Features: AQ5f1JrUgxsap1qjy28r4hGjGP9JLEynezowZaXNkhywkoRn7mf0NOlkCEu0OlU Message-ID: Subject: Finding execution time for a query To: pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000aebf6c0630364498" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000aebf6c0630364498 Content-Type: text/plain; charset="UTF-8" Hello all, How do I find the execution time of a query? I tried these methods: I used pgbench - pgbench -n -t 1 -f ./query.sql and got: latency average = 9.787 ms <- should i take this as the execution time? initial connection time = 12.481 ms tps = 102.176356 (without initial connection time) used *pg_stat_statements* to fetch execution time for that query. SELECT total_exec_time FROM pg_stat_statements where query = '' got: total_exec_time -------------------- 12.242579000000001 (1 row) used *EXPLAIN ANALYZE*, got: QUERY PLAN ------------------------------------------------------------------------------------------------ (cost=0.00..0.01 rows=0 width=0) (actual time=0.182..0.182 rows=0 loops=1) -> Result (cost=0.00..0.01 rows=1 width=230) (actual time=0.034..0.034 rows=1 loops=1) Planning Time: 0.021 ms Execution Time: 0.195 ms (4 rows) Now, which among these gives me the actual execution time of the query? Or rather, how can i find out the actual execution time of the query? --000000000000aebf6c0630364498 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello all,

How do I find the execu= tion time of a query?
I tried these methods:
I used
pgbench - pgbench = -n -t 1 -f ./query.sql <database name>
and got:
=C2=A0 =C2=A0 latency average =3D 9.787 ms <= ;- should i take this as the execution time?
=C2=A0 =C2=A0 initial conne= ction time =3D 12.481 ms
=C2=A0 =C2=A0 tps =3D 102.176356 (without initi= al connection time)
used pg_stat_statements to fetch exe= cution time for that query.
SELECT total_e= xec_time FROM pg_stat_statements where query =3D '<query here>= 9;
got:
=C2=A0 =C2=A0 =C2=A0 to= tal_exec_time =C2=A0
=C2=A0 =C2=A0 --------------------
=C2=A0 =C2= =A0 =C2=A012.242579000000001
=C2=A0 =C2=A0 (1 row)
used E= XPLAIN ANALYZE, got:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0QUERY PLAN =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0
---------------= ---------------------------------------------------------------------------= ------
=C2=A0<query description> =C2=A0(cost=3D0.00..0.01 rows=3D0= width=3D0) (actual time=3D0.182..0.182 rows=3D0 loops=3D1)
=C2=A0 =C2= =A0-> =C2=A0Result =C2=A0(cost=3D0.00..0.01 rows=3D1 width=3D230) (actua= l time=3D0.034..0.034 rows=3D1 loops=3D1)
=C2=A0Planning Time: 0.021 ms<= br>=C2=A0Execution Time: 0.195 ms
(4 rows)

Now, which among these gives me the actual execution time of the query? Or=20 rather, how can i find out the actual execution time of the query?
--000000000000aebf6c0630364498--