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
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.
Make sure that you are connected to the correct database when you grant the permissions, as each database has its own schemas.