Ask
88

postgres in a container on the same box, or managed at $19/mo for 8gb of data Backups

Currently postgres 17 in compose next to the app, data on a mounted volume, pg_dump to R2 nightly from a cron container. 8 GB and growing maybe 400 MB a month. Two-person team, no ops person, we ship a lot.

Someone on the team wants to move to managed because "nightly dumps mean up to 24 hours of data loss", which is true. But managed is $19-25 and, more to the point, adds a network hop and I'm not sure what else.

If you run postgres in docker in production — what actually went wrong for you?

10 answers Share
Report

Answering anonymously — a moderator will review it first.

  • @negativesplitz · 3w ago · 3 replies

    Things that actually went wrong for me, ordered by how much they hurt:

    1. Major version upgrade. Going from postgres:16 to 17 in compose does not migrate your data directory — the container starts, sees an incompatible PGDATA and refuses. In production, at a bad moment, because someone had written postgres:latest. Pin the exact minor version, always, and treat upgrades as a planned dump/restore with downtime.
    2. Disk full. Postgres does not degrade gracefully, it stops accepting writes. Alert at 70%, not 90%.
    3. The thing you're worried about — losing a day — has never happened to me, because dumps aren't your only line of defence unless you decide they are.

    Your colleague is right about the exposure and wrong about the fix. You don't need managed to close a 24-hour window, you need WAL archiving. pgBackRest or wal-g shipping WAL to R2 gets you point-in-time recovery to within about a minute, and it's an afternoon of work. That capability is most of what managed is actually selling you.

    134
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @coworking_cass · 3w ago

      wal-g to R2 it is. I think we'd both quietly assumed PITR was a managed-only capability, which is just wrong.

      41
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
    • @mulch_mule · 3w ago

      Set it up, then restore to a specific point in time on a throwaway box before you believe any of it. Setup is the easy half.

      23
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @rubberduck_rae · 3w ago · 2 replies

    Postgres in a container is fine. Postgres in a container with data in a named volume you don't fully understand is the actual risk. Bind-mount to an explicit host path so you know exactly where the bytes are, and make sure a stray docker compose down -v can't take them with it.

    Also shm_size. The 64 MB default bites you the first time somebody runs a big parallel query and you get "could not resize shared memory segment". Set it to 1g and forget about it.

    37
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @coworking_cass · 3w ago

      We hit the shm one last month and never traced it properly. That's the answer, thank you.

      19
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @flux_and_solder · 3w ago

    Container versus managed is slightly the wrong axis. The question is who is on the hook when it's broken, and on a two-person team shipping fast the answer is "whoever least wants to be".

    $19 is roughly 40 minutes of one developer's time a month. If self-hosting costs you more than 40 minutes a month averaged over a year — including the one bad night — managed is cheaper. In my experience at 8 GB with simple usage, self-hosting comes in well under that, as long as you do the WAL thing.

    62
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @muslin_mira · 3w ago

    The extra network hop is real but small — same region is maybe 1-3 ms per query. What actually hurts is a chatty ORM doing 40 sequential queries per request, where 2 ms becomes 80. Count your queries per request before deciding it doesn't matter.

    A local socket to a container on the same box is genuinely faster, and for some workloads noticeably so.

    24
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @edge_runtime_bo · 3w ago

    Whatever you choose, separate it from the backup fix. Do WAL archiving this week regardless. If you migrate to managed in three months you've lost nothing and you'll know how your own restore works — which you'll want anyway the day the managed provider has a bad afternoon and you need a copy somewhere else.

    16
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @kettlebell_ned · 3w ago · 2 replies

    8gb fits in ram on a 15 euro box, self host. managed postgres at that size is paying for a checkbox

    15
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @negativesplitz · 3w ago

      It's paying for somebody else's pager, which is a real product. Whether you want it depends on whether you'd rather debug WAL replay or ship features. Both are defensible answers.

      13
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report