User/Role
In this document, “user” refers to a logical object within a database cluster created with
CREATE USER/ROLE.
In PostgreSQL, users belong to the database cluster, rather than a specific database. Create business users before you create business databases.
Pigsty defines roles and users through two config parameters:
pg_default_roles: Define globally shared roles and userspg_users: Define business users and roles at cluster level
The first parameter defines roles and users shared across the environment. The second defines business roles and users for one cluster. Both parameters use arrays of user definition objects. Pigsty creates users and roles in array order. Thus, a later user can belong to an earlier role.
By default, all users marked with pgbouncer: true are added to the Pgbouncer connection pool user list.
Define Users
Example from Pigsty demo pg-meta cluster:
Each user or role definition is an object.
Only name is required:
User-level pool quota is consistently defined by
pool_connlimit(mapped to Pgbouncermax_user_connections).
Parameter Overview
The only required field is name.
It must be a valid username that is unique within the cluster.
All other parameters have defaults.
| Field | Category | Type | Attr | Description |
|---|---|---|---|---|
name | Basic | string | Required | Username, must be valid and unique |
state | Basic | enum | Optional | State: create (default), absent |
password | Basic | string | Mutable | User password, plaintext or hash |
comment | Basic | string | Mutable | User comment |
login | Privilege | bool | Mutable | Can login, default true |
superuser | Privilege | bool | Mutable | Is superuser, default false |
createdb | Privilege | bool | Mutable | Can create databases, default false |
createrole | Privilege | bool | Mutable | Can create roles, default false |
inherit | Privilege | bool | Mutable | Inherit role privileges, default true |
replication | Privilege | bool | Mutable | Can replicate, default false |
bypassrls | Privilege | bool | Mutable | Bypass RLS, default false |
connlimit | Privilege | int | Mutable | Connection limit, -1 unlimited |
expire_in | Validity | int | Mutable | Expire N days from now (priority) |
expire_at | Validity | string | Mutable | Expiration date, YYYY-MM-DD format |
roles | Role | array | Additive | Roles array, string or object format |
parameters | Params | object | Mutable | Role-level parameters |
pgbouncer | Pool | bool | Mutable | Add to connection pool, default false |
pool_mode | Pool | enum | Mutable | Pool mode: transaction (default) |
pool_connlimit | Pool | int | Mutable | Pool user max connections |
Parameter Details
name
This required string specifies the username. The username must be unique within the cluster.
Use a valid PostgreSQL identifier that matches ^[a-z_][a-z0-9_]{0,62}$.
Start with a lowercase letter or underscore.
Use only lowercase letters, digits, and underscores.
The maximum length is 63 characters.
state
Enum for user operation: create or absent. Default create.
| State | Description |
|---|---|
create | Default, create user, update if exists |
absent | Delete user with DROP ROLE |
Pigsty prevents deletion of these system users with state: absent to prevent cluster failure:
postgres: Database superuserreplicator: Replication user (orpg_replication_username)dbuser_dba: Admin user (orpg_admin_username)dbuser_monitor: Monitor user (orpg_monitor_username)
password
This mutable string specifies the user password. Users without a password cannot log in with password authentication.
Password can be:
| Format | Example | Description |
|---|---|---|
| Plaintext | DBUser.Meta | Not recommended, logged to config |
| SCRAM-SHA-256 | SCRAM-SHA-256$4096:xxx$yyy:zzz | Recommended, PG10+ default |
| MD5 hash | md5... | Legacy compatibility |
When Pigsty sets a password, it temporarily disables logging to prevent password disclosure:
To generate SCRAM-SHA-256 hash:
comment
String, mutable. User comment, defaults to business user {name}.
Pigsty sets the comment with COMMENT ON ROLE.
Special characters are supported, and Pigsty automatically escapes quotes.
login
This mutable Boolean controls login access.
The default is true.
Set false to create a Role rather than a user.
Roles usually group permissions.
In PostgreSQL, CREATE USER equals CREATE ROLE ... LOGIN.
superuser
This mutable Boolean controls superuser privileges.
The default is false.
Superusers have full database privileges. They bypass all permission checks.
Pigsty provides a default superuser through pg_admin_username (dbuser_dba).
Do not create additional superusers unless necessary.
createdb
This mutable Boolean controls permission to create databases.
The default is false.
Some applications, such as Gitea and Odoo, may require the CREATEDB privilege for their administration users.
createrole
This mutable Boolean controls permission to create other roles.
The default is false.
Users with CREATEROLE can create, modify, and delete other roles that are not superusers.
inherit
This mutable Boolean controls automatic inheritance of privileges from roles to which the user belongs.
The default is true.
If you set false, use an explicit SET ROLE command to use the role privileges.
replication
This mutable Boolean controls permission to start streaming replication.
The default is false.
Usually, only replication users (replicator) need this permission.
Regular users should not have it unless they need logical decoding subscriptions.
bypassrls
This mutable Boolean controls permission to bypass row-level security (RLS) policies.
The default is false.
When enabled, the user can access all rows, even when RLS policies apply. Usually, only administrators need this permission.
connlimit
This mutable integer sets the maximum number of concurrent connections.
The default is -1 (unlimited).
A positive integer limits the number of simultaneous sessions for this user. The limit does not apply to superusers.
expire_in
This mutable integer sets expiration to N days from the current date.
This parameter takes priority over expire_at.
Each playbook run recalculates the expiration date.
Use this parameter for temporary users that need periodic renewal.
Generates SQL:
expire_at
String, mutable. Expiration date in YYYY-MM-DD format, or special value infinity.
This parameter has lower priority than expire_in.
Use infinity for users that must not expire.
roles
This additive array lists the roles to which the user belongs. Array elements can be strings or objects.
Simple format - strings for role names:
Use objects for more detailed control:
Object Format Parameters:
| Param | Type | Description |
|---|---|---|
name | string | Role name (required) |
state | enum | grant (default) or absent/revoke: control membership |
admin | bool | true: WITH ADMIN OPTION, false: REVOKE ADMIN |
set | bool | PG16+: true: WITH SET TRUE, false: REVOKE SET |
inherit | bool | PG16+: true: WITH INHERIT TRUE, false: REVOKE INHERIT |
PostgreSQL 16+ New Features:
PostgreSQL 16 introduced finer-grained role membership control:
- ADMIN OPTION: Allow granting role to other users
- SET OPTION: Allow using
SET ROLEto switch to this role - INHERIT OPTION: Auto-inherit this role’s privileges
The set and inherit options work only in PG16+.
Earlier versions ignore them and add warning comments.
parameters
This mutable object sets role-level configuration parameters with ALTER ROLE ... SET.
The parameters apply to all sessions for this user.
Use the special value DEFAULT to reset a parameter to its PostgreSQL default.
This value is case-insensitive:
Common role-level params:
| Parameter | Description | Example |
|---|---|---|
work_mem | Query work memory | '64MB' |
statement_timeout | Statement timeout | '30s' |
lock_timeout | Lock wait timeout | '10s' |
idle_in_transaction_session_timeout | Idle transaction timeout | '10min' |
search_path | Schema search path | 'app,public' |
log_statement | Log level | 'ddl' |
temp_file_limit | Temp file size limit | '10GB' |
Query user-level parameters through the pg_db_role_setting system view.
pgbouncer
This mutable Boolean adds the user to the Pgbouncer user list.
The default is false.
For production users that need connection pool access, explicitly set pgbouncer: true.
The default, false, prevents accidental pool access for internal users.
Users with pgbouncer: true are added to /etc/pgbouncer/userlist.txt.
pool_mode
Enum, mutable. User-level pool mode: transaction, session, or statement. Default transaction.
| Mode | Description | Use Case |
|---|---|---|
transaction | Return connection after txn | Most OLTP apps, default |
session | Return connection after session | Apps needing session state |
statement | Return after each statement | Simple stateless queries |
User-level pool params are configured via /etc/pgbouncer/useropts.txt:
pool_connlimit
This mutable integer sets the maximum pool connections for the user.
If you omit it, Pigsty does not generate a user-level override.
The global pgbouncer.ini default of 100 then applies.
PgBouncer uses 0 for unlimited connections.
ACL System
Pigsty provides a built-in access control / ACL model. Assign these default business roles to users as required:
| Role | Privileges | Typical Use Case |
|---|---|---|
dbrole_readwrite | Global read-write | Primary application accounts |
dbrole_readonly | Global read-only | Read-only application access |
dbrole_admin | DDL privileges | Application administrators and table creation |
dbrole_offline | Independent read-only; instance scope controlled by HBA | Ad hoc users, ETL, and analytics |
dbrole_offline does not restrict a user to offline instances by itself.
To apply this restriction, set role: offline on the corresponding HBA rule.
See Offline Role and Instance Isolation.
To define your own ACL system, customize these parameters and templates:
pg_default_roles: System-wide roles and global userspg_default_privileges: Default privileges for new objectspg-init-roles.sql: Role creation SQL templatepg-init-template.sql: Privilege SQL template
Pgbouncer Users
Pigsty enables Pgbouncer as connection pool middleware by default.
Pigsty adds users from pg_users to the Pgbouncer user list only when they have pgbouncer: true.
Users in connection pool are listed in /etc/pgbouncer/userlist.txt:
User-level pool params are maintained in /etc/pgbouncer/useropts.txt:
When you create users, Pigsty reloads the Pgbouncer user list online. The reload does not affect existing connections.
Pgbouncer runs as the same dbsu as PostgreSQL.
The default is the postgres operating system user.
Use the pgb alias to access Pgbouncer administration functions.
Use pgbouncer_auth_query to query authentication data dynamically for pool users.
This parameter removes the need to manage pool users manually.
Related Resources
For user management operations, see User Management.
For user access privileges, see Access Control: Role System.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)