Re: log bind parameter values on error

From: Alexey Bashtanov <bashtanov(at)imap(dot)cc>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, david(at)pgmasters(dot)net
Subject: Re: log bind parameter values on error
Date: 2019-03-29 14:55:27
Message-ID: 0da3d152-be04-7cfb-56b3-866f24223e69@imap.cc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello and sorry for weeks of silence.

>> Hello Anders and Peter,
>>
>> Thanks for your messages.
>> Please see the new patch version attached.
> In my testing, I couldn't get this patch to do anything. Could you
> please share your testing steps?

Sure. Provided you're in the postgres checkout and you've run make in
src/test/examples/ this should work

CREATE SCHEMA testlibpq3;
SET search_path = testlibpq3;
CREATE TABLE test1_(i int4, t text, b bytea);
INSERT INTO test1_ VALUES(0, '', '');
CREATE VIEW test1 AS SELECT 1/i i, t, b FROM test1_;

-- will log only statement
\! ./src/test/examples/testlibpq3

ALTER SYSTEM SET log_parameters_on_error TO on;
SELECT pg_reload_conf();

-- will log statement with parameters
\! ./src/test/examples/testlibpq3

> I did
>
> postgres -D data --log-parameters-on-error=on
>
> pgbench -i bench
>
> alter table pgbench_accounts alter column aid type smallint;
>
> pgbench -M extended -S -T 10 bench
>
> This will then error out on type overflows, but I don't see any
> parameters being logged:
>
> ERROR: value "62812" is out of range for type smallint
> STATEMENT: SELECT abalance FROM pgbench_accounts WHERE aid = $1;
>
> (In this case the error message contains the parameter value, so it's
> not a very practical case, but it should work, it seems.)
I guess this error occurred /while/ binding, so the parameters probably
weren't yet all bound by the time of error reporting.
That's why the error message came without parameters.

> Meanwhile, I have committed a patch that refactors the ParamListInfo
> initialization a bit, so you don't have to initialize hasTextValues in a
> bunch of places unrelated to your core code. So please rebase your
> patch on that.

Please find rebased patch attached.

I apologize for no reply before: I first thought my patch was really
faulty and knew I wouldn't have time to fix it these days, but it seems
to me it actually works.

Anyway, I don't suppose you manage to review it within the remaining few
days, so I'll rebase it again in the beginning of the next CF.

Best regards,
  Alexey

Attachment Content-Type Size
log_parameters_v007.patch text/x-patch 17.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2019-03-29 15:02:18 Re: monitoring CREATE INDEX [CONCURRENTLY]
Previous Message Tom Lane 2019-03-29 14:45:37 Re: table_privileges view always show object owner as a grantor