set_user
similar to SET ROLE but with added logging
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
set_user | 4.2.0 | SEC | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 7370 | set_user | No | Yes | Yes | Yes | No | No | - |
| Related | pg_permissions login_hook pg_auth_mon pg_session_jwt auth_delay pgaudit pg_roast pg_readonly acl pg_command_fw |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PGDG | 4.2.0 | 1817161514 | set_user | - |
| RPM | PGDG | 4.2.0 | 1817161514 | set_user_$v | - |
| DEB | PGDG | 4.2.0 | 1817161514 | postgresql-$v-set-user | - |
Install
You can install set_user directly. First, make sure the PGDG repository is added and enabled:
Install the extension using pig or apt/yum/dnf:
Install
pig
dnf
apt
Preload:
Create Extension:
Usage
set_user allows switching users and optional privilege escalation with enhanced audit logging. It provides an additional layer of control when unprivileged users must escalate to superuser or object owner roles for maintenance tasks.
Configuration
Add to postgresql.conf:
| Parameter | Default | Description |
|---|---|---|
set_user.block_alter_system | on | Block ALTER SYSTEM when escalated |
set_user.block_copy_program | on | Block COPY PROGRAM when escalated |
set_user.block_log_statement | on | Block SET log_statement; force log_statement=all for superusers |
set_user.superuser_allowlist | * | Roles allowed to escalate to superuser |
set_user.nosuperuser_target_allowlist | * | Roles allowed as non-superuser targets |
set_user.superuser_audit_tag | AUDIT | Tag appended to log_line_prefix on escalation |
Functions
Permission Setup
Behavior on Escalation
When escalating to a superuser role:
- The role transition is logged with a specific notation
ALTER SYSTEMandCOPY PROGRAMare blocked (if configured)log_statementis forced toallfor full audit trail- The
AUDITtag is appended tolog_line_prefix
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)