Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p2dji-0005SJ-AN for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Dec 2022 19:36:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p2djh-0005Uw-5F for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Dec 2022 19:36:13 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p2djg-0005Se-QU for pgsql-hackers@lists.postgresql.org; Tue, 06 Dec 2022 19:36:12 +0000 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p2dje-0000rI-1M for pgsql-hackers@postgresql.org; Tue, 06 Dec 2022 19:36:11 +0000 Received: by mail-pj1-x1035.google.com with SMTP id fa4-20020a17090af0c400b002198d1328a0so2215383pjb.0 for ; Tue, 06 Dec 2022 11:36:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=Z0PPd7op1TZg9ILf7H9OncwQh7sMl2HHNsk+oD8B+xY=; b=i2AHnpH41dgVp0TAys/Lmikq3HngMj8FoS3ZdlWaUPt2ZY5Iwl0BM1XI3Na89JMO2t s7LyxPcHnnkAExerfxRLlnoovGqllkOqN2U7q/+o389tTFscVD8DK4mIAw96Z1mFeXxA jMFqSrfnL0jtTyXrkVgzgFX3uz9OXo7cPSVzlIrQfQc293GJgKWBEBgsxB7hezpXNU9k hNl6nxTbreWbkSXC+XQj+LjCcSBFCzqncKXvZzA0qmCLNcUswvzEw605DCWqxatDp9tV 3ROXMNA+S6PtfJZOFruYxdObAwvahso6CrVlgzAc+f0o3PtGAXxOQN4v578V+DZ+bRsL /mXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Z0PPd7op1TZg9ILf7H9OncwQh7sMl2HHNsk+oD8B+xY=; b=urT4bM89gLLPHoAhViRp6vOzfWojJiVsBZTE+4qrBoVtkdyOZE2/Ejql1vUrMkp4gP xpmadhgeJrqYHOGsGe0ppzC0Pxe7PdOZwpPKRgmKAwl32FemwEy4QVmahBUp1WhB/WtW likHsxvjEPWPJxyWGnHFRZl7EXJ9OETY9reUrn+bx4xqe1GCNF+WMjdd9i7eMHuyQAR7 f/TJmMRaz+PrU0dxlt7htCkZazrzGbVLbj2bQ/bALNnkTSn0zfPVk1zhL5+pthgTp14q mYxqTpuJM+OvtJKYl046G9gV4EhWXcWeG+Ssn9kRv3VMQNmdGAAHeW1PKfeoAWSfk1Zr DmHw== X-Gm-Message-State: ANoB5pnkOoMT3aBDZcaBrmaJB7fvi3eeX4ZOBDQLnbRNNDs2aAqAEPx+ hN8kBLfADUF7Oql+FkhvRD1BztbkYRA= X-Google-Smtp-Source: AA0mqf64wCJVHTk+UtqwlM9VC43+JMZUa71VPRlhlQ7nrugo74OZR1PbbL8RkD1Mjp9JVJpO0zSdCw== X-Received: by 2002:a17:902:82c2:b0:189:a208:d124 with SMTP id u2-20020a17090282c200b00189a208d124mr34965064plz.143.1670355368473; Tue, 06 Dec 2022 11:36:08 -0800 (PST) Received: from nathanxps13 ([50.47.162.83]) by smtp.gmail.com with ESMTPSA id y16-20020a63ce10000000b0047696938911sm10271305pgf.74.2022.12.06.11.36.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 11:36:07 -0800 (PST) Date: Tue, 6 Dec 2022 11:36:06 -0800 From: Nathan Bossart To: pgsql-hackers@postgresql.org Subject: add \dpS to psql Message-ID: <20221206193606.GB3078082@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="gatW/ieO32f1wygP" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --gatW/ieO32f1wygP Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi hackers, As discussed elsewhere [0], \dp doesn't show privileges on system objects, and this behavior is not mentioned in the docs. I've attached a small patch that adds support for the S modifier (i.e., \dpS) and the adjusts the docs. Thoughts? [0] https://postgr.es/m/a2382acd-e465-85b2-9d8e-f9ed1a5a66e9%40postgrespro.ru -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --gatW/ieO32f1wygP Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="add_s_modifier_to_dp.patch" diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index d3dd638b14..406936dd1c 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -1825,14 +1825,16 @@ INSERT INTO tbl1 VALUES ($1, $2) \bind 'first value' 'second value' \g - \dp [ pattern ] + \dp[S] [ pattern ] Lists tables, views and sequences with their associated access privileges. If pattern is specified, only tables, views and sequences whose names match the - pattern are listed. + pattern are listed. By default only user-created objects are shown; + supply a pattern or the S modifier to include system + objects. diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index de6a3a71f8..3520655dc0 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -875,7 +875,7 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd) success = listCollations(pattern, show_verbose, show_system); break; case 'p': - success = permissionsList(pattern); + success = permissionsList(pattern, show_system); break; case 'P': { @@ -2831,7 +2831,7 @@ exec_command_z(PsqlScanState scan_state, bool active_branch) char *pattern = psql_scan_slash_option(scan_state, OT_NORMAL, NULL, true); - success = permissionsList(pattern); + success = permissionsList(pattern, false); free(pattern); } else diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 2eae519b1d..eb98797d67 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -1002,7 +1002,7 @@ listAllDbs(const char *pattern, bool verbose) * \z (now also \dp -- perhaps more mnemonic) */ bool -permissionsList(const char *pattern) +permissionsList(const char *pattern, bool showSystem) { PQExpBufferData buf; PGresult *res; @@ -1121,15 +1121,12 @@ permissionsList(const char *pattern) CppAsString2(RELKIND_FOREIGN_TABLE) "," CppAsString2(RELKIND_PARTITIONED_TABLE) ")\n"); - /* - * Unless a schema pattern is specified, we suppress system and temp - * tables, since they normally aren't very interesting from a permissions - * point of view. You can see 'em by explicit request though, eg with \z - * pg_catalog.* - */ + if (!showSystem && !pattern) + appendPQExpBufferStr(&buf, "AND n.nspname !~ '^pg_'\n"); + if (!validateSQLNamePattern(&buf, pattern, true, false, "n.nspname", "c.relname", NULL, - "n.nspname !~ '^pg_' AND pg_catalog.pg_table_is_visible(c.oid)", + "pg_catalog.pg_table_is_visible(c.oid)", NULL, 3)) goto error_return; diff --git a/src/bin/psql/describe.h b/src/bin/psql/describe.h index bd051e09cb..58d0cf032b 100644 --- a/src/bin/psql/describe.h +++ b/src/bin/psql/describe.h @@ -38,7 +38,7 @@ extern bool describeRoles(const char *pattern, bool verbose, bool showSystem); extern bool listDbRoleSettings(const char *pattern, const char *pattern2); /* \z (or \dp) */ -extern bool permissionsList(const char *pattern); +extern bool permissionsList(const char *pattern, bool showSystem); /* \ddp */ extern bool listDefaultACLs(const char *pattern); --gatW/ieO32f1wygP--