bgworker-and-extensions

Generate PostgreSQL background worker and extension hook templates with signal-safe standards.

Updated Jun 1, 2026
One-click install
npx skills add https://github.com/matejformanek/postgres-claude --skill bgworker-and-extensions
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: bgworker-and-extensions
Source: https://github.com/matejformanek/postgres-claude/tree/main/.claude/skills/bgworker-and-extensions
Command: npx skills add https://github.com/matejformanek/postgres-claude --skill bgworker-and-extensions

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill eliminates the complexity and common pitfalls associated with extending PostgreSQL internals, such as improper signal handling, memory leaks, and incorrect hook chaining, which often lead to unstable database extensions.

Core Features & Use Cases

  • Background Worker Lifecycle: Provides a robust procedural guide for registering static and dynamic background workers, including signal handling and latch management.
  • Extension Hook Layering: Offers a canonical pattern for chaining hooks like ProcessUtility_hook and planner_hook to ensure compatibility with other extensions.
  • Use Case: Use this skill when developing a custom PostgreSQL extension that requires a background process for asynchronous tasks or needs to intercept query planning and execution phases.

Quick Start

Use the bgworker-and-extensions skill to generate a signal-safe background worker main function and a hook registration template for your PostgreSQL extension.

Frequently Asked Questions about bgworker-and-extensions

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I register a PostgreSQL background worker in a C extension?

PostgreSQL background worker registration involves implementing a signal-safe main function and following postmaster lifecycle integration patterns. This ensures proper process registration, latch management, and non-blocking signal handling within the backend C environment.

What is the correct way to chain PostgreSQL extension hooks like ProcessUtility_hook?

Chaining PostgreSQL extension hooks like ProcessUtility_hook requires a canonical layering pattern to maintain compatibility with other extensions. Proper hook chaining intercepts query planning and execution phases without causing memory leaks or unstable database behavior.

How do I handle signals safely in a PostgreSQL background worker?

Signal handling in a PostgreSQL background worker must be non-blocking and utilize proper latch usage. By following verified signal-safe coding standards, you can manage asynchronous tasks and background processes without encountering memory leaks or process instability.

Can I intercept query planning with a PostgreSQL extension hook?

Yes, you can intercept query planning by implementing and chaining the planner_hook. This allows your custom PostgreSQL extension to modify or monitor the query execution pipeline while maintaining compatibility with other installed extensions through correct hook architecture.

Why does my PostgreSQL extension cause memory leaks during background processing?

Memory leaks in PostgreSQL extensions often result from improper signal handling and incorrect background worker lifecycle management. Applying verified implementation patterns for latch usage and postmaster integration eliminates these common pitfalls and stabilizes the extension.