brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: pg_dump -j dumps a large database in parallel, but only in directory format

Database
~/tips/tip-database-pg-dump-parallel-directory

pg_dump -Fd -j 4 -f /backup/appdb.dir appdb

Speeds up PostgreSQL dumps and restores by processing several tables at once.

On a big PostgreSQL database one dump process leaves most of the CPU idle. Parallel jobs fix that.

pg_dump -Fd -j 4 -f /backup/appdb.dir appdb
pg_restore -j 4 -d appdb_new /backup/appdb.dir

-Fd writes a directory with one file per table, and -j 4 dumps four tables at the same time. pg_restore -j 4 reads the same directory with four workers, which usually helps even more on restore, because index builds run in parallel.

pg_dump creates the -f directory, and if it already exists it must be empty. It opens one connection per job plus one more, so make sure max_connections has room.

Further reading: PostgreSQL documentation: pg_dump

More Database tips mariadb -e 'CREATE DATABASE IF NOT EXISTS blog' mariadb-dump --no-create-info --insert-ignore shop orders > orders-rows.sql SELECT table_schema, table_name, CHECKSUM TABLE shop.orders; services: All Database tips (53) All topics

Link