REVOKE removes a database privilege from a role or group. In PostgreSQL, revoking CONNECT from PUBLIC restricts database access for roles that have not received an explicit grant. section 2.8
Block access to other databases
REVOKE CONNECT ON DATABASE brewery FROM PUBLIC; REVOKE CONNECT ON DATABASE postgres FROM PUBLIC; A role with access to coffee_chain can still connect there, but attempts to connect to brewery or postgres fail with “permission denied for database” and “User does not have CONNECT privilege.” section 2.8
Use REVOKE to:
- Remove inherited access granted through PUBLIC. section 2.8
- Limit a role’s connections to its intended database while retaining explicitly granted access. section 2.8
Listing 2.34 Revoking access on the brewery and postgres databases
REVOKE CONNECT ON DATABASE brewery FROM PUBLIC; REVOKE CONNECT ON DATABASE postgres FROM PUBLIC;
View the complete commands that revoke CONNECT on the brewery and postgres databases. section 2.8
