connection_limits
connection_limits · Enforce connection quotas by user, database, source IP or hostname, including combined rules.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100057 | connection_limits | connection_limits | 1.0.0 | ADMIN | BSD-2-Clause | C |
PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18
Usage
Sources:
connection_limits enforces concurrent-connection quotas by database name, role name, client address, or a combination of those fields. It is useful when PostgreSQL’s built-in role and database connection limits are not expressive enough.
Server configuration
The library must reserve shared memory during server startup. Add it to the preload list, optionally define defaults, and restart PostgreSQL:
Specific rules are read from PGDATA/pg_limits.conf. The mask column is optional, and all acts as a wildcard:
After installing the SQL extension, inspect counters or reload the rule file with:
The preload setting and shared-memory allocation still require a restart. The SQL reload function only rereads rules after the library is active.
Caveats
- Superuser connections are counted but not rejected. They can therefore consume a quota and prevent ordinary roles from connecting.
- Rules are keyed by the database and role names supplied during login, not by object identifiers. Update the rule file after a rename.
- File rules override the per-database, per-user, and per-IP defaults. Review overlapping rules carefully.
- The install SQL leaves
connection_limits_reload()executable byPUBLIC, and the C function performs no superuser check before replacing shared rules. Revoke that privilege from untrusted roles; otherwise any database user can trigger rule reloads. - Prefer PostgreSQL’s built-in CONNECTION LIMIT for simple per-role or per-database quotas. This extension uses server hooks and old internal APIs, and upstream provides no current major-version compatibility matrix.