pg_permissions
pg_permissions : view object permissions and compare them with the desired state
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 5140 | pg_permissions | pg_permissions | 1.6 |
ADMIN | PostgreSQL | SQL |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| ----d-- | No | No | No | Yes | no | no |
| Relationships | |
|---|---|
| See Also | set_user pg_roast pg_readonly pgaudit pg_command_fw acl pg_auditor pg_snakeoil |
Packages
| Linux / PG | PG19 | PG18 | PG17 | PG16 | PG15 |
|---|---|---|---|---|---|
| el8.x86_64 | N/A | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 |
| el8.aarch64 | N/A | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 |
| el9.x86_64 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 |
| el9.aarch64 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 |
| el10.x86_64 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 |
| el10.aarch64 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 |
| d12.x86_64 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 |
| d12.aarch64 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 |
| d13.x86_64 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 |
| d13.aarch64 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 |
| u22.x86_64 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 |
| u22.aarch64 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 |
| u24.x86_64 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 |
| u24.aarch64 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 |
| u26.x86_64 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 |
| u26.aarch64 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 | PGDG 1.4.1 |
Source
github.com/cybertec-postgresql/pg_permissions
pg_permissions-1.6.tar.gz
Install
Make sure PGDG repo available:
Install this extension with pig:
Create this extension with:
Usage
Sources:
pg_permissions compares actual privileges with a desired baseline and can generate or apply corrective grants. Version 1.6 requires PostgreSQL 15 or later. It is pure SQL, requires no preload, and is not relocatable; choose the installation schema initially. The installer needs CREATE privileges there.
Define and Inspect a Baseline
The application role and schema in this example must already exist:
A missing flag of true means a required privilege is absent; false means an extra privilege. A NULL object name covers all objects of the specified type in that schema. Audit scope is limited to targeted objects, managed roles and roles inheriting from them. Use all_permissions for a broader review. Superusers are omitted because they implicitly hold all privileges.
Review Before Applying
permission_fix_sql() returns corrective SQL. permission_apply() defaults to a dry run; permission_apply(false) executes it using the caller’s privileges. The writable granted column on permission views also executes GRANT or REVOKE. Restrict both baseline writes and permission-changing access.
The object views cover databases, schemas, tables, views, columns, functions and sequences. Their source column distinguishes ownership, direct grants, PUBLIC and inherited-role privileges. PUBLIC can be an explicit target grantee. permission_target_snapshot(role, schema) adopts current grants as the baseline; this changes the desired state and should be deliberate.
default_acl_target, default_acl_permissions and default_acl_diffs() separately handle ALTER DEFAULT PRIVILEGES. A default privilege affects future objects; it does not repair existing grants. Baseline tables are readable by PUBLIC but writable only by the extension owner and explicitly authorized roles. role_dependencies() inspects dependencies; role_drop() can reassign ownership and drop roles and warrants a separate review.
Upgrade Boundary
Follow the version-by-version update scripts. For an installed 1.4 database:
Version 1.6 restores the missing 1.2-to-1.3 path. Its 1.5-to-1.6 migration rewrites the baseline: empty permission lists are removed, COLUMN entries without a column become table-level entries, and duplicates are merged. Back up and review the desired state before upgrading. MAINTAIN privileges are rejected before PostgreSQL 17.