Home / Market / postgres readonly queries

postgres readonly queries

Execute safe read-only SQL queries against PostgreSQL databases with multi-connection support and defense-in-depth write protection.

skill★ 507610 dlgithubCC-BY-4.0 content; MIT code; upstream exceptions applyInstall in CosmosUpstream Source

Documentation & Preview

postgres

Read-only PostgreSQL query skill. Query multiple databases safely with write protection.

Setup

  1. Copy the example config:
cp connections.example.json connections.json
  1. Add your database credentials:
{
  "databases": [
    {
      "name": "prod",
      "description": "Production - users, orders, transactions",
      "host": "db.example.com",
      "port": 5432,
      "database": "app_prod",
      "user": "readonly",
      "password": "secret",
      "sslmode": "require"
    }
  ]
}
  1. Secure the config:
chmod 600 connections.json

Usage

# List configured databases
python3 scripts/query.py --list

# List tables
python3 scripts/query.py --db prod --tables

# Show schema
python3 scripts/query.py --db prod --schema

# Run query
python3 scripts/query.py --db prod --query "SELECT * FROM users" --limit 100

Config Fields

| Field | Required | Default | Description | |-------|----------|---------|-------------| | name | Yes | - | Database identifier | | description | Yes | - | What data it contains (for auto-selection) | | host | Yes | - | Hostname | | port | No | 5432 | Port | | database | Yes | - | Database name | | user | Yes | - | Username | | password | Yes | - | Password | | sslmode | No | prefer | disable, allow, prefer, require, verify-ca, verify-full |

Safety Features

Requirements

pip install psycopg2-binary