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 -Fc makes a compressed database dump that pg_restore can pick apart

Database
~/tips/tip-database-pg-dump-custom-format

pg_dump -Fc -f appdb.dump appdb

Saves a PostgreSQL database as a compressed archive from which you can restore only chosen parts.

A plain SQL dump is all or nothing. PostgreSQL’s custom format lets me restore a single table later.

pg_dump -Fc -f appdb.dump appdb
pg_restore -l appdb.dump
pg_restore -d appdb_copy -t users appdb.dump

-Fc writes the custom archive format, which is compressed by default. pg_restore -l lists everything inside, and -t users restores only that table into the target database, which must already exist.

It is also a good default for large databases, since the dump is compressed while it is written. The file is not readable SQL and only pg_restore can use it. If you want a text file to read or pipe into psql, use the default plain format instead.

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