Skip to content
Non-interactive PostgreSQL query tool.
Branch: master
Clone or download
Latest commit c847549 Aug 21, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Initial commit. Aug 21, 2019
LICENSE Initial commit. Aug 21, 2019 Initial commit. Aug 21, 2019
package-lock.json Initial commit. Aug 21, 2019
package.json v1.0.1 Aug 21, 2019
pgcmd.js Added shebang. Aug 21, 2019


Non-interactive PostgreSQL query tool.

It outputs JSON which means you can process and view the results with tools like jq or catj.


npm install -g pgcmd


pgcmd -h localhost \
      -u postgres \
      -p p@ssw0rd \
      -d postgres \
      'select * from pg_database where datname = $1' \
      -m template0

If no script is specified, pgcmd reads from the standard input:

echo 'select * from pg_database where datname = $1' | pgcmd -m template0


    "datname": "template0",
    "datdba": 10,
    "encoding": 6,
    "datcollate": "en_US.utf8",
    "datctype": "en_US.utf8",
    "datistemplate": true,
    "datallowconn": false,
    "datconnlimit": -1,
    "datlastsysoid": 13066,
    "datfrozenxid": "562",
    "datminmxid": "1",
    "dattablespace": 1663,
    "datacl": "{=c/postgres,postgres=CTc/postgres}"

Environment Variables

The following environment variables are supported:


Version History

  • 1.0
    • Initial release.


Soheil Rashidi

Copyright and License

Copyright 2019 Soheil Rashidi.

Licensed under the The MIT License (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

You can’t perform that action at this time.