mirror of
https://github.com/binwiederhier/ntfy.git
synced 2026-05-09 08:26:00 +02:00
[PR #1619] [MERGED] Add experimental PostgreSQL support as alternative database backend #1666
Labels
No labels
ai-generated
android-app
android-app
android-app
🪲 bug
build
build
dependencies
docs
enhancement
enhancement
🔥 HOT
in-progress 🏃
ios
prio:low
prio:low
pull-request
question
🔒 security
server
server
unified-push
web-app
website
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/ntfy#1666
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/binwiederhier/ntfy/pull/1619
Author: @binwiederhier
Created: 2/20/2026
Status: ✅ Merged
Merged: 3/7/2026
Merged by: @binwiederhier
Base:
main← Head:postgres-support📝 Commits (10+)
e432bf2Rename PostgreSQL table prefix from wp_ to webpush_5331437Unify webpush store tests across SQLite and PostgreSQL backendsa8dcecdRefactor webpush store tests and add coveragebdd2019Manual refinements869b972Manual review4e5f95bRefactor webpush store to eliminate code duplication82e15d8Manual changes60fa50fMerge branch 'main' into postgres-webpush+userb567b4eMerge branch 'main' into postgres-webpush07c3e28Refactor user package to Store interface with PostgreSQL support📊 Changes
76 files changed (+15032 additions, -10219 deletions)
View changed files
📝
.github/workflows/release.yaml(+16 -0)📝
.github/workflows/test.yaml(+17 -3)📝
.gitignore(+2 -0)📝
Makefile(+6 -4)📝
cmd/serve.go(+22 -14)📝
cmd/user.go(+18 -10)➕
db/db.go(+38 -0)➕
db/pg/pg.go(+93 -0)➕
db/test/test.go(+63 -0)📝
docs/config.md(+76 -13)📝
docs/releases.md(+39 -17)📝
go.mod(+6 -2)📝
go.sum(+13 -4)➕
message/cache.go(+590 -0)➕
message/cache_postgres.go(+110 -0)➕
message/cache_postgres_schema.go(+85 -0)➕
message/cache_sqlite.go(+142 -0)➕
message/cache_sqlite_schema.go(+453 -0)➕
message/cache_sqlite_test.go(+292 -0)➕
message/cache_test.go(+829 -0)...and 56 more files
📄 Description
Summary
Add PostgreSQL as an alternative database backend to SQLite for all three database-backed stores: message cache, user/access control, and web push subscriptions. Configured via a single
database-urloption (connection string).Resolves #1114.
What changed
New
database-urlconfig option — when set to a PostgreSQL connection string (e.g.postgres://user:pass@host:5432/ntfy), ntfy uses PostgreSQL for everything instead of SQLite. Thecache-file,auth-file, andweb-push-fileoptions must not be set when using PostgreSQL. Settingdatabase-urlimplicitly enables auth (equivalent to settingauth-file).Architecture
*sql.DBPostgreSQL connection pool is created at startup and shared across all stores, rather than each store managing its own connectionmodel/— shared types (Message,Attachment,Action, etc.) used across packagesmessage/— message cache with SQLite and PostgreSQL backendswebpush/— web push subscription store with SQLite and PostgreSQL backendsdb/— shared database utilities (ExecTx,QueryTx) and PostgreSQL connection helper (db/pg)user/— refactored manager with separate SQLite and PostgreSQL backends (previously had SQLite-only migrations baked in)_sqlite.go/_postgres.gosplit for backend-specific SQL and schema, with shared logic in the main fileTests
server/server_test.go,server/server_*_test.go) run against both SQLite and PostgreSQL viaforEachBackend()test helpermessage/cache_test.go,user/manager_test.go,webpush/store_test.go) also run against both backendstest.yaml) spins up a PostgreSQL 17 service container and setsNTFY_TEST_DATABASE_URLMigration tool
tools/pgimport/— one-off CLI tool to import existing SQLite data (cache, users, web push) into PostgreSQLDocs
pool_max_conns,pool_max_idle_conns,pool_conn_max_lifetime,pool_conn_max_idle_time)Config example
Test plan
pgimportmigration tool🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.