在PostgreSQL 15服务器新建用户和数据库后无法在public模式建表
PostgreSQL 15 远程连接后无法在public模式创建表的问题
环境与已完成操作
- 系统:Debian 11
- PostgreSQL版本:15
已完成的配置步骤:
- 修改
postgresql.conf开启远程监听:listen_addresses = '*' - 创建目标数据库和用户:
su postgres psqlpostgres=# create database exampledomain; postgres=# create user exampledomain with encrypted password 'mypassword'; postgres=# grant all privileges on database exampledomain to exampledomain; - 修改
pg_hba.conf允许该用户远程连接:host exampledomain exampledomain 0.0.0.0/0 md5
问题现象
使用exampledomain用户成功连接数据库后,执行如下建表语句:
CREATE TABLE public.newtable ( id varchar NULL );
收到错误提示:
ERROR: permission denied for schema public Position: 14
旧版PostgreSQL中执行上述步骤即可正常创建表,请问PostgreSQL 15是否需要额外操作?
解决方法
PostgreSQL 15调整了默认权限规则:默认不再将public模式的CREATE权限授予PUBLIC角色(旧版本如14及之前是默认授予的),因此需要手动为用户添加对应权限:
- 切换到postgres用户进入psql终端:
su postgres psql - 连接到目标数据库:
\c exampledomain - 授予用户在public模式的创建权限:
若需要让用户能访问该模式下已存在的对象,可额外执行:GRANT CREATE ON SCHEMA public TO exampledomain;GRANT USAGE ON SCHEMA public TO exampledomain;
执行完成后,用户即可正常在public模式下创建表。
内容的提问来源于stack exchange,提问作者Ar_
相关产品推荐
相关产品推荐

