DMP csv2pg: large, messy data files into PostgreSQL¶
Available now
DMP csv2pg loads a whole folder of data files into PostgreSQL. Point it at the folder and a PostgreSQL server, and it creates the databases, schemas and tables and loads everything — the 50 GB, 340-million-row file that almost every other loader gives up on, the folder of hundreds of files and tens of gigabytes, the file the database's own import refuses, the JSON dump from another team — in one run. Whether you need to import a large CSV into Postgres, turn JSON or Parquet into PostgreSQL tables, or bulk-load a folder of exports on Windows, it is the same single command.
DMP csv2pg is the first tool in the DMP family of tools for moving data into databases. Tools for SQL Server, MySQL, Oracle and more are coming.
Before and after¶
Without DMP csv2pg¶
- Try to load the file. It fails.
- Spend the afternoon finding out why, and fix it by hand or with a script.
- Write every table definition by hand, and hope you guessed right.
- Load again, hit the next problem, go back to step 2.
- Repeat for each of the other 300 files.
With DMP csv2pg¶
- Put the files in folders named after the target database, schema and table.
- Run one command.
- Read the short list of logs that need your attention — often there are none.
- Query the tables with SQL and add the indexes your queries need.
Quick start¶
dmp csv2pg --source="D:\exports" --host=localhost --port=5432 ^
--user=postgres --password=secret --database=postgres
dmp csv2pg --source="D:\exports" --host=localhost --port=5432 `
--user=postgres --password=secret --database=postgres
dmp csv2pg --source=/data/exports --host=localhost --port=5432 \
--user=postgres --password=secret --database=postgres
With per-file progress and timings, leaving two CPU cores free for other work:
dmp csv2pg --source="D:\exports" --host=localhost --port=5432 ^
--user=postgres --password=secret --database=postgres ^
--verbose=true --cores=-2
dmp csv2pg --source="D:\exports" --host=localhost --port=5432 `
--user=postgres --password=secret --database=postgres `
--verbose=true --cores=-2
dmp csv2pg --source=/data/exports --host=localhost --port=5432 \
--user=postgres --password=secret --database=postgres \
--verbose=true --cores=-2
CSV files only, leaving Parquet and JSON files aside:
dmp csv2pg --source="D:\exports" --host=localhost --port=5432 ^
--user=postgres --password=secret --database=postgres ^
--parquet=false --jsonl=false
dmp csv2pg --source="D:\exports" --host=localhost --port=5432 `
--user=postgres --password=secret --database=postgres `
--parquet=false --jsonl=false
dmp csv2pg --source=/data/exports --host=localhost --port=5432 \
--user=postgres --password=secret --database=postgres \
--parquet=false --jsonl=false
Built-in help is always there: dmp --help and dmp csv2pg --help.
What one run gives you¶
- Every file taken as it is. CSV, JSON, JSON Lines and Parquet, plain or compressed — nothing to convert or tidy up by hand first.
- Clean tables you can trust. Messy data goes in; well-formed tables, ready for SQL, come out.
- Databases, schemas and tables created and filled, many files at once.
- A short report. At the end you get the list of logs that need your attention, and the total run time.
- Progress you can see. A progress bar while it works; per-file timings with
--verbose=true. - A dropped connection is not the end. If the database connection drops during a load, csv2pg reconnects and carries on.
- Safe to run again. Change a setting and simply run again.
What it copes with¶
Most loaders are built for tidy data. DMP csv2pg is built for the real thing — files that are huge, damaged, inconsistent or exported by systems nobody remembers:
- Monstrous sizes. A 50 GB file of 340 million rows loads in a single run; files far bigger than your machine's memory are no problem.
- Hundreds of files across many folders, tens of gigabytes in all, in one run.
- Odd and mixed encodings, including more than one in the same file.
- CSV that is not quite CSV: stray quotes, rows with too many or too few fields, rows broken in two.
- JSON stuck inside CSV columns.
- Stray characters and raw bytes in the middle of text.
- Every delimiter — comma, semicolon, tab, pipe — found for you, no settings.
Tab-separated data goes in whether the file is named
.csv,.tsvor.tab. - Dates, numbers and empty values written in many different ways, even within one column — they arrive as real dates, numbers and NULLs, so SQL and indexes work.
Most files need no settings at all: in our own tests on 67 real-world data sets, more than 80 % of tables went in untouched. Anything that needs a human decision is written to the table's log, with a hint on what to do next. The toughest files are covered by the repair in Pro and above.
Built for files that are too big¶
- Every CPU core.
--cores=0(the default) uses all of them,--cores=4uses four,--cores=-2all but two. Your edition sets the ceiling. - Measured: a 2.9 GB, 7.8-million-line CSV went from raw file to loaded table in under 9 minutes; a 10.3 GB file was cleaned and loaded in 6 min 28 s — while the rest of a 47.4 GB, 374-table run went on in parallel, all of it done in 33 min 51 s (the machines are listed under Use cases).
- 50 GB and 340 million rows in one file? It loads in a single run (2 h 15 min on a laptop).
More real runs, with sizes, times and the edition each needs: See the use cases.
Supported input¶
| Kind | Extensions | Edition |
|---|---|---|
| CSV | .csv, with any single-character delimiter, found automatically |
All |
| Tab-separated | .tsv, .tab |
All |
| Compressed CSV and tab-separated | .csv, .tsv or .tab followed by .gz, .bz2, .zip, .xz, .zst, .tar, .tar.gz, .tar.xz or .tar.bz2 |
All |
| JSON / JSON Lines | .json, .jsonl, plain or with the same compression suffixes |
Trial, Pro, Pro+, Enterprise |
| Parquet | .parquet |
Trial, Pro, Pro+, Enterprise |
Each archive must hold exactly one file.
System requirements¶
- Windows: Windows 10 or Windows 11, 64-bit (x64); Windows Server 2016, 2019, 2022 or 2025, 64-bit.
- Linux and macOS: on request.
- Machine: a physical computer or server; DMP does not run in a virtual machine. The database server can be anywhere, virtual or managed.
- Database: a PostgreSQL server (9.4 or later; tested on 9.4 to 18) that the machine running DMP can reach over the network.
- Network: online licences need outgoing HTTPS (TLS 1.2 or 1.3) to www.wildpythonprogramming.uk; a standard web proxy is fine. Offline licences (Enterprise) need no network.
- Not supported: Windows 8.1 and older (including Windows 7 and Windows XP), Windows Server 2012 R2 and older, 32-bit systems.
Older machines. If your files live on an older system, run DMP on any supported machine that can read those files (for example over a network share) and reach your database. DMP does not need to run on the machine where the files were produced.
Folder layout¶
The folder structure tells csv2pg where each file goes. Each database can use its own layout, and one run can fill several databases.
source/
└── finance/ ← database
└── data/
└── underwriting/ ← schema
└── offers/ ← table
└── data.csv
source/
└── library/ ← database
└── data/
└── catalogue/ ← schema
├── names.csv ← table "names"
├── records.csv
└── titles.csv
source/
└── open_data/ ← database
└── data/
├── air_quality.csv ← table in "public"
└── complaints.csv
Settings¶
All settings are optional. Put a settings.toml at the level it should apply to — all
databases, one database, one schema — or a my_table.toml next to my_table.csv.
The most specific file wins. Unknown setting names are reported, not ignored.
[sanitise]
skipRows = 2 # skip a two-line legend at the top
[database]
recreate = false # keep the existing database (default: recreate it)
tableNotEmptyAction = "append" # or "delete" (the default)
autoShortenIdentifiers = true # shorten names longer than PostgreSQL allows
[columns."Year End"]
dataType = "timestamp without time zone"
Command reference¶
| Option | Default | Meaning |
|---|---|---|
--source |
required | Folder holding the data |
--host, --port |
required | PostgreSQL server |
--user, --password |
required | PostgreSQL credentials |
--database |
required | Database to connect to first |
--parquet |
true |
Include Parquet files |
--jsonl |
true |
Include JSON and JSON Lines files |
--restore |
true |
Start each run afresh, so changed settings apply to every file |
--cores |
0 |
CPU cores: 0 = all, 4 = four, -2 = all but two |
--verbose |
false |
Show per-file progress and timings |
--skipped-names |
true |
Name each file skipped over the licence limit; false shows only how many |
Good to know
- By default csv2pg recreates each target database it loads into, so every run
starts clean. To load into an existing database, set
recreate = false. - csv2pg creates tables and columns; it does not create indexes or keys. Add them after the load, on the columns your queries use.
- Run one csv2pg at a time against a given source folder.
- A file that fails is logged and the others carry on.
See it on your own files. The trial takes every input format, on a small sample.