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.4 |
ADMIN
|
BSD 2-Clause
|
SQL
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d--
|
No
|
Yes
|
No
|
Yes
|
no
|
no
|
| Relationships | |
|---|---|
| See Also | pg_readonly
pgaudit
set_user
pg_upless
safeupdate
pgauditlogtofile
credcheck
login_hook
|
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | MIXED
|
1.4 |
18
17
16
15
14
|
pg_permissions |
- |
| RPM | PGDG
|
1.4 |
18
17
16
15
14
|
pg_permissions_$v |
- |
| DEB | PIGSTY
|
1.4 |
18
17
16
15
14
|
postgresql-$v-pg-permissions |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
el8.aarch64
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
el9.x86_64
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
el9.aarch64
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
el10.x86_64
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
el10.aarch64
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
d12.x86_64
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
d12.aarch64
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
d13.x86_64
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
d13.aarch64
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
u22.x86_64
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
u22.aarch64
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
u24.x86_64
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
u24.aarch64
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
Source
pig build pkg pg_permissions; # build debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall this extension with pig:
pig install pg_permissions; # install via package name, for the active PG version
pig install pg_permissions -v 18; # install for PG 18
pig install pg_permissions -v 17; # install for PG 17
pig install pg_permissions -v 16; # install for PG 16
pig install pg_permissions -v 15; # install for PG 15
pig install pg_permissions -v 14; # install for PG 14Create this extension with:
CREATE EXTENSION pg_permissions;Usage
pg_permissions: view object permissions and compare them with the desired state
pg_permissions lets you review actual permissions on database objects and compare them against a desired permission state.
Define Desired Permissions
Insert entries into permission_target to describe what permissions should exist:
INSERT INTO permission_target (role_name, permissions, object_type, schema_name)
VALUES ('appuser', '{SELECT,INSERT,UPDATE,DELETE}', 'TABLE', 'appschema');
INSERT INTO permission_target (role_name, permissions, object_type, schema_name)
VALUES ('appuser', '{USAGE}', 'SCHEMA', 'appschema');
INSERT INTO permission_target (role_name, permissions, object_type, schema_name, object_name)
VALUES ('appuser', '{USAGE}', 'SEQUENCE', 'appschema', 'appseq');Set object_name or column_name to NULL to apply to all objects of that type in the schema.
Find Permission Differences
SELECT * FROM permission_diffs();Returns rows where missing = TRUE (permission should exist but doesn’t) or missing = FALSE (extra permission that shouldn’t exist).
Review Actual Permissions
Available views (all with the same column structure):
database_permissions– permissions on the current databaseschema_permissions– permissions on schemastable_permissions– permissions on tablesview_permissions– permissions on viewscolumn_permissions– permissions on table/view columnsfunction_permissions– permissions on functionssequence_permissions– permissions on sequencesall_permissions– UNION of all above
SELECT * FROM table_permissions WHERE role_name = 'appuser' AND schema_name = 'appschema';Grant/Revoke via Views
The granted column of the permission views is updatable – updating it executes the appropriate GRANT or REVOKE command.
Note: superusers are not shown in the views (they automatically have all permissions).