PostgreSQL用户权限正常却无法在information_schema.tables看到部分表
PostgreSQL 14.5权限问题:用户无法在information_schema.tables中看到全部同schema表
背景信息
- PostgreSQL版本:14.5
- 所有表位于单个非postgres数据库,且均属于
publicschema - 已为
my_user执行以下授权:
GRANT USAGE ON SCHEMA public TO my_user; GRANT SELECT ON ALL TABLES IN SCHEMA public TO my_user; ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO my_user;
- 现象:用户能看到部分表,但有部分表未出现在
information_schema.tables中
已执行的排查步骤
- 验证缺失表的权限配置:
SELECT table_schema, table_name, grantee, privilege_type FROM information_schema.role_table_grants WHERE table_name = 'missing_table';
- 确认用户拥有
publicschema的USAGE权限:
SELECT schema_name, grantee, privilege_type FROM information_schema.role_usage_grants WHERE schema_name = 'public';
- 对比可见表与缺失表的所有者:
SELECT table_schema, table_name, table_owner FROM information_schema.tables WHERE table_name IN ('visible_table', 'missing_table');
- 检查用户角色的所有表权限:
SELECT * FROM information_schema.role_table_grants WHERE grantee = 'my_user';
观察到的关键现象
- 用户可正常查询可见表
- 用户直接查询缺失表(如
SELECT * FROM public.missing_table;)无报错,但这些表未出现在information_schema.tables中
核心疑问
- 同schema、相同授权配置下,为何部分表在
information_schema.tables中不可见? - 如何进一步排查根本原因?
补充说明
- 所有表均属于
publicschema - 当前持有数据库管理员权限,可执行任意必要查询或提供更多细节
内容的提问来源于stack exchange,提问作者dorje
相关产品推荐
相关产品推荐

