Skip to content

feat: require shared_preload_libraries for pg_textsearch#235

Merged
tjgreen42 merged 5 commits intomainfrom
require-shared-preload-libraries
Feb 25, 2026
Merged

feat: require shared_preload_libraries for pg_textsearch#235
tjgreen42 merged 5 commits intomainfrom
require-shared-preload-libraries

Conversation

@tjgreen42
Copy link
Copy Markdown
Collaborator

@tjgreen42 tjgreen42 commented Feb 19, 2026

Summary

  • Enforce loading via shared_preload_libraries to prevent fatal ShmemIndex entry size is wrong errors when the .so is replaced during deployment without a server restart
  • Remove lazy init fallbacks in registry.c that were the previous workaround for not requiring preloading
  • Update all test infrastructure (Makefile, shell scripts, CI workflows) to configure shared_preload_libraries with the versioned library name

Context

pg_textsearch uses Postgres shared memory (ShmemInitStruct) for its index registry. Without shared_preload_libraries, each backend loads the .so independently via dlopen. If the .so file is replaced on disk (e.g., during a deployment) without restarting Postgres, different backends get different code, causing a fatal ShmemIndex entry size is wrong error. Requiring shared_preload_libraries ensures all backends use the same .so (inherited from the postmaster via fork), eliminating this class of bugs.

Testing

  • All 47 SQL regression tests pass
  • make format-check passes
  • Error message verified when extension not in shared_preload_libraries

@tjgreen42 tjgreen42 force-pushed the require-shared-preload-libraries branch 2 times, most recently from d852e41 to e4b88d1 Compare February 19, 2026 23:46
Without shared_preload_libraries, each backend loads the .so
independently via dlopen. If the .so file is replaced on disk (e.g.,
during a deployment) without restarting Postgres, different backends
get different code, causing a fatal ShmemIndex entry size mismatch.

Requiring shared_preload_libraries ensures all backends use the same
.so inherited from the postmaster via fork, eliminating this class of
bugs.

Changes:
- Add check in _PG_init() that errors if not loaded during
  shared_preload_libraries processing
- Remove lazy init fallbacks in registry.c (tp_registry_get_dsa and
  tp_registry_is_registered)
- Update all test infrastructure: Makefile test-local, shell scripts
  (concurrency.sh, recovery.sh, segment.sh, cic.sh), and all CI
  workflows (ci, coverage, sanitizer, nightly-stress, benchmark,
  upgrade-tests)
- Update CLAUDE.md to document the requirement
@tjgreen42 tjgreen42 force-pushed the require-shared-preload-libraries branch from e4b88d1 to 9bc6483 Compare February 24, 2026 23:37
The revert of versioned shared library filenames (#238) removed the
PG_TEXTSEARCH_LIB_NAME macro, breaking the shared_preload_libraries
check added in the previous commit.
Add the shared_preload_libraries configuration step to the README
Getting Started section. Update CLAUDE.md to remove stale reference
to versioned library name and note that a server restart is needed
after updating the binary during development.
After the revert of versioned shared library filenames (#238), the
library is just pg_textsearch.so. Update all CI workflows and shell
test scripts that were still constructing the versioned name.
v0.1.0 extension SQL references functions (e.g., bm25_get_current_score)
that no longer exist in the current binary. This test was previously
passing on main only because the versioned shared_preload_libraries name
failed silently, allowing the old SQL to load without the C library.
With shared_preload_libraries now enforced, this path is no longer viable.

Upgrades from v0.2.0+ continue to be tested in test-upgrades.
@tjgreen42 tjgreen42 marked this pull request as ready for review February 25, 2026 23:21
@tjgreen42 tjgreen42 merged commit 4a9aaf2 into main Feb 25, 2026
29 checks passed
@tjgreen42 tjgreen42 deleted the require-shared-preload-libraries branch February 25, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant