diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index cae763af0bffd6cf1946daffa171d53c16e78012..b398251745fc2241859bcc00fc5fdcf761f76628 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -1,5 +1,5 @@
 <!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.100 2003/11/29 19:51:39 pgsql Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.101 2003/12/01 22:21:54 momjian Exp $
 PostgreSQL documentation
 -->
 
@@ -904,6 +904,17 @@ testdb=>
       </varlistentry>
 
 
+      <varlistentry>
+        <term><literal>\dg [ <replaceable class="parameter">pattern</replaceable> ]</literal></term>
+        <listitem>
+        <para>
+        Lists all database groups or only those that match <replaceable
+        class="parameter">pattern</replaceable>.
+        </para>
+        </listitem>
+      </varlistentry>
+
+
       <varlistentry>
         <term><literal>\distvS [ <replaceable class="parameter">pattern</replaceable> ]</literal></term>
 
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index fda770f9dc8fa99f133923d571cf7170934d6ac0..67d0ad7b3b7d764d3656e16a273be10fc46a362a 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2003, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.107 2003/12/01 22:14:40 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.108 2003/12/01 22:21:54 momjian Exp $
  */
 #include "postgres_fe.h"
 #include "command.h"
@@ -359,6 +359,9 @@ exec_command(const char *cmd,
 			case 'f':
 				success = describeFunctions(pattern, show_verbose);
 				break;
+			case 'g':
+				success = describeGroups(pattern);
+				break;
 			case 'l':
 				success = do_lo_list();
 				break;
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 327dd69a3ce63f8bdddf08744cefda851fa6b562..66a7d7b5d23a61397339c8a3f6ed7dfe6a0899e5 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2003, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.89 2003/12/01 22:11:06 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.90 2003/12/01 22:21:54 momjian Exp $
  */
 #include "postgres_fe.h"
 #include "describe.h"
@@ -1276,12 +1276,13 @@ describeUsers(const char *pattern)
 			"       WHEN u.usesuper THEN CAST('%s' AS pg_catalog.text)\n"
 		 "       WHEN u.usecreatedb THEN CAST('%s' AS pg_catalog.text)\n"
 					  "       ELSE CAST('' AS pg_catalog.text)\n"
-					  "  END AS \"%s\"\n"
+					  "  END AS \"%s\",\n"
+					  "  ARRAY(SELECT g.groname FROM pg_catalog.pg_group g WHERE u.usesysid = ANY(g.grolist)) as \"%s\"\n"
 					  "FROM pg_catalog.pg_user u\n",
 					  _("User name"), _("User ID"),
 					  _("superuser, create database"),
 					  _("superuser"), _("create database"),
-					  _("Attributes"));
+					  _("Attributes"), _("Groups"));
 
 	processNamePattern(&buf, pattern, false, false,
 					   NULL, "u.usename", NULL, NULL);
@@ -1303,6 +1304,46 @@ describeUsers(const char *pattern)
 }
 
 
+/*
+ * \dg
+ *
+ * Describes groups.
+ */
+bool
+describeGroups(const char *pattern)
+{
+	PQExpBufferData buf;
+	PGresult   *res;
+	printQueryOpt myopt = pset.popt;
+
+	initPQExpBuffer(&buf);
+
+	printfPQExpBuffer(&buf,
+					  "SELECT g.groname AS \"%s\",\n"
+					  "  g.grosysid AS \"%s\"\n"
+					  "FROM pg_catalog.pg_group g\n",
+					  _("Group name"), _("Group ID"));
+
+	processNamePattern(&buf, pattern, false, false,
+					   NULL, "g.groname", NULL, NULL);
+
+	appendPQExpBuffer(&buf, "ORDER BY 1;");
+
+	res = PSQLexec(buf.data, false);
+	termPQExpBuffer(&buf);
+	if (!res)
+		return false;
+
+	myopt.nullPrint = NULL;
+	myopt.title = _("List of database groups");
+
+	printQuery(res, &myopt, pset.queryFout);
+
+	PQclear(res);
+	return true;
+}
+
+
 /*
  * listTables()
  *
diff --git a/src/bin/psql/describe.h b/src/bin/psql/describe.h
index e5c9460e9f1bc2143053cda61d4682b5c4586498..acc841a02b21a141aa0eccb5f3fe73c59ec3a20c 100644
--- a/src/bin/psql/describe.h
+++ b/src/bin/psql/describe.h
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2003, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/describe.h,v 1.22 2003/11/29 19:52:06 pgsql Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/describe.h,v 1.23 2003/12/01 22:21:54 momjian Exp $
  */
 #ifndef DESCRIBE_H
 #define DESCRIBE_H
@@ -25,6 +25,9 @@ bool		describeOperators(const char *pattern);
 /* \du */
 bool		describeUsers(const char *pattern);
 
+/* \dg */
+bool		describeGroups(const char *pattern);
+
 /* \z (or \dp) */
 bool		permissionsList(const char *pattern);
 
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 168ddf371606c4298ed9a2f035098548a7d4550b..f36c71a56d9688fa842cb599430ee916836de784 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2003, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.82 2003/11/29 19:52:06 pgsql Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.83 2003/12/01 22:21:54 momjian Exp $
  */
 #include "postgres_fe.h"
 #include "common.h"
@@ -216,6 +216,7 @@ slashUsage(unsigned short int pager)
 	fprintf(output, _("  \\dd [PATTERN]  show comment for object\n"));
 	fprintf(output, _("  \\dD [PATTERN]  list domains\n"));
 	fprintf(output, _("  \\df [PATTERN]  list functions (add \"+\" for more detail)\n"));
+	fprintf(output, _("  \\dg [PATTERN]  list groups\n"));
 	fprintf(output, _("  \\dn [PATTERN]  list schemas\n"));
 	fprintf(output, _("  \\do [NAME]     list operators\n"));
 	fprintf(output, _("  \\dl            list large objects, same as \\lo_list\n"));
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index b6ae2ce8659cc89de1867707436c88822471a949..955e70deb8b471e6687ca646206466089a82731d 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2003, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.96 2003/12/01 22:14:40 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.97 2003/12/01 22:21:54 momjian Exp $
  */
 
 /*----------------------------------------------------------------------
@@ -576,7 +576,7 @@ psql_completion(char *text, int start, int end)
 
 	static const char * const backslash_commands[] = {
 		"\\a", "\\connect", "\\C", "\\cd", "\\copy", "\\copyright",
-		"\\d", "\\da", "\\dc", "\\dC", "\\dd", "\\dD", "\\df", "\\di",
+		"\\d", "\\da", "\\dc", "\\dC", "\\dd", "\\dD", "\\df", "\\dg", "\\di",
 		"\\dl", "\\dn", "\\do", "\\dp", "\\ds", "\\dS", "\\dt", "\\dT",
 		"\\dv", "\\du",
 		"\\e", "\\echo", "\\encoding",