mirror of
https://github.com/postgres/postgres.git
synced 2025-05-29 16:21:20 +03:00
psql: Add more information about service name
This commit adds support for the following items in psql, able to show a service name, when available: - Variable SERVICE. - Substitution %s in PROMPT{1,2,3}. This relies on 4b99fed7541e, that has made the service name available in PGconn for libpq. Author: Michael Banck Reviewed-by: Greg Sabino Mullane Discussion: https://postgr.es/m/6723c612.050a0220.1567f4.b94a@mx.google.com
This commit is contained in:
parent
4b99fed754
commit
477728b5d6
@ -4380,6 +4380,15 @@ bar
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry id="app-psql-variables-service">
|
||||
<term><varname>SERVICE</varname></term>
|
||||
<listitem>
|
||||
<para>
|
||||
The service name, if applicable.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry id="app-psql-variables-shell-error">
|
||||
<term><varname>SHELL_ERROR</varname></term>
|
||||
<listitem>
|
||||
@ -4674,6 +4683,11 @@ testdb=> <userinput>INSERT INTO my_table VALUES (:'content');</userinput>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry id="app-psql-prompting-s">
|
||||
<term><literal>%s</literal></term>
|
||||
<listitem><para>The name of the service.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry id="app-psql-prompting-slash">
|
||||
<term><literal>%/</literal></term>
|
||||
<listitem><para>The name of the current database.</para></listitem>
|
||||
|
@ -4082,6 +4082,7 @@ SyncVariables(void)
|
||||
pset.sversion = PQserverVersion(pset.db);
|
||||
|
||||
SetVariable(pset.vars, "DBNAME", PQdb(pset.db));
|
||||
SetVariable(pset.vars, "SERVICE", PQservice(pset.db));
|
||||
SetVariable(pset.vars, "USER", PQuser(pset.db));
|
||||
SetVariable(pset.vars, "HOST", PQhost(pset.db));
|
||||
SetVariable(pset.vars, "PORT", PQport(pset.db));
|
||||
@ -4115,6 +4116,7 @@ void
|
||||
UnsyncVariables(void)
|
||||
{
|
||||
SetVariable(pset.vars, "DBNAME", NULL);
|
||||
SetVariable(pset.vars, "SERVICE", NULL);
|
||||
SetVariable(pset.vars, "USER", NULL);
|
||||
SetVariable(pset.vars, "HOST", NULL);
|
||||
SetVariable(pset.vars, "PORT", NULL);
|
||||
|
@ -33,6 +33,7 @@
|
||||
* %p - backend pid
|
||||
* %> - database server port number
|
||||
* %n - database user name
|
||||
* %s - service
|
||||
* %/ - current database
|
||||
* %~ - like %/ but "~" when database name equals user name
|
||||
* %w - whitespace of the same width as the most recent output of PROMPT1
|
||||
@ -165,6 +166,11 @@ get_prompt(promptStatus_t status, ConditionalStack cstack)
|
||||
if (pset.db)
|
||||
strlcpy(buf, session_username(), sizeof(buf));
|
||||
break;
|
||||
/* service name */
|
||||
case 's':
|
||||
if (pset.db && PQservice(pset.db))
|
||||
strlcpy(buf, PQservice(pset.db), sizeof(buf));
|
||||
break;
|
||||
/* backend pid */
|
||||
case 'p':
|
||||
if (pset.db)
|
||||
|
Loading…
x
Reference in New Issue
Block a user