← ClaudeAtlas

extension-developmentlisted

Build a PostgreSQL backend loadable extension (.so / contrib module) — covers the .control file, the foo--1.0.sql install script + foo--1.0--1.1.sql upgrade scripts, PGXS vs meson build wiring, the `_PG_init` entry point, shared_preload_libraries vs LOAD vs CREATE EXTENSION load timing, chained hook installation (ProcessUtility_hook, planner_hook, ExecutorStart_hook), trusted vs untrusted extensions, and SQL-callable C function declarations (PG_FUNCTION_INFO_V1, PG_RETURN_*). Use whenever a PG extension is being written or modified — wiring _PG_init, registering hooks, picking PGXS vs meson, writing install/upgrade SQL, declaring CREATE FUNCTION ... LANGUAGE C, or marking the extension trusted. Skip for VS Code / Chrome / Firefox / Safari / browser extensions, NPM / pip / RubyGems / Cargo packages, IntelliJ / Eclipse plugins, and shell completion scripts.
matejformanek/postgres-claude · ★ 0 · AI & Automation · score 70
Install: claude install-skill matejformanek/postgres-claude
# Building a PostgreSQL extension Skill for shipping a loadable extension — what files to create, what each file declares, the two supported build paths, and the hook/GUC idioms that 90% of real extensions use. Reference doc with a worked end-to-end example (pageinspect): `knowledge/conventions/extension-layout.md`. ## 1. The minimum file set For an extension named `<ext>` at version `1.0`: ``` <ext>.control # metadata read by CREATE EXTENSION <ext>--1.0.sql # SQL objects installed by CREATE EXTENSION <ext> <ext>.c # C code (if there is any) Makefile # PGXS build meson.build # only for in-tree contrib/ builds; out-of-tree # extensions use PGXS (Makefile) ``` Add upgrade scripts as the version moves: `<ext>--1.0--1.1.sql`, `<ext>--1.1--1.2.sql`, … `ALTER EXTENSION <ext> UPDATE` chains them. ### `<ext>.control` Real example, verbatim from `source/contrib/pageinspect/pageinspect.control` [verified-by-code]: ``` # pageinspect extension comment = 'inspect the contents of database pages at a low level' default_version = '1.13' module_pathname = '$libdir/pageinspect' relocatable = true ``` Common fields (see `source/doc/src/sgml/extend.sgml` §"Extension Files" [from-doc]): - `default_version` — version installed when `CREATE EXTENSION` omits `VERSION`. - `module_pathname` — substituted for `MODULE_PATHNAME` in the SQL scripts. - `relocatable = true` — objects can be moved with `ALTER EXTENSION