You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在PostgreSQL 15服务器新建用户和数据库后无法在public模式建表

PostgreSQL 15 远程连接后无法在public模式创建表的问题

环境与已完成操作

  • 系统:Debian 11
  • PostgreSQL版本:15

已完成的配置步骤:

  1. 修改postgresql.conf开启远程监听:
    listen_addresses = '*'
    
  2. 创建目标数据库和用户:
    su postgres psql
    
    postgres=# create database exampledomain;
    postgres=# create user exampledomain with encrypted password 'mypassword';
    postgres=# grant all privileges on database exampledomain to exampledomain;
    
  3. 修改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及之前是默认授予的),因此需要手动为用户添加对应权限:

  1. 切换到postgres用户进入psql终端:
    su postgres psql
    
  2. 连接到目标数据库:
    \c exampledomain
    
  3. 授予用户在public模式的创建权限:
    GRANT CREATE ON SCHEMA public TO exampledomain;
    
    若需要让用户能访问该模式下已存在的对象,可额外执行:
    GRANT USAGE ON SCHEMA public TO exampledomain;
    

执行完成后,用户即可正常在public模式下创建表。

内容的提问来源于stack exchange,提问作者Ar_

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 08:03:01