Menu

Three ways a nightly pg_dump job fails without telling you
📰

Three ways a nightly pg_dump job fails without telling you

DEV Community: database·SuperLede·about 3 hours ago
#MoT3bqcD
#devtodatabase#devto#dev#file#exit
Reading 0:00
15s threshold

I broke a nightly Postgres backup script on purpose to see which failures I'd actually hear about. Pointed at a closed port, it exited 0 and left a 20-byte .gz file. A truncated dump got past pg_restore --list . And if cron never starts the job, there's no exit code to check at all.

1. The job fails, and the exit code says it worked

I started with this line:

pg_dump "$DATABASE_URL" | gzip > "backup-$(date +%F).sql.gz"

Enter fullscreen mode

Exit fullscreen mode

I pointed it at a port with no database behind it:

$ ./nightly-naive.sh ; echo "exit $?" pg_dump: error: connection to server at "127.0.0.1" , port 5999 failed: Connection refused Is the server running on that host and accepting TCP/IP connections? exit 0 $ ls -l backup-*.sql.gz -rw-r--r-- 1 me wheel 20 Nov 19 10:31 backup-2026-11-19.sql.gz

Enter fullscreen mode

Exit fullscreen mode

By default, bash gives a pipeline the exit status of its last command.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.