Re: proposal: psql: show current user in prompt - Mailing list pgsql-hackers

From Corey Huinker
Subject Re: proposal: psql: show current user in prompt
Date
Msg-id CADkLM=dWYrpUK-ODdvx4N8usVshWYEUqdP8JseR02Kmgku_BCQ@mail.gmail.com
Whole thread Raw
In response to proposal: psql: show current user in prompt  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: proposal: psql: show current user in prompt
List pgsql-hackers


On Fri, Feb 3, 2023 at 9:56 AM Pavel Stehule <pavel.stehule@gmail.com> wrote:
Hi

one visitor of p2d2 (Prague PostgreSQL Developer Day) asked if it is possible to show the current role in psql's prompt. I think it is not possible, but fortunately (with some limits) almost all necessary work is done, and the patch is short.

In the assigned patch I implemented a new prompt placeholder %N, that shows the current role name.

(2023-02-03 15:52:28) postgres=# \set PROMPT1 '%n as %N at '%/%=%#
pavel as pavel at postgres=#set role to admin;
SET
pavel as admin at postgres=>set role to default;
SET
pavel as pavel at postgres=#

Comments, notes are welcome.

Regards

Pavel

This patch is cluttered with the BACKEND_PID patch and some guc_tables.c stuff that I don't think is related.

We'd have to document the %N.

I think there is some value here for people who have to connect as several different users (tech support), and need a reminder-at-a-glance whether they are operating in the desired role. It may be helpful in audit documentation as well.

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Fix GUC_NO_SHOW_ALL test scenario in 003_check_guc.pl
Next
From: Pavel Stehule
Date:
Subject: Re: proposal: psql: show current user in prompt