mirror of
https://github.com/binwiederhier/ntfy.git
synced 2026-05-09 08:26:00 +02:00
[GH-ISSUE #1114] Postgres database option #786
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#786
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?
Originally created by @brettinternet on GitHub (May 23, 2024).
Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/1114
💡 Postgres!
I use ntfy in a kubernetes environment and would like the option of high availability. I also prefer to use a central DB connection over a volume with a sqlite DB.
💻 ntfy server
@fredrikscode commented on GitHub (Oct 15, 2024):
First result I found while googling "ntfy postgres". I'd love the option of going with postgres or any other type of database server as sqlite bricks over nfs and using volumes is just a very crappy way to deal with storage when running clusters.
@Ittihadyya commented on GitHub (Jan 12, 2025):
Seconding this, I would prefer being able to slot it into already existing infrastructure than having it run its own SQLite database.
@giangduong commented on GitHub (Feb 7, 2025):
+1
@sadorowo commented on GitHub (Jul 4, 2025):
I already use Postgres for various services. It would be nice to connect ntfy to it, instead of having separate databases for no reason.
@gavinmcfall commented on GitHub (Dec 16, 2025):
Also throwing my weight into this one. would love to make this more highly available
@PixNyb commented on GitHub (Dec 25, 2025):
Not being able to use an external database doesn't work in my environment and as such keeps me from enjoying the functionalities that ntfy.sh does very well. Can't wait to see this added
@binwiederhier commented on GitHub (Dec 26, 2025):
Due to popular demand, I may look into this. FYI I did a relatively straight forward PoC a while back: https://github.com/binwiederhier/ntfy/pull/1095
@hugosxm commented on GitHub (Jan 2, 2026):
I use gotify now, with the iOS app that is not working :( I really prefer NTFY and I need pgsql support for that because I run k8s too like many people i guess... So big thank you @binwiederhier ! In the meantime I think I will switch back to ntfy with a local volume !
@binwiederhier commented on GitHub (Feb 17, 2026):
I have started to implement this here: https://github.com/binwiederhier/ntfy/pull/1611/changes
The design is described in the docs:
Does this sound reasonable?
@k8ieone commented on GitHub (Feb 17, 2026):
Yess, looking forward to deploying this! ❤️
@RivenSkaye commented on GitHub (Mar 3, 2026):
Due to how the current
*-filekeys are set up, what would happen if both those keys and a postgres URI are specified?This could be very useful as a migration path for existing users who would prefer PostgreSQL.
For example:
INSERT ... ON CONFLICT DO UPDATEon the PostgreSQL DB and warn the user that they should probably be removing the keys from their config.@binwiederhier commented on GitHub (Mar 3, 2026):
The code is code complete and working well. I have to do a thorough round of regression testing of the entire product before releasing it, but if anyone wants to test it, go wild: https://github.com/binwiederhier/ntfy/pull/1619
It was all done by AI, I have manually reviewed this branch over and over and over again, and I have compared before/after. I also had Cursor created this nice doc for me with a comparison, which I re-did 5-10 times: comparison-2026-03-01.html
--
The ntfy server will not allow both to be set. It's either
database-urlor any of the*-fileoptions.Migration:
I cannot offer a permanent migration path, that would be insane to have to maintain. I had Cursor write a one-off migration tool (pgimport) in the tools folder of that PR. I tested this with the prod ntfy databases and it seems to work. I have not tested that thoroughly though.
Test plan:
database-urlRelease plan:
database-url@binwiederhier commented on GitHub (Mar 7, 2026):
Everyone, please test ntfy 2.18.0 and the Postgres support: https://github.com/binwiederhier/ntfy/releases/tag/v2.18.0
You can learn how to configure it here: https://docs.ntfy.sh/config/#postgresql-experimental
TLDR:
database-url: "postgres://user:pass@host:5432/ntfy"@k8ieone commented on GitHub (Mar 8, 2026):
Switched my instance today without any issues.
I didn't do any imports, fresh start. I didn't have anything persistent on my instance that I wouldn't mind losing.
We'll see how it holds up, my instance is mainly used as a UnifiedPush distributor.
Thank you for your work on this @binwiederhier ❤️
@binwiederhier commented on GitHub (Mar 8, 2026):
Thanks for the feedback @k8ieone
@cmuench commented on GitHub (Mar 8, 2026):
I was able to import two sqlite dbs into my postgtres server with the pgimport tool. Everything works well.
Thanks @k8ieone
@FAUSheppy commented on GitHub (Mar 10, 2026):
Worked like a charm so far, will test the cli/acls & stuff later this week. Thanks for this great feature!
@binwiederhier commented on GitHub (Mar 10, 2026):
Thank you for testing folks. Keep the feedback coming! I'll likely switch ntfy.sh next weekend unless I hear anything that will make me stop it.
@FAUSheppy commented on GitHub (Mar 10, 2026):
Only minor complaint about the error handling:
This left me confused about the actual problem.
Idk what this check does exactly, but with this URL it did break (meaning it didn't fail where it should):
(the URL is wrong, I'm just yapping about the unclear error)
@binwiederhier commented on GitHub (Mar 10, 2026):
@FAUSheppy That's great feedback. I hate bad error messages. I'll improve this.
@binwiederhier commented on GitHub (Mar 11, 2026):
@FAUSheppy Done:
github.com/binwiederhier/ntfy@997e20fa3f@kyuuk commented on GitHub (Mar 11, 2026):
just migrated to postgres using the
pgimporttool (users.db), everything is good, tested some notification and nothing to report except that it works 😄@hugosxm commented on GitHub (Mar 13, 2026):
Sorry for the delay, tested everything today, works like a charm but did not test the migration as I took the opportunity to start from a fresh instance and brand new token / secrets. Thanks a lot for that change !
Is this possible to cache attachements to postgres too ? It would make ntfy fully stateless !
Also can we run multiple replicas of ntfy with postgres ?
@binwiederhier commented on GitHub (Mar 13, 2026):
My plan was S3 bucket/adapter, but I guess pg could be an idea too.
I merged in DB replica support yesterday (not released yet):
You can NOT yet run multiple instances of ntfy yet. There is in-memory state that prevents that. I will add that once I have attachments and replicas fully rolled out.
The postgres push was just step one into making it clusterable or at least more horizontally scalable.
@k8ieone commented on GitHub (Mar 13, 2026):
omg, yesss! You're building towards dream HA!
@hugosxm commented on GitHub (Mar 13, 2026):
Thanks for the clarification, postgres seems easier as a user if you already have the DB. S3 is nice too but this is an additional component to run if you not already have it.
I would be glad to test HA once it is ready ;)