RE: PostgreSQL debug log doesn't record whole procedure(from receiving request to sending response)

From: "Chen, Yan-Jack (NSB - CN/Hangzhou)" <yan-jack(dot)chen(at)nokia-sbell(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: RE: PostgreSQL debug log doesn't record whole procedure(from receiving request to sending response)
Date: 2021-11-16 05:14:19
Message-ID: a5d754c145e2443db972d9baa8558bbb@nokia-sbell.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
> We can see from this that the server spent 10 seconds in CommitTransaction, so the question is what took so long.
I'd wonder first about end-of-transaction triggers (have you got foreign keys on that table? maybe an event trigger?), and then second about delays in writing/fsyncing WAL (what's the underlying storage? do you have synchronous_commit replication turned on?).

We have the same as your second suspicion. Delays in fsyncing WAL as the backend ceph cluster storage and we see there was significant latency increased during that time. Yes. the synchronous_commit is
on.

fsync | on | Forces synchronization of updates to disk.
synchronous_commit | on | Sets the current transaction's synchronization level.

> [ shrug... ] Sure, we could put an elog(DEBUG) after every line of code in the server, and then high-level debugging logs would be even more impossibly voluminous than they are now. I'd say the existing logging gave you plenty of clue where to look.

Actually, do not need to write log for every line code. The last debug log we can see is for CommitTransaction which state is INPROGRESS. But we can't see when CommitTransaction state is DONE/COMPLETE from the debug log which I think this kind of log is valuable which can help to identify where the delay comes, from server or client from the postgres server debug log only shall be enough without to monitoring and analyzing the TCP message.

[2701833-618d1b70.293a09-173273] 2021-11-13 22:25:58.051 GMT <169.254.0.21 UPDATE> DEBUG: 00000: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 23280/1/1
[2701833-618d1b70.293a09-173274] 2021-11-13 22:25:58.051 GMT <169.254.0.21 UPDATE> LOCATION: ShowTransactionStateRec, xact.c:5333

Best Regards
It always takes longer than you expect,
even when you take into account
----------------------------------------------------------------------------------------------
Yan-Jack Chen (陈雁)
Tel: +8613957141340
Addr: No.567 XinCheng Rd, Binjiang District, Hangzhou, China, 310053

-----Original Message-----
From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Sent: 2021年11月15日 23:09
To: Chen, Yan-Jack (NSB - CN/Hangzhou) <yan-jack(dot)chen(at)nokia-sbell(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: PostgreSQL debug log doesn't record whole procedure(from receiving request to sending response)

"Chen, Yan-Jack (NSB - CN/Hangzhou)" <yan-jack(dot)chen(at)nokia-sbell(dot)com> writes:
> We recently encounter one issue about PostgreSQL ODBC client doesn¡¯t receive response from PostgreSQL server in time (client set 5 seconds timeout) occasionally (1 or 2 times per 24 hours). Both PostgreSQL and its client are deployed in VM against. It took us days to debug where cause the timeout. We enable PostgreSQL server debug log via below configuration.

We can see from this that the server spent 10 seconds in CommitTransaction, so the question is what took so long.
I'd wonder first about end-of-transaction triggers (have you got foreign keys on that table? maybe an event trigger?), and then second about delays in writing/fsyncing WAL (what's the underlying storage? do you have synchronous_commit replication turned on?).

> This mail is to ask why PostgreSQL debug log doesn¡¯t really include the response message delay which may cause misleading why troubleshooting. It looks to me the debug log doesn¡¯t record the whole procedure. If there are some developer options include the missing part but we didn¡¯t enable?

[ shrug... ] Sure, we could put an elog(DEBUG) after every line of code in the server, and then high-level debugging logs would be even more impossibly voluminous than they are now. I'd say the existing logging gave you plenty of clue where to look.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Sanjay Minni 2021-11-16 08:26:51 historical log of data records
Previous Message Saul Perdomo 2021-11-16 01:48:14 Re: Managing major PostgreSQL upgrades