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 1mlbQN-0001R8-C6 for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Nov 2021 18:37:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mlbQM-0006GY-BB for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Nov 2021 18:37:18 +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 1mlbQM-0006GM-2J for pgsql-hackers@lists.postgresql.org; Fri, 12 Nov 2021 18:37:18 +0000 Received: from mail-io1-xd33.google.com ([2607:f8b0:4864:20::d33]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mlbQH-0004z0-4a for pgsql-hackers@lists.postgresql.org; Fri, 12 Nov 2021 18:37:17 +0000 Received: by mail-io1-xd33.google.com with SMTP id x10so12354808ioj.9 for ; Fri, 12 Nov 2021 10:37:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=1JT3uCbtb5k2lwDamLsM257gc8JutXy8Q8AJCKP/Aoo=; b=HtgOJVHxOtdybNHnxWgiwc7plzrEJmkqMNNh7/RNk8M7huJwtfehuF0h+VZ0AGfGEy 5KT1D9+3Nut4V7CIvPSUWXh3ZbUqAIyG5G4Z2ML8Ub+vAnTszgiejdxRWT7ujnS603Ul PJMxJOdgqAOHoAkeOWzIjlJ65NWzw0RlVwV6INRAWPcvcG7V29Va3J2v8CqIzi/ct6DY VDVHydnx2WOZezq2xfPNQfdEvdlDFoDfxjrikxF2AcBiLO5Ul6rMOJA+UrBTPHRmaFqm a8NHAGB9cB21qkdHgbWi/kNfnKX7byL1SL9chODYfTwEOP/YFWaNhDFm70uWQodFiq3O 5Rnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=1JT3uCbtb5k2lwDamLsM257gc8JutXy8Q8AJCKP/Aoo=; b=DU/wifuLqpxJmT7iR8O1Harr/09/WnPM35wpKv02iMNiWFdGpDHziQBVBkugCiPCsH 480yLXHtyuZbCvEdtjZKdiGB37MLhrA6H+bb8qitfvKb4nUE3KDi9wIs9RrOOIDIXAw8 d4IECzEucdKiucg5NBuEG3LP9Z5jE/6h+o0rmrH7FB4zjcZYOjJ+xxj0/5HzKs7R+Uts pwVOmKfATSsTd3iFU5X4cA158cwVCJFvzOmxlk6k9XvG0hDm2eJh1R2JN8S1VZYYk4Mr vd66YJzT5PukpUHYTHscq6QDV86GqTZLEM4VGcFtsK/KAi1f/jANI3RHE6LRHM6MHjgi 6HGQ== X-Gm-Message-State: AOAM5335p128yw78Yj611UddTP5akKZLkC54vGd7Gs11r3b9kkMX6LVV OoxJgYLqTB8tdCevmHtlQkSZl3xKnU+UoA== X-Google-Smtp-Source: ABdhPJykg3ER2cfFn1/tpMJmpJ0epI8H8fDcnJeYyC24ox8+QgHq17j+xC8gW4e3L5gjAx9b1/YkbA== X-Received: by 2002:a02:9586:: with SMTP id b6mr13197645jai.24.1636742231031; Fri, 12 Nov 2021 10:37:11 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id b15sm4416617iln.36.2021.11.12.10.37.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Nov 2021 10:37:10 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id C88958009C6; Fri, 12 Nov 2021 12:37:09 -0600 (CST) Date: Fri, 12 Nov 2021 12:37:09 -0600 From: Justin Pryzby To: Ekaterina Sokolova Cc: pgsql-hackers@lists.postgresql.org, torikoshia@oss.nttdata.com, Fujii Masao Subject: Re: RFC: Logging plan of the running query Message-ID: <20211112183709.GK17618@telsasoft.com> References: <8b53b32f-26cc-0531-4ac0-27310e0bef4b@oss.nttdata.com> <7958d03fffe3bafcfe8a505145c63928@oss.nttdata.com> <9c4d9da6-48a5-fa18-4bff-f8eb0d4c9787@oss.nttdata.com> <59e6df324b41176d319f9c30bdb1d858@oss.nttdata.com> <0642712f-1298-960a-a3ba-e256d56040ac@oss.nttdata.com> <3d345c49561f31a1d8ff60ea86f88840@oss.nttdata.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Oct 13, 2021 at 05:28:30PM +0300, Ekaterina Sokolova wrote: > Hi, hackers! > > • pg_query_state is contrib with 2 patches for core (I hope someday > Community will support adding this patches to PostgreSQL). It contains I reviewed this version of the patch - I have some language fixes. I didn't know about pg_query_state, thanks. > To improve this situation, this patch adds > pg_log_current_query_plan() function that requests to log the > plan of the specified backend process. To me, "current plan" seems to mean "plan of *this* backend" (which makes no sense to log). I think the user-facing function could be called pg_log_query_plan(). It's true that the implementation is a request to another backend to log its *own* query plan - but users shouldn't need to know about the implementation. > + Only superusers can request to log plan of the running query. .. log the plan of a running query. > + Note that nested statements (statements executed inside a function) are not > + considered for logging. Only the deepest nesting query's plan is logged. Only the plan of the most deeply nested query is logged. > + (errmsg("backend with PID %d is not running a query", > + MyProcPid))); The extra parens around errmsg() are not needed since e3a87b499. > + (errmsg("backend with PID %d is now holding a page lock. Try again", remove "now" > + (errmsg("plan of the query running on backend with PID %d is:\n%s", > + MyProcPid, es->str->data), Maybe this should say "query plan running on backend with PID 17793 is:" > + * would cause lots of log messages and which can lead to denial of remove "and" > + errmsg("must be a superuser to log information about specified process"))); I think it should say not say "specified", since that sounds like the user might have access to log information about some other processes: | must be a superuser to log information about processes > + > + proc = BackendPidGetProc(pid); > + > + /* > + * BackendPidGetProc returns NULL if the pid isn't valid; but by the time > + * we reach kill(), a process for which we get a valid proc here might > + * have terminated on its own. There's no way to acquire a lock on an > + * arbitrary process to prevent that. But since this mechanism is usually > + * used to below purposes, it might end its own first and the information used for below purposes, -- Justin