Thread: Re: [COMMITTERS] pgsql-server: Have \dn+ show permissions and description

Re: [COMMITTERS] pgsql-server: Have \dn+ show permissions and description

From
Bruce Momjian
Date:
Christopher Kings-Lynne wrote:
> > With \dp having a schema column, how would we display permissions there?
> >
> >        Access privileges for database "test"
> >      Schema | Name | Type  | Access privileges
> >     --------+------+-------+-------------------
> >      public | test | table |
> >     (1 row)
> >
> > I don't think it makes sense to add schema to \dp if it would not
> > normally appear in the \dp display.
> >
> > I figured schema permissions were different enough from table that is
> > belonged under schema, no?  Also, to me view/table/sequence are data
> > storage objects, while schemas seem different.
>
> Don't forget \db for tablespaces as well - that should work the same as
> \dn wrt permissions display.

OK, done and applied:

    test=> \db
           List of tablespaces
        Name    |  Owner   | Location
    ------------+----------+----------
     pg_default | postgres |
     pg_global  | postgres |
     temp       | postgres | /bjm/tmp
    (3 rows)

    test=> \db+
                             List of tablespaces
        Name    |  Owner   | Location |         Access privileges
    ------------+----------+----------+-----------------------------------
     pg_default | postgres |          |
     pg_global  | postgres |          |

Tablespaces, being global, don't have comments so I didn't do that part.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: doc/src/sgml/ref/psql-ref.sgml
===================================================================
RCS file: /cvsroot/pgsql-server/doc/src/sgml/ref/psql-ref.sgml,v
retrieving revision 1.118
diff -c -c -r1.118 psql-ref.sgml
*** doc/src/sgml/ref/psql-ref.sgml    13 Jul 2004 16:48:15 -0000    1.118
--- doc/src/sgml/ref/psql-ref.sgml    15 Jul 2004 03:53:16 -0000
***************
*** 832,837 ****
--- 832,839 ----
          Lists all available tablespaces. If <replaceable
          class="parameter">pattern</replaceable>
          is specified, only tablespaces whose names match the pattern are shown.
+         If <literal>+</literal> is appended to the command name, each object
+         is listed with its associated permissions.
          </para>
          </listitem>
        </varlistentry>
Index: src/bin/psql/command.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/psql/command.c,v
retrieving revision 1.121
diff -c -c -r1.121 command.c
*** src/bin/psql/command.c    13 Jul 2004 16:48:16 -0000    1.121
--- src/bin/psql/command.c    15 Jul 2004 03:53:26 -0000
***************
*** 302,308 ****
                  success = describeAggregates(pattern, show_verbose);
                  break;
              case 'b':
!                 success = describeTablespaces(pattern);
                  break;
              case 'c':
                  success = listConversions(pattern);
--- 302,308 ----
                  success = describeAggregates(pattern, show_verbose);
                  break;
              case 'b':
!                 success = describeTablespaces(pattern, show_verbose);
                  break;
              case 'c':
                  success = listConversions(pattern);
Index: src/bin/psql/describe.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/psql/describe.c,v
retrieving revision 1.102
diff -c -c -r1.102 describe.c
*** src/bin/psql/describe.c    13 Jul 2004 16:48:16 -0000    1.102
--- src/bin/psql/describe.c    15 Jul 2004 03:53:26 -0000
***************
*** 106,112 ****
   * Takes an optional regexp to select particular tablespaces
   */
  bool
! describeTablespaces(const char *pattern)
  {
      PQExpBufferData buf;
      PGresult   *res;
--- 106,112 ----
   * Takes an optional regexp to select particular tablespaces
   */
  bool
! describeTablespaces(const char *pattern, bool verbose)
  {
      PQExpBufferData buf;
      PGresult   *res;
***************
*** 117,126 ****
      printfPQExpBuffer(&buf,
                        "SELECT spcname AS \"%s\",\n"
                        "  pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
!                       "  spclocation AS \"%s\"\n"
!                       "FROM pg_catalog.pg_tablespace\n",
                        _("Name"), _("Owner"), _("Location"));

      processNamePattern(&buf, pattern, false, false,
                         NULL, "spcname", NULL,
                         NULL);
--- 117,133 ----
      printfPQExpBuffer(&buf,
                        "SELECT spcname AS \"%s\",\n"
                        "  pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
!                       "  spclocation AS \"%s\"",
                        _("Name"), _("Owner"), _("Location"));

+     if (verbose)
+         appendPQExpBuffer(&buf,
+             ",\n  spcacl as \"%s\"",
+             _("Access privileges"));
+
+     appendPQExpBuffer(&buf,
+                       "\nFROM pg_catalog.pg_tablespace\n");
+
      processNamePattern(&buf, pattern, false, false,
                         NULL, "spcname", NULL,
                         NULL);
Index: src/bin/psql/describe.h
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/psql/describe.h,v
retrieving revision 1.25
diff -c -c -r1.25 describe.h
*** src/bin/psql/describe.h    13 Jul 2004 16:48:16 -0000    1.25
--- src/bin/psql/describe.h    15 Jul 2004 03:53:26 -0000
***************
*** 14,20 ****
  bool        describeAggregates(const char *pattern, bool verbose);

  /* \db */
! bool        describeTablespaces(const char *pattern);

  /* \df */
  bool        describeFunctions(const char *pattern, bool verbose);
--- 14,20 ----
  bool        describeAggregates(const char *pattern, bool verbose);

  /* \db */
! bool        describeTablespaces(const char *pattern, bool verbose);

  /* \df */
  bool        describeFunctions(const char *pattern, bool verbose);
Index: src/bin/psql/help.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/psql/help.c,v
retrieving revision 1.89
diff -c -c -r1.89 help.c
*** src/bin/psql/help.c    13 Jul 2004 16:48:16 -0000    1.89
--- src/bin/psql/help.c    15 Jul 2004 03:53:26 -0000
***************
*** 211,217 ****
      fprintf(output, _("  \\d{t|i|s|v|S} [PATTERN] (add \"+\" for more detail)\n"
                        "                 list tables/indexes/sequences/views/system tables\n"));
      fprintf(output, _("  \\da [PATTERN]  list aggregate functions\n"));
!     fprintf(output, _("  \\db [PATTERN]  list tablespaces\n"));
      fprintf(output, _("  \\dc [PATTERN]  list conversions\n"));
      fprintf(output, _("  \\dC            list casts\n"));
      fprintf(output, _("  \\dd [PATTERN]  show comment for object\n"));
--- 211,217 ----
      fprintf(output, _("  \\d{t|i|s|v|S} [PATTERN] (add \"+\" for more detail)\n"
                        "                 list tables/indexes/sequences/views/system tables\n"));
      fprintf(output, _("  \\da [PATTERN]  list aggregate functions\n"));
!     fprintf(output, _("  \\db [PATTERN]  list tablespaces (add \"+\" for more detail)\n"));
      fprintf(output, _("  \\dc [PATTERN]  list conversions\n"));
      fprintf(output, _("  \\dC            list casts\n"));
      fprintf(output, _("  \\dd [PATTERN]  show comment for object\n"));