Shared Postgres for containers? reddit / selfhosted ---------------------------------------------------------------------- SillyLilBear · 2023-11-12 21:11 For docker stacks, do you typically run stand alone postgres containers, or do you run one postgres container and setup accounts for each new stack that requries it? Right now I am running a new postgres in docker compose as needed, but seems this is wasteful and it maybe easier to manage/monitor if I just ran one instance. ---------------------------------------------------------------------- fideli_ · 2023-11-12 21:33 Since I'm not interested in being a DB admin, I use separate postgres instances for my apps. ---------------------------------------------------------------------- adamshand · 2023-11-12 21:44 It's much easier from an admin perspective to have dedicated databases for each app/stack. The overhead is pretty low. It bothered me at first, but I've gotten used to it. It's SOOO nice just being able to delete everything without having to disentangle anything. ---------------------------------------------------------------------- notdoreen · 2023-11-12 21:52 I use the same DB container for all my applications. Writing and hearing it in my mind makes me realize how risky that is. If anything happens to my one database, all of my applications are done for. Maybe it's time to have a standalone DB for each app... ---------------------------------------------------------------------- SillyLilBear · 2023-11-12 21:54 I'm not convinced it's a bad idea. ---------------------------------------------------------------------- ddpbsd · 2023-11-12 22:03 Redeploy the container and restore from backups? ---------------------------------------------------------------------- apperrault · 2023-11-12 22:08 I have been going back and forth on this exact question. for the longest time I was one database to rule them all. For some reason a couple of weeks ago I was doing something and I setup vaultwarden with it's own postgres instance. later, I was doing something else with my docker system and somehow borked my other database instance. Granted, I didn't have backups so that was my fault (nothing critical was on there so I am not that upset) but if I had lost my vaultwarden database, i would have been pissed. Now, You get a postgres, and you get a postgres EVERYONE gets a postgres. It's super easy to add to the compose, and I have an additional container I always install with each postgres install that sets up backups for each of them I may go back again some day, but this works for now and I have the CPU and RAM for it to work app ---------------------------------------------------------------------- homemediajunky · 2023-11-12 22:23 I run everything in one instance but have replication setup so if I did lose the master, the backup is up to date. This, plus regular snapshot and VM backups. I have had no issues in years. I even tested just shutting down the master and everything switched with no noticeable downtime. ---------------------------------------------------------------------- notdoreen · 2023-11-12 22:29 What's your backup system? ---------------------------------------------------------------------- MalcolmY · 2023-11-12 23:31 That's a good point. I absolutely hate those "extra" containers I see in Portainer; redis/db/...etc. But I hate even more spending days trying to untangle a mess that I have to do research first to even figure out where to look. Deleting /restarting/editing a stack for example without affecting anything else is key. ---------------------------------------------------------------------- MalcolmY · 2023-11-12 23:34 How do you setup the extra container for backups? Sounds useful! ---------------------------------------------------------------------- apperrault · 2023-11-12 23:39 it's actually pretty easy. [https://pastebin.com/iYtVe3r0](https://pastebin.com/iYtVe3r0) then I just need to offsite backup that backup folder ---------------------------------------------------------------------- mb4x4 · 2023-11-13 00:23 Separate dbs for every container is the only way to go. Little-to-no wasted resources with docker. ---------------------------------------------------------------------- edgan · 2023-11-13 00:25 If you have the resources, one per stack. ---------------------------------------------------------------------- homemediajunky · 2023-11-13 00:53 I use Veeam to backup all VMs. Full backups and also incremental backups. The backup target is an iSCSI share from a TrueNAS server. The iSCSI target is replicated to another TrueNAS server located in another location in the house. Everything replicated to another TrueNAS server located roughly 10 miles away. I have 2x MySQL and 2x Postgres instances running. Replication between the two is setup real-time. Script that basically does mysqldump/pgdump every 15 minutes. This gets backed up to nas01. Gets replicated to nas02. Sent off-site It's not foolproof. But if something happens and my entire house is lost, I would (not that it would be anywhere near a priority other than my important documents which digital copies exist in easy to access locations) be able to do a full restore. ---------------------------------------------------------------------- notdoreen · 2023-11-13 01:00 Thanks for sharing. I'll look into Veaam ---------------------------------------------------------------------- violet-crayola · 2023-11-13 01:13 In development - single postgres for all apps. In production - dedicated postgres for every separate app. ---------------------------------------------------------------------- moontear · 2023-11-13 02:03 So it is one backup container per database? Four Postgres containers and four backup containers? ---------------------------------------------------------------------- homemediajunky · 2023-11-13 05:11 Look at their NFR license for homelab use. ---------------------------------------------------------------------- king_hreidmar · 2023-11-13 05:49 Another thing to consider is that some applications may only support specific major versions of Postgres. You also don’t want to have to take every service down because you need to upgrade one DB. I use k8s to manage my containers and this makes spinning up new postgres pods as easy as “find and replace” on a manifest and a quick k8s apply. It also lets me isolate my DBs a bit from other applications using namespaces so I don’t accidentally connect to the wrong one DB. ---------------------------------------------------------------------- midniteslayr · 2023-11-13 06:32 The only thing I don't see here that is an argument for a singular database instance is if the thing you're developing (or a different service) needs to have access to the other service's data. For example, I am developing a backend multiplayer server for a game, I have my identity managed with a solution called [Hydra](https://www.ory.sh/hydra/). Hydra uses the PostgreSQL connection layer to my CockroachDB instance that my multiplayer framework, [Nakama](https://heroiclabs.com/nakama/), uses. Using Triggers, anytime someone authenticates with Hydra, I populate the Nakama database with the player's data so they can immediately start playing once authenticated. If these were silo-ed with their own database instances, then there would need to be a ton more work to occur so that Hydra can "inform" Nakama about the new player. TL;DR: Singular database instances are better for data sharing and setting up data for other services. ---------------------------------------------------------------------- apperrault · 2023-11-13 16:38 Yeah. That's the way I do it.