Taking advantage of custom background workers
summary
Custom background workers run continuous daemon code inside Postgres with direct access to databases, shared memory and transactions and they are powerful but risky. The talk demonstrates a working hello world worker that logs every 10s using latches and signal handling, and a working kill_idle worker that kills idle connections (default threshold 5s) built with the bgworker.h APIs, SPI calls, custom GUCs and shared_preload_libraries. Notes include PG_MODULE_MAGIC, restart flags, and that 9.4 introduces max_worker_processes=8 to limit process counts.
AI-written summary · about
chapters (10)
- 0:00Custom background workers intro
- 2:18PostgreSQL background workers
- 8:45Internal structure and APIs
- 12:39Basic worker implementation
- 26:04Best practices and pitfalls
- 37:48Advanced use cases
- 49:23Error handling and stability
- 51:06Real-world: killing idle connections
- 55:42Future of PostgreSQL workers
- 59:16Conclusion








