Registry / database / pgcmd
library1.2.0jsnpmunverified

pgcmd is a non-interactive PostgreSQL query tool designed for use from the command line. Version 1.2.0 (current stable) outputs results in JSON by default, making them pipeable to tools like jq, and also supports CSV output. It is released under the MIT license with a low release cadence (last update 2020). Key differentiators: minimal dependencies, simple CLI, and supports parameterized queries via -m options. Compared to psql, it offers machine-friendly output with no interactive features.

npm install pgcmd
INSTALL
IMPORT
SIG · PGCMD
P
pgcmd
databasejavascriptv1.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Runs a parameterized SELECT query against a PostgreSQL database and outputs JSON.

pgcmd -h localhost -u postgres -p mypassword -d postgres 'select * from pg_database where datname = $1' -m template0
Debug
Known issues
gotchaPassword on command line is visible in process listings and shell history.
fix
Use environment variables (PGPASSWORD) instead of -p option.
affects: >=1.0
deprecatedNode.js 14 support was added in v1.1 but older Node versions might not work.
fix
Upgrade pgcmd to v1.1+ or use Node 14+.
affects: <1.1
gotchaNo output if query returns empty result set. Exit code may not reflect SQL errors correctly in all cases.
fix
Check the JSON output array length or use --csv with headers.
affects: >=1.0
breakingThe --csv option was added in v1.1; previous versions only output JSON.
fix
Upgrade to v1.1+ to use --csv.
affects: <1.1
gotchaParameter placeholders use $1, $2, etc. (like libpq), not ?.
fix
Use $N for positional parameters.
affects: >=1.0
Errors
Common errors & fixes
pgcmd: command not found
pgcmd is not installed or not in PATH.
fix
Install globally: npm install -g pgcmd
Error: connect ECONNREFUSED 127.0.0.1:5432
PostgreSQL server is not running or port is blocked.
fix
Ensure PostgreSQL is running on localhost:5432 or use -h and -p to specify correct host and port.
Error: password authentication failed for user "postgres"
Incorrect password or user does not exist.
fix
Use correct password via -p or PGPASSWORD environment variable, or verify user exists.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
packagepgcmd
pgcmd — npm install pgcmd · libregistry