6

I am using postgresql 15

and I tried running these

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;

but when I run

php artisan migrate --seed

I got

SQLSTATE[42501]: Insufficient privilege: 7 ERROR: permission denied for schema public at character 14 (SQL: create table "migrations" ("id" serial primary key not null, "migration" varchar(255) not null, "batch" integer not null))

What I am missing?

I do make sure .env has correct credentials

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

Checking that i did

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

and

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
brombeer
  • 8,716
  • 5
  • 21
  • 27
Fil
  • 8,225
  • 14
  • 59
  • 85
  • 5
    Try to specify the owner of the database in the same way: ```ALTER DATABASE my_database OWNER TO my_database_user;``` – emrdev Feb 05 '23 at 13:37

1 Answers1

12

You are missing permissions on the schema:

GRANT CREATE ON SCHEMA public TO my_database_user;

You are probably using PostgreSQL v15 or higher. The default permissions on the public schema have changed in v15. Before, the insecure default was to allow everyone (PUBLIC) to create objects in schema public. Now only the database owner can do that, unless you grant extra privileges.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263