PostgreSQL 15 Removed CREATE on the public Schema from Ordinary Users

In progress Django

Since PostgreSQL 15, ordinary roles can no longer create tables in the public schema of a database they don't own. The classic setup (create a database, create an app user, GRANT ALL PRIVILEGES ON DATABASE) now ends with permission denied for schema public as soon as the app's first migration runs. Granting on the database was never the same as granting on the schema; older versions just hid it.

Why GRANT ALL ON DATABASE Isn't Enough

GRANT ALL ON DATABASE covers database-level rights only: connecting, creating schemas, creating temporary tables. Creating a table needs CREATE on the schema it goes into. Before version 15, every role had that on public by default. From 15 on, public belongs to the database owner (pg_database_owner) and nobody else gets CREATE automatically.

Fix: Make the App User the Owner

CREATE ROLE appuser WITH LOGIN PASSWORD '...';
CREATE DATABASE appdb OWNER appuser;
ALTER ROLE appuser SET client_encoding TO 'utf8';
ALTER ROLE appuser SET default_transaction_isolation TO 'read committed';
ALTER ROLE appuser SET timezone TO 'UTC';

As owner of the database, appuser owns public through pg_database_owner and can create tables, with no list of grants on tables, sequences and functions to maintain. For an existing database: ALTER DATABASE appdb OWNER TO appuser;.

References

Review cards

Flashcard Why can't ordinary roles create tables in the public schema after PostgreSQL 15?

Because the public schema is owned by the database owner (pg_database_owner) and ordinary roles no longer get the CREATE privilege on it by default.

Flashcard What is the difference between `GRANT ALL PRIVILEGES ON DATABASE` and `CREATE` on the public schema?

GRANT ALL PRIVILEGES ON DATABASE covers database-level rights like connecting and creating schemas, while CREATE on the public schema is needed to create tables within it.

Flashcard What's the simplest fix for 'permission denied for schema public' on PostgreSQL 15 or later?

Make the app user own the database (CREATE DATABASE appdb OWNER appuser, or ALTER DATABASE ... OWNER TO): the owner owns public through pg_database_owner. Otherwise, GRANT CREATE, USAGE ON SCHEMA public while connected to that database.