postgres logo

postgres

Free

Execute safe read-only SQL queries against PostgreSQL databases with multi-connection support and defense-in-depth security. *By [@sanjay3290](https://github.com/sanjay3290)*

FreeFree tier
Type
Open Source

About postgres

A read-only PostgreSQL query skill designed for safe, multi-database SQL exploration. It enforces write protection at the database level using PostgreSQL's readonly mode, restricts queries to SELECT, SHOW, EXPLAIN, and WITH statements, prevents multi-statement queries, sets query (30s) and connection (10s) timeouts, caps returned rows at 10,000, and sanitizes credentials from error messages. Supports multiple database connections via a JSON config file.

Key Features

Read-only query execution with write protection at database level
Multi-database connection support via JSON configuration
Query validation restricting to SELECT, SHOW, EXPLAIN, WITH statements
Single statement enforcement blocking multi-query injections
Query timeout (30s) and connection timeout (10s)
Memory cap of 10,000 rows per query
Credential sanitization from error messages
Supports SSL modes: disable, allow, prefer, require, verify-ca, verify-full

Pros & Cons

Pros
  • Defense-in-depth security: readonly mode, query validation, timeouts, row limits, credential protection
  • Supports multiple databases with separate credentials
  • Simple setup via JSON config file and requirements.txt
  • Open-source and free to use
Cons
  • Limited to read-only operations (no INSERT, UPDATE, DELETE)
  • Requires manual configuration of database connections
  • Dependent on psycopg2-binary library
  • Not a full SQL client; only allows a subset of SQL statements

Best For

Safe ad-hoc SQL queries against production databasesDatabase schema exploration and table listingRead-only data analysis and reportingAutomated monitoring queries with strict security boundaries

FAQ

What databases can I query?
Any PostgreSQL database for which you have read-only credentials. Multiple databases can be configured in the connections.json file.
Is this skill safe for production use?
Yes. It enforces read-only sessions, restricts queries to safe statements, enforces timeouts, caps row returns, and hides credentials in error messages.
How do I set up the skill?
Copy connections.example.json to connections.json, add your database details, and run pip install psycopg2-binary. Then use the query.py script with --db, --tables, --schema, or --query options.