diff options
| author | Robert Haas | 2010-07-20 03:54:19 +0000 |
|---|---|---|
| committer | Robert Haas | 2010-07-20 03:54:19 +0000 |
| commit | 013ed0bd814218076385de8bb8438e2020abdf50 (patch) | |
| tree | 8ccb44ad89c17df8a9f7f10a65b6340157b91649 /src/bin/psql/command.c | |
| parent | b25749cc64995ae668f6744765169b354a7f43be (diff) | |
Add \conninfo command to psql, to show current connection info.
David Christensen. Reviewed by Steve Singer. Some further changes by me.
Diffstat (limited to 'src/bin/psql/command.c')
| -rw-r--r-- | src/bin/psql/command.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index acc5d35cf93..affdffce1d9 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -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) { |
