Hacking dbdr

Dump once. Restore into ClickHouse or Postgres.

dbdr is one static Go binary. It works out what to create in what order, reads big tables in bounded pieces, and writes files you load back with one command.

Continue reading

Open source, BSD 3-Clause · 2 volumes · 20 chapters · 18,428 words

Quick start

Install

bash
go install github.com/harishiyer89/dbdump/cmd/dbdr@latest

or build from a checkout with make build, which puts the binary in dist/. make build-all cross-compiles for macOS, Linux and Windows on amd64 and arm64. How to use the tool, flag by flag, is covered in the top-level README.

Dump and restore

bash
# Connections use TLS and verify the server's certificate by default;
# add --tls-ca for an internal CA, or --tls=disable for a local test server.

# ClickHouse: structure as SQL, data in the engine's own binary format
dbdr -db=shop -un=default --only=schema -o=schema.sql
dbdr -db=shop -un=default --only=data -fmt=native -o=data.zip
dbdr restore -un=default -hn=target -s=schema.sql -d=data.zip

# ClickHouse to Postgres: dump once, pick the destination at restore time
dbdr -db=shop -un=default --only=schema -fmt=portable -o=shop.dbschema
dbdr -db=shop -un=default --only=data   -fmt=portable -o=shop.dbdata
dbdr restore -e=postgres -un=postgres -s=shop.dbschema -d=shop.dbdata

Pick a format

Format What it is Restorable into
sql plain CREATE and INSERT text the same engine
native the engine's own binary bulk format (ClickHouse Native, Postgres binary COPY), copied without decoding the same engine, fastest
portable an engine-neutral JSON schema and a compact binary row format any supported engine

Which one to use, and when: Vol. II, chapter 1.

Engines

Engine Schema SQL data Native Portable
ClickHouse yes yes yes yes
Postgres yes not yet yes yes
MySQL registered stub only; see Chapter 9

Each chapter ends with exercises. Some of them are a few minutes' work. Others are real features the program doesn't have yet, and a good answer to one of those would make a good pull request.

dbdr is short for database dump and restore.

This book and the dbdr source it describes are released under the BSD 3-Clause License. See LICENSE. Copyright (c) 2026, Littlebit Labs.

Run it as you read.