Hands-on Lab·PostgreSQL
PostgreSQL Default Privileges and Role Membership
A grant covers the tables that exist when you make it, and nothing created afterwards. ALTER DEFAULT PRIVILEGES fixes the future; a group role fixes the past - and you usually need both.
Roles and Authentication Guide 20 of 47 Advanced
- OSUbuntu 26.04 LTS
- PostgreSQL18.6-0ubuntu0.26.04.1
- Authscram-sha-256
- TimeAbout 16 min
Default privileges are recorded per granting role and per schema. A table created by a different role is not covered, which is the commonest reason they appear not to work.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| db-a01 | 192.168.0.81 | Ubuntu 26.04 LTS | Primary / Source / Replica Set Member 1 | 2 Core | 4 GB | 50 GB |
This guide includes
Use this when a grant stops covering new tables. This matters because a grant applies to what exists at the moment you make it and nothing created afterwards - which is the surprise that produces permission bugs weeks later.
- creating a new table, and watching the existing grant fail to cover it
- granting for the future with
ALTER DEFAULT PRIVILEGES - fixing the past with a group role, since default privileges do nothing retroactively
Before you start
- The
analystrole with its grants from the previous guide.
-
Create a new table and watch the grant not cover it
-
Grant for the future
-
Fix the past with a group role