Connect to a PostgreSQL database to inspect its schema (tables, columns, indexes, foreign keys, views) and execute read-only SQL queries. Use when the user needs to explore or retrieve data from a PostgreSQL database.
Inspect schemas and run read-only queries against a PostgreSQL database using the bundled helper script.
Before first use, ensure the psycopg2-binary Python package is installed:
pip install psycopg2-binary
If the import fails when running the script, install the package and retry.
The helper script is located at:
${CLAUDE_SKILL_DIR}/scripts/query_postgres.py
The script accepts connection details via command-line arguments standard PostgreSQL environment variables. Arguments take precedence over environment variables.
| Argument | Env Variable | Default | Description |
|---|---|---|---|
--host | PGHOST | localhost | Database host |
--port | PGPORT | 5432 | Database port |
--database | PGDATABASE | postgres | Database name |
--user | PGUSER | postgres | Username |
--password | PGPASSWORD | (empty) | Password |
--connection-string | DATABASE_URL | (none) | Full connection URI (overrides individual params) |
Ask the user for connection details before running the script. Never guess or assume credentials.
List all tables and views in the database:
python3 ${CLAUDE_SKILL_DIR}/scripts/query_postgres.py --host <host> --database <db> --user <user> --password <pass> schema
Inspect a specific table's columns, indexes, and foreign keys:
python3 ${CLAUDE_SKILL_DIR}/scripts/query_postgres.py --host <host> --database <db> --user <user> --password <pass> schema --table <table_name>
Optionally filter by schema:
python3 ${CLAUDE_SKILL_DIR}/scripts/query_postgres.py --host <host> --database <db> --user <user> --password <pass> schema --schema <schema_name>
List all available databases on the server:
python3 ${CLAUDE_SKILL_DIR}/scripts/query_postgres.py --host <host> --user <user> --password <pass> schema --list-databases
Run a read-only SQL query:
python3 ${CLAUDE_SKILL_DIR}/scripts/query_postgres.py --host <host> --database <db> --user <user> --password <pass> query "SELECT * FROM users LIMIT 10"
Output as JSON instead of a table:
python3 ${CLAUDE_SKILL_DIR}/scripts/query_postgres.py --host <host> --database <db> --user <user> --password <pass> query --format json "SELECT * FROM users LIMIT 10"
SET default_transaction_read_only = true on every connection. Any INSERT, UPDATE, DELETE, DROP, or CREATE statement will be rejected by PostgreSQL.--limit <N> to change this.--limit to avoid returning excessively large result sets.--connection-string instead of individual parameters.