A quick note for PostgreSQL extension maintainers: PostgreSQL 18 introduces a new macro: PG_MODULE_MAGIC_EXT
. Use it to name and version your modules. Where your module .c
file likely has:
PG_MODULE_MAGIC;
Or:
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
Change it to something like:
#ifdef PG_MODULE_MAGIC_EXT
PG_MODULE_MAGIC_EXT(.name = "module_name", .version = "1.2.3");
#else
PG_MODULE_MAGIC;
#endif
Replace the name of your module and the version as appropriate. Note that PG_MODULE_MAGIC
was added in Postgres 8.2; if for some reason your module still supports earlier versions, use a nested #ifdef
to conditionally execute it:
#ifdef PG_MODULE_MAGIC_EXT
PG_MODULE_MAGIC_EXT(.name = "module_name", .version = "1.2.3");
#else
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
#endif
If you manage the module version in your Makefile
, as the PGXN Howto suggests, consider renaming the .c
file to .c.in
and changing the Makefile
like so:
-
Replace
.version = "1.2.3"
with.version = "__VERSION__"
-
Add
src/$(EXTENSION).c
toEXTRA_CLEAN
-
Add this
make
target:src/$(EXTENSION).c: src/$(EXTENSION).c.in sed -e 's,__VERSION__,$(EXTVERSION),g' $< > $@
-
If you use Git, add
/src/*.c
to.gitignore
For an example of this pattern, see semver@3526789.
That’s all!