Repository navigation
Description
Problem to Solve
Serverpod's embedded PostgreSQL is a great addition for local development and testing. However, the current implementation makes it difficult to use custom PostgreSQL builds, particularly when a project requires additional extensions or a different PostgreSQL version.
I identified several related limitations:
- Hardcoded bundle specifications:
publishedBundleSpecsinbundle_spec.dartdefines the supported PostgreSQL versions, bundle revisions, and PostGIS/pgvector versions. Users cannot supply their own specifications through configuration. - Limited download sources:
SERVERPOD_PG_BUNDLE_REPOallows overriding the GitHub repository, but the download URL still follows a fixed GitHub Releases structure. Arbitrary HTTPS URLs are not supported. - Fixed bundle manifest validation:
ServerpodBundleArtifact.validateExtracted()verifies PostgreSQL, revision, platform, PostGIS, and pgvector versions against the predefinedBundleSpec. There is no general mechanism for declaring and validating additional bundled extensions. - Potential cache collisions:
ServerpodBundleArtifact.cacheKeyuses onlyspec.bundleId(<postgres-version>-r<revision>). Different bundles from different sources can therefore share the same cache location. Additionally,BinaryStore.ensure()considers an existing.meta.jsonsufficient for a cache hit without checking whether the cached artifact matches the requested source. - PostgreSQL configuration: Some custom extensions require
shared_preload_libraries, butpostgres_conf_builder.dartcurrently generatesshared_preload_libraries = ''in Serverpod's managed configuration block.
As a result, developers who need a custom PostgreSQL build must continue using an external PostgreSQL with Docker, despite the embedded database functionality already providing most of the necessary infrastructure.
Proposal
I propose adding first-class support for custom embedded PostgreSQL bundles while preserving the existing behavior for official Serverpod bundles.
1. Custom BundleSpec
Allow developers to supply their own bundle specifications without modifying publishedBundleSpecs.
A custom specification should support:
- PostgreSQL version and bundle revision.
- Arbitrary bundled extensions and their versions, rather than a fixed set of extension fields.
- Platform-specific artifacts.
- Validation of declared versions and bundle metadata.
- A unique identity for the custom bundle.
The existing official specifications would remain the default when no custom configuration is provided.
2. Configurable download sources
Extend the existing SERVERPOD_PG_BUNDLE_REPO mechanism to support arbitrary HTTPS download URLs, including GitHub Releases, self-hosted servers, or other artifact repositories.
This could be implemented using environment variables, serverpod config etc...
For example, a custom bundle manifest could conceptually look like:
{
"id": "custom-pg17-textsearch",
"postgres": "17.7.0",
"revision": 1,
"extensions": {
"pg_textsearch": "0.5.0"
},
"artifacts": {
"macos-arm64": {
"url": "https://example.com/postgres-macos-arm64.tar.xz",
"sha256": "<expected-sha256>"
}
}
}This is only an illustrative format, not a suggestion to adopt this exact schema.
3. Source-aware cache identity
Custom bundles should not accidentally share cache entries with official bundles or other custom distributions.
Currently, the cache key is derived from the PostgreSQL version and bundle revision, without incorporating the source or distribution identity.
Possible improvements include:
- Incorporating a custom bundle identifier or namespace into the cache key.
- Optionally incorporating a pinned artifact checksum.
- Validating cached artifact identity before reusing it.
- Preserving backward compatibility with existing official bundle caches.
The existing .meta.json already records source_url and sha256, which could potentially help with validation.
4. Integrity and version validation
Custom bundles should retain the security and verification guarantees of official Serverpod bundles.
Ideally, this includes:
- SHA-256 verification against an explicitly trusted expected checksum.
- Validation of PostgreSQL and declared extension versions against the bundle manifest.
- Validation of platform compatibility.
- Clear errors when the bundle contents do not match the supplied specification.
- Consistent handling of bundle revisions and cache invalidation.
Where practical, validation could also verify installed PostgreSQL binaries and extension metadata rather than relying exclusively on self-declared manifest values.
5. Support extensions requiring preloading
Some extensions require PostgreSQL configuration changes, particularly shared_preload_libraries.
It would be useful to expose a supported way to configure this setting for embedded PostgreSQL, rather than requiring modifications to the generated managed configuration block.
This could also be addressed in a separate issue if it is considered outside the scope of custom bundle distribution.
Backward compatibility
The current official bundle download, caching, validation, and startup behavior should remain unchanged when no custom bundle is configured.
Use Case
In my project, I use PostgreSQL 17 with the pg_textsearch extension for BM25 full-text search.
Currently, I run a custom PostgreSQL Docker image to provide the required extension.
I would like to use Serverpod's embedded PostgreSQL for local development and integration testing while keeping the same PostgreSQL version and extensions.
An ideal workflow would be:
- Build PostgreSQL with the required extensions.
- Package it using a Serverpod-compatible bundle structure.
- Publish the bundle to my own GitHub Releases or another artifact host.
- Declare the custom bundle specification and download source in my project's configuration.
- Run
serverpod startand let Serverpod automatically download, verify, cache, and start the custom PostgreSQL distribution.
This would preserve the main advantages of embedded PostgreSQL.
Alternatives
The following alternatives are currently available:
1. Continue using Docker
2. Install PostgreSQL natively
This avoids Docker but requires developers to install, configure, and manage PostgreSQL and its extensions separately, losing the automatic lifecycle benefits of embedded PostgreSQL.
3. Fork or modify serverpod_embedded_postgres
Developers could modify publishedBundleSpecs, bundle download logic, and PostgreSQL configuration directly. However, this introduces maintenance overhead and makes upgrading Serverpod more complicated.
4. Use the existing SERVERPOD_PG_BUNDLE_REPO override
This is useful for mirrors or compatible custom bundles but does not solve the hardcoded specification, arbitrary URL, extension validation, or cache identity limitations.
SERVERPOD_PG_CACHE_DIR can isolate different distributions manually, but it does not provide automatic cache isolation based on bundle identity.
None of these alternatives provides the same out-of-the-box experience as the official embedded PostgreSQL bundles while supporting custom PostgreSQL distributions.
Additional context
Relevant source code:
[bundle_spec.dart](https://github.com/serverpod/serverpod/blob/main/packages/serverpod_embedded_postgres/lib/src/binary/bundle_spec.dart)— DefinesBundleSpec,publishedBundleSpecs, andbundleSpecFor().[serverpod_bundle.dart](https://github.com/serverpod/serverpod/blob/main/packages/serverpod_embedded_postgres/lib/src/binary/serverpod_bundle.dart)— DefinesSERVERPOD_PG_BUNDLE_REPO, constructs the archive URL, usesspec.bundleIdas the cache key, and validates extracted bundle manifests.[binary_store.dart](https://github.com/serverpod/serverpod/blob/main/packages/serverpod_embedded_postgres/lib/src/binary/binary_store.dart)— Handles downloads, SHA-256 verification, extraction, cache directories, and cache-hit detection.[postgres_conf_builder.dart](https://github.com/serverpod/serverpod/blob/main/packages/serverpod_embedded_postgres/lib/src/cluster/postgres_conf_builder.dart)— Generates the managed PostgreSQL configuration, includingshared_preload_libraries.[PUBLISH.md](https://github.com/serverpod/serverpod/blob/main/packages/serverpod_embedded_postgres/PUBLISH.md)— Documents bundle versioning, revisions, and the publishing process.
The existing BinaryArtifact and BinaryStore abstractions already provide much of the required download, verification, and caching infrastructure, so supporting custom distributions may be possible without fundamentally changing the embedded PostgreSQL architecture.
I'd be interested in working on a PR for this if it's something that serverpod would like to support. I'd appreciate some guidance on the preferred approach before getting started, especially since this touches a critical part of the embedded PostgreSQL infrastructure.
How experienced are you with this library?
Intermediate - Familiar with the basics or have used it in a few projects
Are you interested in working on a PR for this?
- I want to work on this
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsInbox 📫
Activity