在第14个字符处,模式public的权限被拒绝。

9

我正在使用postgresql 15

我尝试运行这些命令

grant all privileges on database my_database to my_database_user;
grant all privileges on all tables in schema public to my_database_user;
grant all privileges on all sequences in schema public to my_database_user;
grant all privileges on all functions in schema public to my_database_user;

但是当我运行

php artisan migrate --seed

时,我得到了以下错误信息:

SQLSTATE[42501]: 权限不足:7 ERROR: 在字符14处拒绝访问模式public (SQL: create table "migrations" ("id" serial primary key not null, "migration" varchar(255) not null, "batch" integer not null))

我缺少什么?

我确保.env文件中的凭据是正确的。

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=my_database
DB_USERNAME=my_database_user
DB_PASSWORD=password

我检查了一下

postgres=# \du my_database_user
            List of roles
  Role name  | Attributes | Member of 
-------------+------------+-----------
 my_database_user |            | {}

并且

postgres=# SELECT * FROM pg_roles;
          rolname          | rolsuper | rolinherit | rolcreaterole | rolcreatedb | rolcanlogin | rolreplication | rolconnlimit | rolpassword | rolvaliduntil | rolbypassrls | rolconfig |  oid  
---------------------------+----------+------------+---------------+-------------+-------------+----------------+--------------+-------------+---------------+--------------+-----------+-------
 my_database_user               | f        | t          | f             | f           | t           | f              |           -1 | ********    |               | f            |           | 16389

8
尝试以相同的方式指定数据库所有者:ALTER DATABASE my_database OWNER TO my_database_user; - emrdev
1个回答

18

您在模式上缺少权限:

GRANT CREATE ON SCHEMA public TO my_database_user;

你可能正在使用 PostgreSQL v15 或更高版本。在 v15 中,public 模式的默认权限已经发生了变化。以前,不安全的默认设置是允许每个人(PUBLIC)在 public 模式中创建对象。现在只有数据库所有者可以这样做,除非你授予额外的权限。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接