pg-export CLI
Repo: score-ra/pg-export (private)
CLI entry point: pg-export or node bin/pg-export.js
Framework: Commander.js 14.0
Language: Node.js
CLI tool to export PostgreSQL data to CSV files. Connects to any PostgreSQL database, auto-discovers schema, and exports tables or custom queries to timestamped CSV files.
Modes
Exactly one mode must be specified per invocation.
| Mode | Description | Docs |
|---|---|---|
--list-tables (-l) | List all tables in the database | View |
--table NAME (-t) | Export a single table to CSV | View |
--all (-a) | Export all tables (one CSV per table) | View |
--query SQL (-q) | Execute custom SQL and export to CSV | View |
Global Options
| Option | Description | Default |
|---|---|---|
-c, --connection-string URL | PostgreSQL connection string | DATABASE_URL env var |
-o, --output DIR | Output directory for CSV files | ./exports |
-f, --filename NAME | Override auto-generated filename | -- |
-w, --where CLAUSE | SQL WHERE filter (for --table and --all) | -- |
Output
- Format: CSV with headers (UTF-8)
- Naming:
{table}-YYYY-MM-DD.csvfor tables,query-YYYY-MM-DD.csvfor queries - Empty tables: 0-byte file
- Credentials: Automatically redacted in console output
Prerequisites
- Node.js 18+
DATABASE_URLenv var or--connection-stringflagnpm installfrom repo root- Target database must be PostgreSQL 12+