From 013ed0bd814218076385de8bb8438e2020abdf50 Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Tue, 20 Jul 2010 03:54:19 +0000 Subject: Add \conninfo command to psql, to show current connection info. David Christensen. Reviewed by Steve Singer. Some further changes by me. --- src/bin/psql/command.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/bin/psql/command.c') 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) { -- cgit v1.2.3