Re: Augmenting the deadlock message with application_name

From: Karoline Pauls <code(at)karolinepauls(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Karoline Pauls <code(at)karolinepauls(dot)com>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Augmenting the deadlock message with application_name
Date: 2024-05-10 20:10:58
Message-ID: lzHNTJiudGbsP7Gp5m35jDnafS06ZcdKDMDBVrynsREgeJRLVmFuIOuEPM0oW8eXkEwI0VsNTP_tQyUdJpPU08k0OZwobIkts_dIx9D6fGc=@karolinepauls.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Friday, 10 May 2024 at 20:17, Bruce Momjian <bruce(at)momjian(dot)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 affected by 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 transaction 782; 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Maiquel Grassi 2024-05-10 20:58:02 Re: First draft of PG 17 release notes
Previous Message Melanie Plageman 2024-05-10 19:48:24 Re: BitmapHeapScan streaming read user and prelim refactoring