我还是psql的新手,我偶然发现了一个问题。
我有一个用户 admin ,我已授予数据库 mywebsite 的所有权限
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-------------+----------+----------+-------------+-------------+-----------------------
mywebsite | postgres | UTF8 | en_PH.UTF-8 | en_PH.UTF-8 | =Tc/postgres +
| | | | | postgres=CTc/postgres+
| | | | | admin=CTc/postgres
postgres | postgres | UTF8 | en_PH.UTF-8 | en_PH.UTF-8 |
template0 | postgres | UTF8 | en_PH.UTF-8 | en_PH.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_PH.UTF-8 | en_PH.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
这是角色列表
mywebsite=# \du
admin | | {}
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
mywebsite=# \dn+
public | postgres | postgres=UC/postgres+| standard public schema
| | =UC/postgres |
mywebsite=# \d
No relations found.|
我试图检查数据库是否为空
mywebsite=# select count(*)
mywebsite-# from pg_class c
mywebsite-# join pg_namespace s on s.oid = c.relnamespace
mywebsite-# where s.nspname not in ('pg_catalog', 'information_schema')
mywebsite-# and s.nspname not like 'pg_temp%'
mywebsite-# ;
count
-------
36
(1 row)
这会计算非默认 Postgres表格的表格数量。
所以我不知道为什么输出"没有发现任何关系"
答案 0 :(得分:0)
这会计算非默认Postgres表的表数。
很确定没有。你忘记了TOAST桌子。我在新安装的10.1中获得了40分。
但是这应该计算表格,序列和一些其他关系的数量:
select count(*)
from pg_class c
join pg_namespace s on s.oid = c.relnamespace
where s.nspname not in ('pg_catalog', 'information_schema', 'pg_toast')
and s.nspname not like 'pg_temp%'