Learning center

Find why a new PostgreSQL table missed a default grant

Check which role actually created the table. At object creation, PostgreSQL applies the default privileges of the current creating role. It does not inherit other roles' default privileges.

In a fictional reporting database, report_ddl has default privileges that give report_reader SELECT on future tables. A migration connected as migration_login and omitted the expected role switch. Its new table lacks the grant. In psql, inspect \ddp for the applicable default privileges and \dp reporting.monthly_sales for the current table's grants. Read the migration execution record to verify which role created the table. The table's current owner is a clue, since ownership can change later. ALTER DEFAULT PRIVILEGES ยท psql meta-commands

Repair the existing table's grant only where approved. Fix the creating role in the migration path or its defaults for future tables. A change to default privileges does not update existing tables.

Trace another denied request.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading