Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hC74S-0000WM-AI for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Apr 2019 18:26:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hC74Q-0000DK-Fx for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Apr 2019 18:26:38 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hC74Q-00006V-5A for pgsql-hackers@lists.postgresql.org; Thu, 04 Apr 2019 18:26:38 +0000 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hC74M-00011f-Km for pgsql-hackers@postgresql.org; Thu, 04 Apr 2019 18:26:37 +0000 Received: by mail-qt1-x841.google.com with SMTP id z16so4442752qtn.4 for ; Thu, 04 Apr 2019 11:26:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=Q0CHAJuaRJKJjSPYBQAtLOmk4a67x+iFlv8j7VALvNU=; b=AevnQirf4qdzsZOm+DKqsS+MTWosLPCoPJsK3h0TUFDE/WJeVMKTcxiJzwcHeCBfsF 9bvYlZJd1YS6v0G4ZmgKaLit5r4O6GqiCa8z+JEyDaM5E5R9dbyeNys64Bn4uWwdNZQm 79PTx2gEbOJbkVSV07UDMFENEEfE8QHA0VdjxWF3o5Imeqva6pzlt2WQ3lXMvugba2Wl /mKbQDy0OHkSfDp2CPBNvRRYVy4fqiZE4P1LGpL4Kh+I2egu7YOiLZrF/6PsmTMM++GX vRR0lvioQNYFYjGex8bMEu7ivTkxbhDtrY+yUoCx6vWZQU6E6Cop0FkCZLqqZYvNPB1G ES8w== 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:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=Q0CHAJuaRJKJjSPYBQAtLOmk4a67x+iFlv8j7VALvNU=; b=jhSEXCV775xnQPfdD5GgY30E9m0pbO0iSMfKN1j8dM/ufrqkrZ1UjudhORunnsjuSV DSTrJfFtisnbwyHAy6l0OPg3pX3+Q5DtMdsmFfjQzfped8dUHSozT+nLjMtnki8dC2BS c6ZxnLgEyykycr+pM3Mu5YxnTXKfrl80YjA3QRTz5F3OXWwyx0XKklSFRjxClrDuw6Bx +LKaMW9eQUyj9eK0TDZNiJiKFgnVZ86cUfBQ681G+IuwE1BCMAW2nXcchzVVCAIBlqb0 /oirWw8vnoeq6bM8R2Z1USVjiAUZjFO0TDqmOQkwiUFOLU5SLkQxpdo4eFZgE/k7xval gHZQ== X-Gm-Message-State: APjAAAXVItfMDbYlE5A9bB1P6KUoh6rKnyHmnvbbYd29KcJFtOtRw+pY /4jRs4QZGqzO4XwW29i/L6eB0Q== X-Google-Smtp-Source: APXvYqwS+FjOMt4pyhDW2yxl9Jt5wPY6Hvh54w9X+TcDVUE7LIu0jdmISYpXmS2hmxTJBsDL840xgA== X-Received: by 2002:a0c:d0bd:: with SMTP id z58mr6143773qvg.121.1554402392679; Thu, 04 Apr 2019 11:26:32 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.121.29.3]) by smtp.gmail.com with ESMTPSA id w12sm10626246qkb.91.2019.04.04.11.26.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Apr 2019 11:26:32 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 4371C120F3B; Thu, 4 Apr 2019 15:26:30 -0300 (-03) Date: Thu, 4 Apr 2019 15:26:30 -0300 From: Alvaro Herrera To: Justin Pryzby Cc: Arthur Zakirov , pgsql-hackers@postgresql.org Subject: Re: query logging of prepared statements Message-ID: <20190404182630.GA4305@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190404180704.GA31569@alvherre.pgsql> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2019-Apr-04, Alvaro Herrera wrote: > However, turning duration logging off and using log_statement=all, this is what > I get: > > 2019-04-04 14:58:42.564 -03 [31685] LOG: statement: SET search_path = testlibpq3 > 2019-04-04 14:58:42.565 -03 [31685] LOG: execute > 2019-04-04 14:58:42.565 -03 [31685] DETAIL: parameters: $1 = 'joe''s place' > 2019-04-04 14:58:42.565 -03 [31685] LOG: execute > 2019-04-04 14:58:42.565 -03 [31685] DETAIL: parameters: $1 = '2' With this patch (pretty much equivalent to reinstanting the errdetail_execute for that line), diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index dbc7b797c6e..fd73d5e9951 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -2056,7 +2056,6 @@ exec_execute_message(const char *portal_name, long max_rows) prepStmtName, *portal_name ? "/" : "", *portal_name ? portal_name : ""), - errhidestmt(true), errdetail_params(portalParams))); was_logged = true; } I get what seems to be pretty much what is wanted for this case: 2019-04-04 15:18:16.817 -03 [4559] LOG: statement: SET search_path = testlibpq3 2019-04-04 15:18:16.819 -03 [4559] LOG: execute 2019-04-04 15:18:16.819 -03 [4559] DETAIL: parameters: $1 = 'joe''s place' 2019-04-04 15:18:16.819 -03 [4559] STATEMENT: SELECT * FROM test1 WHERE t = $1 2019-04-04 15:18:16.820 -03 [4559] LOG: execute 2019-04-04 15:18:16.820 -03 [4559] DETAIL: parameters: $1 = '2' 2019-04-04 15:18:16.820 -03 [4559] STATEMENT: SELECT * FROM test1 WHERE i = $1::int4 However, by setting both log_statement=all and log_min_duration_statement=0 and that patch (I also added %l to log_line_prefix), I get this: 2019-04-04 15:23:45 -03 [5208-1] LOG: statement: SET search_path = testlibpq3 2019-04-04 15:23:45 -03 [5208-2] LOG: duration: 0.441 ms 2019-04-04 15:23:45 -03 [5208-3] LOG: duration: 1.127 ms parse : SELECT * FROM test1 WHERE t = $1 2019-04-04 15:23:45 -03 [5208-4] LOG: duration: 0.789 ms bind 2019-04-04 15:23:45 -03 [5208-5] DETAIL: parameters: $1 = 'joe''s place' 2019-04-04 15:23:45 -03 [5208-6] LOG: execute 2019-04-04 15:23:45 -03 [5208-7] DETAIL: parameters: $1 = 'joe''s place' 2019-04-04 15:23:45 -03 [5208-8] STATEMENT: SELECT * FROM test1 WHERE t = $1 2019-04-04 15:23:45 -03 [5208-9] LOG: duration: 0.088 ms 2019-04-04 15:23:45 -03 [5208-10] LOG: duration: 0.363 ms parse : SELECT * FROM test1 WHERE i = $1::int4 2019-04-04 15:23:45 -03 [5208-11] LOG: duration: 0.206 ms bind 2019-04-04 15:23:45 -03 [5208-12] DETAIL: parameters: $1 = '2' 2019-04-04 15:23:45 -03 [5208-13] LOG: execute 2019-04-04 15:23:45 -03 [5208-14] DETAIL: parameters: $1 = '2' 2019-04-04 15:23:45 -03 [5208-15] STATEMENT: SELECT * FROM test1 WHERE i = $1::int4 2019-04-04 15:23:45 -03 [5208-16] LOG: duration: 0.053 ms Note that line 5208-8 is duplicative of 5208-3. I think we could improve on this by setting a "logged" flag in the portal; if the Parse logs the statement, then don't include the statement in further lines, otherwise do. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services