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 1mk0FA-000280-PC for pgsql-novice@arkaria.postgresql.org; Mon, 08 Nov 2021 08:43:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mk0F9-0003Vl-6v for pgsql-novice@arkaria.postgresql.org; Mon, 08 Nov 2021 08:43:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mk0F8-0003Vb-PJ for pgsql-novice@lists.postgresql.org; Mon, 08 Nov 2021 08:43:06 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mk0F5-00078E-2Q for pgsql-novice@lists.postgresql.org; Mon, 08 Nov 2021 08:43:05 +0000 Received: by mail-wm1-x332.google.com with SMTP id 67-20020a1c1946000000b0030d4c90fa87so11032465wmz.2 for ; Mon, 08 Nov 2021 00:43:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20210112.gappssmtp.com; s=20210112; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=tj0KA3hqQZ8Nccvf0/8DLcSM8HF9aOthelayHMnP/R8=; b=IewjyhmHBippgJaqKBUGR2RLs0qc3R/BlFhxGNwVec76AJLHU5DlbO1MZ909ZfxyiG tP20X/5FZefXcJ5+Ve/VeXhYWd8Mr+lo1VDBXF00QyUglHw9C7awwKRZcjn4B2XnieBw dJFdtLTpnlLm0wnrUtiJkIwnPkdiGUtl3p2TKiwR1Cw8QUjcdWl07mREmXnHbcwq+FXk nLOpHmTeX7IolGfggVzDH9k/ICGmn5oCjYw4bazL9Goo613c8hgrS0l3LsVNDVx0+G+d 9BVNQGCQXzER68zPcSYaWnNkWfVQubBDLWvDAdLcRZA15sp9jj5b92EPfOGJsgCIcK29 qnCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=tj0KA3hqQZ8Nccvf0/8DLcSM8HF9aOthelayHMnP/R8=; b=oS0Mpf59tdtzsaHo6B7EY6gtEbtmmJT4P8Lbf4kbY/fHBhjgU9KNyh/URQ+bml7/79 XGO4Jd/TAfQeyo8IllpYmhsVVhsJ/jrkloTnsW06PgYN4JOUZMHU8JpF4+QD5Xffhzb+ nJxAnnaQfjd6E0s67qvic3zZDyuzomYQEbyaklKMnOre4b+i2EiCCtQeexbxtDgrvxlg pBZLR8BOV1oqES4NXyN9cgiygyeDH1TyX6jN2f0+osKpE3JRfgB9x/zjAUg1Cqsv/zcZ 7kmDxmBla6suwRBT/1S86itN8x25nSsjwNireK7mqOk5lAnFXGcgsmaCi1ZsPzjkJBK7 mg9A== X-Gm-Message-State: AOAM5318aercHoqA1apvecDs/nbNZXDSFd7i1YYnhCEmgpxLv2Zc5MV4 ydbgCfT4LOcxqcQlWaR/kv5iBQ== X-Google-Smtp-Source: ABdhPJwPbMx/ELPAGAPkn/8T3xxTF3PPHlNFk5csxdXeixGBjN12Die0dSLdPeS5I+jjIY7NS9Xypw== X-Received: by 2002:a7b:ca4c:: with SMTP id m12mr48972337wml.119.1636360980596; Mon, 08 Nov 2021 00:43:00 -0800 (PST) Received: from localhost.localdomain (dynamic-e1vumhh6f533tadyy-pd01.res.v6.highway.a1.net. [2001:871:5c:8299:ef99:d70e:7b49:fe3a]) by smtp.gmail.com with ESMTPSA id o1sm17064444wrn.63.2021.11.08.00.42.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 00:42:52 -0800 (PST) Message-ID: Subject: Re: Check explain plan of a running query in other session From: Laurenz Albe To: Jonas Gassenmeyer , pgsql-novice@lists.postgresql.org Date: Mon, 08 Nov 2021 09:42:46 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.4 (3.40.4-2.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 2021-11-08 at 09:20 +0100, Jonas Gassenmeyer wrote: > 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? There is nothing like that built into PostgreSQL, but you could try pg_show_plans: https://github.com/cybertec-postgresql/pg_show_plans Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com