mirror of
https://github.com/postgres/postgres.git
synced 2025-06-30 21:42:05 +03: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:
@ -3,7 +3,7 @@
|
||||
*
|
||||
* 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 "command.h"
|
||||
@ -294,6 +294,22 @@ exec_command(const char *cmd,
|
||||
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 */
|
||||
else if (pg_strcasecmp(cmd, "copy") == 0)
|
||||
{
|
||||
|
Reference in New Issue
Block a user