【问题标题】:Postrgresql - No Relations FoundPostgres - 未找到任何关系
【发布时间】:2018-01-03 09:52:09
【问题描述】:

我还是 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 表的表数。

所以我不知道为什么它会输出“No Relations found”

【问题讨论】:

    标签: postgresql


    【解决方案1】:

    这会计算不是默认 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%'
    

    【讨论】:

      猜你喜欢
      • 2015-07-25
      • 1970-01-01
      • 2021-07-19
      • 2017-04-29
      • 1970-01-01
      • 2013-03-18
      • 1970-01-01
      • 2020-03-05
      相关资源
      最近更新 更多