this post was submitted on 29 Apr 2025
3 points (80.0% liked)

Self Hosted - Self-hosting your services.

13405 readers
5 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

Rules

Important

Beginning of January 1st 2024 this rule WILL be enforced. Posts that are not tagged will be warned and if not fixed within 24h then removed!

Cross-posting

If you see a rule-breaker please DM the mods!

founded 4 years ago
MODERATORS
 

I’m running funkwhale in docker. This consists of a half dozen docker containers one of which is postgres.

To run a backup, funkwhale suggests shutting down all of the containers and then docker compose running pg_dump on the postgres container. Presumably this is to copy the database when nobody is accessing it.

For some reason when I do this, I get an error like:

pg_dump: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
	Is the server running locally and accepting connections on that socket?

It would seem that postgres isn’t running. I see the same error with other commands such as psql.

If I fully boot the container and then try exec-ing the command, it works fine.

So it would seem that the run command isn’t fully booting the instance before running the command? What’s going on here?

The container is built from postgres:15-alpine

top 3 comments
sorted by: hot top controversial new old
[–] mhzawadi@lemmy.horwood.cloud 3 points 1 week ago

if it helps, I run Lemmy and dont stop the database at all.

I mount a back directory to the container and then run the bellow to do the backup.

dockerID=$(docker ps | grep lemmy_postgres | awk '{print $1}')
docker exec ${dockerID} /usr/local/bin/pg_dumpall -c -U lemmy | gzip > /mnt/backups/lemmy/lemmy_dump_`date +%Y%m%d-%H%M%S`.sql.gz

replace the lemmy_postgres with your funkwhale name.

[–] lukecooperatus@lemmy.ml 2 points 1 week ago* (last edited 1 week ago) (1 children)

That's working as intended; as the compose docs state, the command passed by run overrides the command defined in the service configuration, so it wouldn't normally be possible to actually shut down all the containers and then use docker compose run to interact with one of them. Run doesn't start anything up in the container other than the command you pass to it.

I'm not familiar with funkwhale, but they probably meant either to (a) shut down all the containers except postgres so that running pg_dump has something to connect to, or (b) use exec as you have done.

Personally, I do what you did, and use exec most of the time to do database dumps. AFAIK, postgres doesn't require that all other connections to it are closed before using pg_dump. It begins a transaction at the time you run it, so it's not interfering with anything else going on while it produces output (see relevant SO answer here). You could probably just leave your entire funkwhale stack up when you use docker compose exec to run pg_dump.

[–] ch00f@lemmy.world 1 points 1 week ago

Here’s the funkwhale page: https://docs.funkwhale.audio/administrator/upgrade/backup.html

Looks light a oversight on their part. Thanks for the advice.

I remember reading that copying a database while it’s in use is risky. Good to know pg_dump handles this correctly.