Re: Add new error_action COPY ON_ERROR "log"

From: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: torikoshia <torikoshia(at)oss(dot)nttdata(dot)com>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, jian(dot)universality(at)gmail(dot)com, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>, Alexander Korotkov <aekorotkov(at)gmail(dot)com>
Subject: Re: Add new error_action COPY ON_ERROR "log"
Date: 2024-03-13 14:02:37
Message-ID: CALj2ACU5Mt0O52=Qm=Ojhx=C1aHmzOAWPQR2sVRk+hGRwhGtNg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Mar 13, 2024 at 11:09 AM Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>
> Hmm. This NOTICE is really bugging me. It is true that the clients
> would get more information, but the information is duplicated on the
> server side because the error context provides the same information as
> the NOTICE itself:
> NOTICE: data type incompatibility at line 1 for column "a"
> CONTEXT: COPY aa, line 1, column a: "a"
> STATEMENT: copy aa from stdin with (on_error ignore, log_verbosity verbose);

Yes, if wanted, clients can also get the CONTEXT - for instance, using
'\set SHOW_CONTEXT always' in psql.

I think we can enhance the NOTICE message to include the column value
(just like CONTEXT message is showing) and leverage relname_only to
emit only the relation name in the CONTEXT message.

/*
* We suppress error context information other than the relation name,
* if one of the operations below fails.
*/
Assert(!cstate->relname_only);
cstate->relname_only = true;

I'm attaching the v8 patch set implementing the above idea. With this,
[1] is sent to the client, [2] is sent to the server log. This
approach not only reduces the duplicate info in the NOTICE and CONTEXT
messages, but also makes it easy for users to get all the necessary
info in the NOTICE message without having to set extra parameters to
get CONTEXT message.

Another idea is to move even the table name to NOTICE message and hide
the context with errhidecontext when we emit the new NOTICE messages.

Thoughts?

[1]
NOTICE: data type incompatibility at line 2 for column n: "a"
NOTICE: data type incompatibility at line 3 for column k: "3333333333"
NOTICE: data type incompatibility at line 4 for column m: "{a, 4}"
NOTICE: data type incompatibility at line 5 for column n: ""
NOTICE: data type incompatibility at line 7 for column m: "a"
NOTICE: data type incompatibility at line 8 for column k: "a"
NOTICE: 6 rows were skipped due to data type incompatibility
COPY 3

[2]
2024-03-13 13:49:14.138 UTC [1330270] NOTICE: data type
incompatibility at line 2 for column n: "a"
2024-03-13 13:49:14.138 UTC [1330270] CONTEXT: COPY check_ign_err
2024-03-13 13:49:14.138 UTC [1330270] NOTICE: data type
incompatibility at line 3 for column k: "3333333333"
2024-03-13 13:49:14.138 UTC [1330270] CONTEXT: COPY check_ign_err
2024-03-13 13:49:14.138 UTC [1330270] NOTICE: data type
incompatibility at line 4 for column m: "{a, 4}"
2024-03-13 13:49:14.138 UTC [1330270] CONTEXT: COPY check_ign_err
2024-03-13 13:49:14.138 UTC [1330270] NOTICE: data type
incompatibility at line 5 for column n: ""
2024-03-13 13:49:14.138 UTC [1330270] CONTEXT: COPY check_ign_err
2024-03-13 13:49:14.138 UTC [1330270] NOTICE: data type
incompatibility at line 7 for column m: "a"
2024-03-13 13:49:14.138 UTC [1330270] CONTEXT: COPY check_ign_err
2024-03-13 13:49:14.138 UTC [1330270] NOTICE: data type
incompatibility at line 8 for column k: "a"
2024-03-13 13:49:14.138 UTC [1330270] CONTEXT: COPY check_ign_err
2024-03-13 13:49:14.138 UTC [1330270] NOTICE: 6 rows were skipped due
to data type incompatibility

--
Bharath Rupireddy
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Attachment Content-Type Size
v8-0001-Add-LOG_VERBOSITY-option-to-COPY-command.patch application/octet-stream 9.5 KB
v8-0002-Add-detailed-info-when-COPY-skips-soft-errors.patch application/octet-stream 7.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2024-03-13 14:07:55 Re: Regarding the order of the header file includes
Previous Message Teodor Sigaev 2024-03-13 13:40:38 Re: type cache cleanup improvements