Re: Log a sample of transactions

From: Adrien NAYRAT <adrien(dot)nayrat(at)anayrat(dot)info>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: "Kuroda, Hayato" <kuroda(dot)hayato(at)jp(dot)fujitsu(dot)com>, "'pgsql-hackers(at)lists(dot)postgresql(dot)org'" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Log a sample of transactions
Date: 2019-03-01 18:17:47
Message-ID: e91430fb-6543-e956-00e0-6bad9f60b1af@anayrat.info
Views: Raw Message | Whole Thread | Download mbox
Thread:
Lists: pgsql-hackers

Hello,

On 2/15/19 3:24 PM, Adrien NAYRAT wrote:
> On 2/14/19 9:14 PM, Andres Freund wrote:
>> I wonder if this doesn't need a warning, explaining that using this when
>> there are large transactions could lead to slowdowns.
>
> Yes, I will add some wording

Warning added.

>> It seems pretty weird to have this in postgres.c, given you declared it
>> in xact.h?
>
> Yes, I have to revise my C. I will move it to
> src/backend/access/transam/xact.c

Fixed

>> Why are both of these checked? ISTM once xact_is_sampled is set, we
>> ought not to respect a different value of log_xact_sample_rate for the
>> rest of that transaction.
>
> I added theses checks to allow to disable logging during a sampled
> transaction, per suggestion of Masahiko Sawada:
> https://www.postgresql.org/message-id/CAD21AoD4t%2BhTV6XfK5Yz%3DEocB8oMyJSYFfjAryCDYtqfib2GrA%40mail.gmail.com

I added a comment to explain why transaction logging is rechecked.

>>
>> As far as I can tell xact_is_sampled is not properly reset in case of
>> errors?
>>
>

I am not sure if I should disable logging in case of errors. Actually we
have:

postgres=# set log_transaction_sample_rate to 1;
SET
postgres=# set client_min_messages to 'LOG';
LOG: duration: 0.392 ms statement: set client_min_messages to 'LOG';
SET
postgres=# begin;
LOG: duration: 0.345 ms statement: begin;
BEGIN
postgres=# select 1;
LOG: duration: 0.479 ms statement: select 1;
?column?
----------
1
(1 row)

postgres=# select * from missingtable;
ERROR: relation "missingtable" does not exist
LINE 1: select * from missingtable;
^
postgres=# select 1;
ERROR: current transaction is aborted, commands ignored until end of
transaction block
postgres=# rollback;
LOG: duration: 11390.295 ms statement: rollback;
ROLLBACK

If I reset xact_is_sampled (after the first error inside
AbortTransaction if I am right), "rollback" statement will not be
logged. I wonder if this "statement" should be logged?

If the answer is no, I will reset xact_is_sampled in AbortTransaction.

Patch attached with fix mentioned above, but without xact_is_sampled reset.

Cheers,

Attachment Content-Type Size
log_xact-5.patch text/x-patch 6.6 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Chapman Flack 2019-03-01 18:23:54 Re: Infinity vs Error for division by zero
Previous Message Robert Haas 2019-03-01 18:15:21 Re: Refactoring the checkpointer's fsync request queue