pgsmith
pgsmith · Evaluate synchronized Flagsmith feature flags inside PostgreSQL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 102446 | pgsmith | pgsmith | 0.1.0 | FEAT | BSD-3-Clause | SQL |
PostgreSQL · 14, 15, 16, 17, 18
| Relationships | |
|---|---|
| Requires | plpgsql |
Usage
Sources:
pgsmith 0.1.0 mirrors Flagsmith configuration into PostgreSQL and evaluates feature flags in SQL. Evaluation uses local snapshots; a separate sync service or optional database-side integrations obtain new configurations. This is an early source release with SQL/PL/pgSQL code and no compiled PostgreSQL library.
Enable and Synchronize
Upstream targets PostgreSQL 14–18 and UTF-8 databases. On a server with the extension files installed:
The control marks it trusted and nonrelocatable. It creates the flagsmith and flagsmith_c schemas; standard installation needs no preload or restart. The four helper roles are created only when the installer has permission to create roles, so verify their existence and grants.
The pgsmith sync command uses a database connection for a role with flagsmith_loader, the Flagsmith API address, and server-side environment keys supplied through private configuration:
The alternative pg_tle installer requires that extension and its administrative permission. RDS/Aurora require pg_tle in their preload configuration; that requirement belongs to the installation route. Optional in-database synchronization needs Supabase Vault, http or pg_net, and pg_cron for scheduling. These are not dependencies of local flag evaluation.
Evaluate Flags
After at least one environment has synchronized:
flagsmith.flags returns feature, enabled, value, variant, reason, and metadata. flagsmith.flag retrieves one flag; flagsmith.value and flagsmith.variant return its value or experiment arm. flagsmith.get_flags evaluates a specified environment or snapshot through the interpreter. Use a MATERIALIZED CTE when one flag evaluation should be shared across a query.
Permissions and Operations
flagsmith_readerevaluates flags,flagsmith_trackerrecords exposures/events,flagsmith_planneradds review access, andflagsmith_loaderchanges served configuration. Nothing is granted toPUBLICby default.- Readers can evaluate arbitrary identities and traits. Do not directly grant that role to Supabase
anonorauthenticatedfor row-security decisions; expose a restricted wrapper bound to the authenticated caller. flagsmith.pinandflagsmith.unpincontrol the served snapshot.flagsmith.health,flagsmith.sync_status, andflagsmith.event_statusreport stale configuration and sync/event problems. A sync failure leaves the last accepted configuration serving.- Backups omit derived snapshots and compiled functions. After restore, run
pgsmith sync --onceorflagsmith.sync_tickto rebuild them. Upstream 0.1.0 has no upgrade path yet; the documented reinstall requires resynchronization. - Only the owner may add remote sync sources, because these determine where server keys are sent. Review
pg_netqueue permissions before choosing that transport; the queue can contain credentials.