Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit013ed0b

Browse files
committed
Add \conninfo command to psql, to show current connection info.
David Christensen. Reviewed by Steve Singer. Some further changes by me.
1 parentb25749c commit013ed0b

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

‎doc/src/sgml/ref/psql-ref.sgml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.245 2010/07/10 00:50:24 rhaas Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.246 2010/07/20 03:54:19 rhaas Exp $
33
PostgreSQL documentation
44
-->
55

@@ -780,6 +780,16 @@ testdb=&gt;
780780
</listitem>
781781
</varlistentry>
782782

783+
<varlistentry>
784+
<term><literal>\conninfo</literal></term>
785+
<listitem>
786+
<para>
787+
Outputs connection information about the current database
788+
connection.
789+
</para>
790+
</listitem>
791+
</varlistentry>
792+
783793
<varlistentry>
784794
<term><literal>\copy { <replaceable class="parameter">table</replaceable> [ ( <replaceable class="parameter">column_list</replaceable> ) ] | ( <replaceable class="parameter">query</replaceable> ) }
785795
{ <literal>from</literal> | <literal>to</literal> }

‎src/bin/psql/command.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2010, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.221 2010/07/06 19:18:59 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.222 2010/07/20 03:54:19 rhaas Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"command.h"
@@ -294,6 +294,22 @@ exec_command(const char *cmd,
294294
free(opt);
295295
}
296296

297+
/* \conninfo -- display information about the current connection*/
298+
elseif (strcmp(cmd,"conninfo")==0)
299+
{
300+
char*db=PQdb(pset.db);
301+
char*host=PQhost(pset.db);
302+
303+
if (!db)
304+
printf("You are not connected.\n");
305+
elseif (host)
306+
printf("You are connected to database \"%s\" on host \"%s\" at port \"%s\" as user \"%s\".\n",
307+
db,host,PQport(pset.db),PQuser(pset.db));
308+
else
309+
printf("You are connected to database \"%s\" via local socket as user \"%s\".\n",
310+
db,PQuser(pset.db));
311+
}
312+
297313
/* \copy */
298314
elseif (pg_strcasecmp(cmd,"copy")==0)
299315
{

‎src/bin/psql/help.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2010, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.159 2010/05/26 19:29:22 rhaas Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.160 2010/07/20 03:54:19 rhaas Exp $
77
*/
88
#include"postgres_fe.h"
99

@@ -162,7 +162,7 @@ slashUsage(unsigned short int pager)
162162
{
163163
FILE*output;
164164

165-
output=PageOutput(86,pager);
165+
output=PageOutput(87,pager);
166166

167167
/* if you add/remove a line here, change the row count above */
168168

@@ -249,6 +249,7 @@ slashUsage(unsigned short int pager)
249249
PQdb(pset.db));
250250
fprintf(output,_(" \\encoding [ENCODING] show or set client encoding\n"));
251251
fprintf(output,_(" \\password [USERNAME] securely change the password for a user\n"));
252+
fprintf(output,_(" \\conninfo display information about current connection\n"));
252253
fprintf(output,"\n");
253254

254255
fprintf(output,_("Operating System\n"));

‎src/bin/psql/tab-complete.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2010, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.200 2010/07/06 19:19:00 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.201 2010/07/20 03:54:19 rhaas Exp $
77
*/
88

99
/*----------------------------------------------------------------------
@@ -636,7 +636,7 @@ psql_completion(char *text, int start, int end)
636636
};
637637

638638
staticconstchar*constbackslash_commands[]= {
639-
"\\a","\\connect","\\C","\\cd","\\copy","\\copyright",
639+
"\\a","\\connect","\\conninfo","\\C","\\cd","\\copy","\\copyright",
640640
"\\d","\\da","\\db","\\dc","\\dC","\\dd","\\dD","\\des","\\deu","\\dew","\\df",
641641
"\\dF","\\dFd","\\dFp","\\dFt","\\dg","\\di","\\dl",
642642
"\\dn","\\do","\\dp","\\drds","\\ds","\\dS","\\dt","\\dT","\\dv","\\du",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp