mirror of
https://github.com/binwiederhier/ntfy.git
synced 2026-05-09 08:26:00 +02:00
[PR #1648] [MERGED] Add PostgreSQL read-only replica support #1677
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#1677
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/1648
Author: @binwiederhier
Created: 3/11/2026
Status: ✅ Merged
Merged: 3/13/2026
Merged by: @binwiederhier
Base:
main← Head:postgres-replica📝 Commits (8)
f186574WIP: Postgres read-only replicaab33ac7Refineac65df1Move auth queries to primary, redo health check loop85bdfc6Refine, log unhealthy replica1f483dcRemove consts9eaadd7Log270fec5Bump8a34dfeMove things, rename things📊 Changes
26 files changed (+462 additions, -227 deletions)
View changed files
📝
cmd/serve.go(+6 -1)📝
cmd/user.go(+3 -2)📝
db/db.go(+123 -24)📝
db/pg/pg.go(+34 -22)📝
db/test/test.go(+13 -12)➕
db/types.go(+19 -0)➕
db/util.go(+36 -0)📝
docs/config.md(+36 -11)📝
docs/releases.md(+4 -0)📝
go.mod(+24 -24)📝
go.sum(+50 -50)📝
message/cache.go(+15 -13)📝
message/cache_postgres.go(+5 -4)📝
message/cache_sqlite.go(+4 -3)📝
server/config.go(+2 -1)📝
server/server.go(+19 -6)📝
test/server.go(+13 -2)📝
tools/pgimport/main.go(+2 -1)📝
user/manager.go(+17 -17)📝
user/manager_postgres.go(+4 -4)...and 6 more files
📄 Description
Summary
db.DBwrapper that supports routing read queries to PostgreSQL read replicas via round-robin with automatic health checking and fallback to primaryBeginnerinterface soExecTx/QueryTxwork with both*sql.DBand*db.DBReadOnly()--database-replica-urlsflag (opt-in, no behavior change when unconfigured)Configuration
Design
db.DBwraps a primary*sql.DBand optional replicasReadOnly()returns a*sql.DBfrom a healthy replica (round-robin) or falls back to primarydb.NewDB(sqlDB, nil)for uniform typing)Test plan
go test ./...passes (all existing tests, no replicas = ReadOnly returns primary)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.