Skip to main content

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.

ModeDescriptionDocs
--list-tables (-l)List all tables in the databaseView
--table NAME (-t)Export a single table to CSVView
--all (-a)Export all tables (one CSV per table)View
--query SQL (-q)Execute custom SQL and export to CSVView

Global Options

OptionDescriptionDefault
-c, --connection-string URLPostgreSQL connection stringDATABASE_URL env var
-o, --output DIROutput directory for CSV files./exports
-f, --filename NAMEOverride auto-generated filename--
-w, --where CLAUSESQL WHERE filter (for --table and --all)--

Output

  • Format: CSV with headers (UTF-8)
  • Naming: {table}-YYYY-MM-DD.csv for tables, query-YYYY-MM-DD.csv for queries
  • Empty tables: 0-byte file
  • Credentials: Automatically redacted in console output

Prerequisites

  • Node.js 18+
  • DATABASE_URL env var or --connection-string flag
  • npm install from repo root
  • Target database must be PostgreSQL 12+