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 1mjztb-0001I9-GA for pgsql-novice@arkaria.postgresql.org; Mon, 08 Nov 2021 08:20:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mjzta-00021d-8w for pgsql-novice@arkaria.postgresql.org; Mon, 08 Nov 2021 08:20:50 +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 1mjztZ-00021U-UP for pgsql-novice@lists.postgresql.org; Mon, 08 Nov 2021 08:20:50 +0000 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mjztV-0005Cp-10 for pgsql-novice@lists.postgresql.org; Mon, 08 Nov 2021 08:20:48 +0000 Received: by mail-pf1-x42b.google.com with SMTP id s13so1001499pfd.7 for ; Mon, 08 Nov 2021 00:20:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=XVeYRkwxJgq5pZV0jqLhEXYqYXBEWfxWAvTvGTO7Eio=; b=CfDWqXa5Kio4Ma93swOmIWJvpRibxWTnDNITEj3QpPf+68xG19ShQqvuc+wTycZFza 61NNSDBf3ylsTdKTBUE9k/WqDkWQjTYCESJIz8QF2rosNjFX83dKJsYSDujZ9G6w9vhd 4L6S/PD42M2dTwrTY5ALmiarn+eWMw8xya3DXXXqXARYlx04E0m3NdN+KyJ8Iue4MHqe xZEHcF4gW8C6WmOeTPVppDGrMIJNuWEU6BPQnAO/uBZgY51IPhSj1/HwmS1NX8YLnz/t SHd91QCp+ba7j/PQHTO2en1MbcjDweyukRd5WR5SkdowcwYNVabdrJ7DtXy+tDS88JbE QZeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=XVeYRkwxJgq5pZV0jqLhEXYqYXBEWfxWAvTvGTO7Eio=; b=A1VYpwElMtjczy2W1RuKEHEWjcQr+AAPRo7DefJdq17FeAQvnzlT02NMLqQ7pnwNWB J2lFzpB+Vk9V9KBZ/A5/TQAwMa+pfrKWPGtL0f/dTkuz4JxUW40hQysrFlEYr7MZ0JXb dzIIrbslfCx0BjvFLae87NE1DCgsGj4ZqZAviEXKy/yxemNObncROtx20o/37jnDpe6L 18VmEmQ7fxu//DoybJrlA8wb4R63KkaU/iunUPzMspH6KqNw1NxOzEvp2GxfUq+FHXJ5 WBiVEkdI47QMoDQYN7/jaTHF5IXSTx2+H7/NUzhUSUxAESS96w8lbjWLdnPJW/ZcC5ST hpiA== X-Gm-Message-State: AOAM533fq3xpM8LWlwjvYsYUtYSSoFDyMZ+QdXpv5zgYozVDRBkGcNTt oITzwyjgHkoa4JsppDhQIB9mD/HZ+MAq9uY8c+P8FiTA X-Google-Smtp-Source: ABdhPJxCvFk42OOkkGe76yHeWYTXYwGkaOHbCP9/QvMtS3Psqf+l1QLXR/CCjeVCO4byURxa/0aOeND5+NLish0idpI= X-Received: by 2002:a63:8642:: with SMTP id x63mr42294628pgd.376.1636359643281; Mon, 08 Nov 2021 00:20:43 -0800 (PST) MIME-Version: 1.0 From: Jonas Gassenmeyer Date: Mon, 8 Nov 2021 09:20:33 +0100 Message-ID: Subject: Check explain plan of a running query in other session To: pgsql-novice@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000433dae05d042ab8f" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000433dae05d042ab8f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello, I am asking myself for a while if there is an easy option (via dictionary views like pg_stat_activity or similar) to check what execution plan was chosen for a long running SQL statement while it is running in a different session? I have a performance problem in a plpgsql procedure that executes an update within a loop. My guess is that it chose a generic plan instead of bind peeking and then does not use an index. I am not able to proof my theory, since I don't know how to get the explain plan for it. For me the easiest would be to check the running statement in a different session and "hook into" the other plpgsql session to check what the optimizer chose. Is that something I can do easily? If not: What is the PostgreSQL way of doing it? Danke und viele Gr=C3=BC=C3=9Fe Jonas --000000000000433dae05d042ab8f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello,

I am = asking myself for a while if there is an easy option (via dictionary views = like pg_stat_activity or similar) to check what execution plan was chosen f= or a long running SQL statement while it is running in a different session?=
I have a performance problem in a plpgsql procedure= that executes an update within a loop. My guess is that it chose a generic= plan instead of bind peeking and then does not use an index.

I am not able to proof my theory,= since I don't know how to get the explain plan for it.
For me the easiest would be to check the running statement in a d= ifferent session and "hook into" the other plpgsql session to che= ck what the optimizer chose.

Is that something I can do easily? If not: What is the PostgreSQL way = of doing it?

Da= nke und viele Gr=C3=BC=C3=9Fe
Jonas
--000000000000433dae05d042ab8f--