pg_readonly
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_readonly | 1.0.6 | ADMIN | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 5120 | pg_readonly | No | Yes | Yes | Yes | No | No | - |
| Related | plan_filter pg_kpart prioritize qos pg_permissions set_user pg_roast pg_command_fw pg_hint_plan |
|---|
Latest PGDG RPM/catalog version is 1.0.6; PIGSTY DEB and source remain on 1.0.5.
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | MIXED | 1.0.6 | 1817161514 | pg_readonly | - |
| RPM | PGDG | 1.0.6 | 1817161514 | pg_readonly_$v | - |
| DEB | PIGSTY | 1.0.5 | 1817161514 | postgresql-$v-pg-readonly | - |
Build
You can build the DEB packages for pg_readonly using pig build:
Install
You can install pg_readonly directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
Install the extension using pig or apt/yum/dnf:
Preload:
Create Extension:
Usage
pg_readonly sets all databases in a PostgreSQL cluster to read-only mode at the SQL level. It must be loaded via shared_preload_libraries. The read-only status is managed in shared memory with a global flag (not persisted across restarts).
Check Read-Only Status
Set Cluster Read-Only
In read-only mode, SELECT statements are allowed (unless they call writing functions), but DML (INSERT, UPDATE, DELETE), DDL (including TRUNCATE), and DCL (GRANT, REVOKE) are blocked:
Note: set_cluster_readonly() terminates all open transactions.
Set Cluster Read-Write
Note: background processes (checkpointer, bgwriter, walwriter, autovacuum) continue running in read-only mode – the restriction is at the SQL statement level only.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)