Re: Fix log_line_prefix to display the transaction id (%x) for statements not in a transaction block - Mailing list pgsql-hackers

From Quan Zongliang
Subject Re: Fix log_line_prefix to display the transaction id (%x) for statements not in a transaction block
Date
Msg-id 7201b127-fffb-4142-9e90-fd91dee02731@yeah.net
Whole thread Raw
In response to Re: Fix log_line_prefix to display the transaction id (%x) for statements not in a transaction block  (jian he <jian.universality@gmail.com>)
List pgsql-hackers
A little tweak to the code.
GetTopTransactionIdIfAny() != InvalidTransactionId
changed to
TransactionIdIsValid(GetTopTransactionIdIfAny()


On 2024/1/12 08:51, jian he wrote:
> Hi
...
> with patch:
> src3=# explain(analyze, costs off) select 1 from pg_sleep(10);
> 2024-01-12 08:43:14.750 CST [5739] jian@src3/psql XID:0 LOG:
> duration: 10010.167 ms  plan:
>          Query Text: explain(analyze, costs off) select 1 from pg_sleep(10);
>          Function Scan on pg_sleep  (cost=0.00..0.01 rows=1 width=4)
> (actual time=10010.155..10010.159 rows=1 loops=1)
> 2024-01-12 08:43:14.750 CST [5739] jian@src3/psql XID:0 LOG:
> statement: explain(analyze, costs off) select 1 from pg_sleep(10);
>                                   QUERY PLAN
> -----------------------------------------------------------------------------
>   Function Scan on pg_sleep (actual time=10010.155..10010.159 rows=1 loops=1)
>   Planning Time: 0.115 ms
>   Execution Time: 10010.227 ms
> (3 rows)
This problem does exist in a statement that takes a long time to run.
XID is applied only for the first change tuple. If the user want to see 
it in a single statement log, they have to wait until the statement has 
finished executing. And we don't know how long it will take until the 
statement ends. It is not appropriate to output the log twice because of 
xid. Besides, without parsing log_line_prefix we don't know if the user 
wants to see xid.
Attachment

pgsql-hackers by date:

Previous
From: Sutou Kouhei
Date:
Subject: Re: Make COPY format extendable: Extract COPY TO format implementations
Next
From: Richard Guo
Date:
Subject: Re: set_cheapest without checking pathlist