pg_simula
pg_simula · Inject WAIT, ERROR, FATAL, or PANIC failures into PostgreSQL operations
Overview
PostgreSQL · 10
Usage
Sources:
pg_simula is a failure-injection extension for PostgreSQL testing. It can delay selected command tags or raise ERROR, FATAL, or PANIC, and it can reject new connections. Use it only on disposable test systems: some actions terminate sessions or crash the server.
Setup and Core Workflow
The library must be preloaded because it installs planner, utility-command, and connection hooks. Add it to shared_preload_libraries, restart PostgreSQL, and then create the extension:
Rules are stored in simula_events(operation, action, sec). The operation is a PostgreSQL command tag. WAIT sleeps for sec; ERROR, FATAL, and PANIC inject the corresponding server error level. clear_all_events() removes every rule. Prefer the management functions over direct table edits, which can recursively trigger simulations.
Connection Refusal and Safety
pg_simula.enabled controls command simulation. pg_simula.connection_refuse rejects new connections with an authorization error; configure and test a recovery path through an existing session or configuration reload before enabling it.
The upstream project reports testing only on Linux with PostgreSQL 10. Hooks and internal APIs are version-sensitive, so do not infer support for later releases. A PANIC rule can force PostgreSQL recovery, and a FATAL rule disconnects the session. Keep the extension, its configuration, and its event table out of production and remove all rules after each test.