mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-03-07 19:47:50 +08:00
Add \conninfo command to psql, to show current connection info.
David Christensen. Reviewed by Steve Singer. Some further changes by me.
This commit is contained in:
parent
b25749cc64
commit
013ed0bd81
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.245 2010/07/10 00:50:24 rhaas Exp $
|
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.246 2010/07/20 03:54:19 rhaas Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -780,6 +780,16 @@ testdb=>
|
|||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><literal>\conninfo</literal></term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Outputs connection information about the current database
|
||||||
|
connection.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><literal>\copy { <replaceable class="parameter">table</replaceable> [ ( <replaceable class="parameter">column_list</replaceable> ) ] | ( <replaceable class="parameter">query</replaceable> ) }
|
<term><literal>\copy { <replaceable class="parameter">table</replaceable> [ ( <replaceable class="parameter">column_list</replaceable> ) ] | ( <replaceable class="parameter">query</replaceable> ) }
|
||||||
{ <literal>from</literal> | <literal>to</literal> }
|
{ <literal>from</literal> | <literal>to</literal> }
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2000-2010, PostgreSQL Global Development Group
|
* Copyright (c) 2000-2010, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.221 2010/07/06 19:18:59 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.222 2010/07/20 03:54:19 rhaas Exp $
|
||||||
*/
|
*/
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
@ -294,6 +294,22 @@ exec_command(const char *cmd,
|
|||||||
free(opt);
|
free(opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* \conninfo -- display information about the current connection */
|
||||||
|
else if (strcmp(cmd, "conninfo") == 0)
|
||||||
|
{
|
||||||
|
char *db = PQdb(pset.db);
|
||||||
|
char *host = PQhost(pset.db);
|
||||||
|
|
||||||
|
if (!db)
|
||||||
|
printf("You are not connected.\n");
|
||||||
|
else if (host)
|
||||||
|
printf("You are connected to database \"%s\" on host \"%s\" at port \"%s\" as user \"%s\".\n",
|
||||||
|
db, host, PQport(pset.db), PQuser(pset.db));
|
||||||
|
else
|
||||||
|
printf("You are connected to database \"%s\" via local socket as user \"%s\".\n",
|
||||||
|
db, PQuser(pset.db));
|
||||||
|
}
|
||||||
|
|
||||||
/* \copy */
|
/* \copy */
|
||||||
else if (pg_strcasecmp(cmd, "copy") == 0)
|
else if (pg_strcasecmp(cmd, "copy") == 0)
|
||||||
{
|
{
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2000-2010, PostgreSQL Global Development Group
|
* Copyright (c) 2000-2010, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.159 2010/05/26 19:29:22 rhaas Exp $
|
* $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.160 2010/07/20 03:54:19 rhaas Exp $
|
||||||
*/
|
*/
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ slashUsage(unsigned short int pager)
|
|||||||
{
|
{
|
||||||
FILE *output;
|
FILE *output;
|
||||||
|
|
||||||
output = PageOutput(86, pager);
|
output = PageOutput(87, pager);
|
||||||
|
|
||||||
/* if you add/remove a line here, change the row count above */
|
/* if you add/remove a line here, change the row count above */
|
||||||
|
|
||||||
@ -249,6 +249,7 @@ slashUsage(unsigned short int pager)
|
|||||||
PQdb(pset.db));
|
PQdb(pset.db));
|
||||||
fprintf(output, _(" \\encoding [ENCODING] show or set client encoding\n"));
|
fprintf(output, _(" \\encoding [ENCODING] show or set client encoding\n"));
|
||||||
fprintf(output, _(" \\password [USERNAME] securely change the password for a user\n"));
|
fprintf(output, _(" \\password [USERNAME] securely change the password for a user\n"));
|
||||||
|
fprintf(output, _(" \\conninfo display information about current connection\n"));
|
||||||
fprintf(output, "\n");
|
fprintf(output, "\n");
|
||||||
|
|
||||||
fprintf(output, _("Operating System\n"));
|
fprintf(output, _("Operating System\n"));
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2000-2010, PostgreSQL Global Development Group
|
* Copyright (c) 2000-2010, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.200 2010/07/06 19:19:00 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.201 2010/07/20 03:54:19 rhaas Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*----------------------------------------------------------------------
|
/*----------------------------------------------------------------------
|
||||||
@ -636,7 +636,7 @@ psql_completion(char *text, int start, int end)
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const char *const backslash_commands[] = {
|
static const char *const backslash_commands[] = {
|
||||||
"\\a", "\\connect", "\\C", "\\cd", "\\copy", "\\copyright",
|
"\\a", "\\connect", "\\conninfo", "\\C", "\\cd", "\\copy", "\\copyright",
|
||||||
"\\d", "\\da", "\\db", "\\dc", "\\dC", "\\dd", "\\dD", "\\des", "\\deu", "\\dew", "\\df",
|
"\\d", "\\da", "\\db", "\\dc", "\\dC", "\\dd", "\\dD", "\\des", "\\deu", "\\dew", "\\df",
|
||||||
"\\dF", "\\dFd", "\\dFp", "\\dFt", "\\dg", "\\di", "\\dl",
|
"\\dF", "\\dFd", "\\dFp", "\\dFt", "\\dg", "\\di", "\\dl",
|
||||||
"\\dn", "\\do", "\\dp", "\\drds", "\\ds", "\\dS", "\\dt", "\\dT", "\\dv", "\\du",
|
"\\dn", "\\do", "\\dp", "\\drds", "\\ds", "\\dS", "\\dt", "\\dT", "\\dv", "\\du",
|
||||||
|
Loading…
Reference in New Issue
Block a user