Re: Augmenting the deadlock message with application_name - Mailing list pgsql-hackers

From Karoline Pauls
Subject Re: Augmenting the deadlock message with application_name
Date
Msg-id lzHNTJiudGbsP7Gp5m35jDnafS06ZcdKDMDBVrynsREgeJRLVmFuIOuEPM0oW8eXkEwI0VsNTP_tQyUdJpPU08k0OZwobIkts_dIx9D6fGc=@karolinepauls.com
Whole thread Raw
In response to Re: Augmenting the deadlock message with application_name  (Bruce Momjian <bruce@momjian.us>)
Responses Re: Augmenting the deadlock message with application_name
Re: Augmenting the deadlock message with application_name
List pgsql-hackers
On Friday, 10 May 2024 at 20:17, Bruce Momjian <bruce@momjian.us> wrote:
>
> log_line_prefix supports application name --- why would you not use
> that?
>

log_line_prefix is effective in the server log. This change is mostly about improving the message sent back to the
client.While the server log is also changed to reflect the client message, it doesn't need to be. 

Additionally, with `%a` added to log_line_prefix, the server log would only contain the application name of the client
affectedby the deadlock, not the application names of all other clients involved in it. 

Example server log with application names (here: a and b) added to the log prefix:

2024-05-10 20:39:58.459 BST [197591] (a)ERROR:  deadlock detected
2024-05-10 20:39:58.459 BST [197591] (a)DETAIL:  Process 197591 (application_name: a) waits for ShareLock on
transaction782; blocked by process 197586. 
        Process 197586 (application_name: b) waits for ShareLock on transaction 781; blocked by process 197591.
        Process 197591, (application_name: a): SELECT * FROM q WHERE id = 2 FOR UPDATE;
        Process 197586, (application_name: b): SELECT * FROM q WHERE id = 1 FOR UPDATE;
2024-05-10 20:39:58.459 BST [197591] (a)HINT:  See server log for query details.
2024-05-10 20:39:58.459 BST [197591] (a)CONTEXT:  while locking tuple (0,2) in relation "q"
2024-05-10 20:39:58.459 BST [197591] (a)STATEMENT:  SELECT * FROM q WHERE id = 2 FOR UPDATE;

All log line prefixes refer to the application a. The message has both a and b.

Anyway, the server log is not the important part here. The crucial UX feature is the client getting application names
back,so  browsing through server logs can be avoided. 

Best,
Karoline



pgsql-hackers by date:

Previous
From: Melanie Plageman
Date:
Subject: Re: BitmapHeapScan streaming read user and prelim refactoring
Next
From: Maiquel Grassi
Date:
Subject: Re: First draft of PG 17 release notes