fast-gateway-protocol

postgres-daemon

Fast PostgreSQL operations via FGP daemon - 30-80x faster than MCP. Use when user needs to run SQL queries, manage schema, analyze performance, or work with any Postgres database. Triggers on "run sql", "postgres query", "list tables", "database schema", "pg query", "explain query".

fast-gateway-protocol 2 Updated 4mo ago

Resources

1
GitHub

Install

npx skillscat add fast-gateway-protocol/fgp-skills/postgres-daemon

Install via the SkillsCat registry.

SKILL.md

FGP Postgres Daemon

Ultra-fast PostgreSQL operations with persistent connection pooling. 30-80x faster than per-query connections.

Why FGP?

Operation FGP Daemon Per-query conn Speedup
Simple query 1-5ms ~80ms 15-80x
Complex query 5-20ms ~100ms 5-20x
Transaction 3-10ms ~90ms 10-30x
Schema info 2-8ms ~85ms 10-40x

Persistent connection pool eliminates connection overhead.

Installation

brew install fast-gateway-protocol/tap/fgp-postgres

# Or
bash ~/.claude/skills/fgp-postgres/scripts/install.sh

Setup

# Connection string
export DATABASE_URL="postgres://user:pass@host:5432/dbname"

# Or individual vars
export PGHOST="localhost"
export PGPORT="5432"
export PGUSER="postgres"
export PGPASSWORD="password"
export PGDATABASE="mydb"

Usage

Queries

# Simple query
fgp pg "SELECT * FROM users LIMIT 10"

# With parameters
fgp pg "SELECT * FROM users WHERE id = $1" --params '[123]'

# From file
fgp pg --file query.sql

# Output formats
fgp pg "SELECT * FROM users" --format table  # Default
fgp pg "SELECT * FROM users" --format json
fgp pg "SELECT * FROM users" --format csv
fgp pg "SELECT * FROM users" --format vertical

Transactions

# Transaction block
fgp pg --transaction "
  UPDATE accounts SET balance = balance - 100 WHERE id = 1;
  UPDATE accounts SET balance = balance + 100 WHERE id = 2;
"

# From file
fgp pg --transaction --file migration.sql

Schema Exploration

# List tables
fgp pg tables

# List tables in schema
fgp pg tables --schema public

# Describe table
fgp pg describe users

# List columns
fgp pg columns users

# List indexes
fgp pg indexes users

# List foreign keys
fgp pg fkeys users

# List all schemas
fgp pg schemas

# Database size
fgp pg size

Data Operations

# Insert
fgp pg insert users --data '{"name": "John", "email": "john@example.com"}'

# Update
fgp pg update users --where "id = 1" --set '{"name": "Jane"}'

# Delete
fgp pg delete users --where "id = 1"

# Upsert
fgp pg upsert users --data '{"id": 1, "name": "John"}' --conflict id

# Copy from CSV
fgp pg copy users --from data.csv

# Copy to CSV
fgp pg copy users --to backup.csv

Explain & Analyze

# Explain query
fgp pg explain "SELECT * FROM orders WHERE status = 'pending'"

# Explain analyze (actually runs)
fgp pg explain "SELECT * FROM orders" --analyze

# With buffers
fgp pg explain "SELECT * FROM orders" --analyze --buffers

Connections

# List connections
fgp pg connections

# Kill connection
fgp pg kill <pid>

# Current connection info
fgp pg whoami

Maintenance

# Vacuum table
fgp pg vacuum users

# Vacuum analyze
fgp pg vacuum users --analyze

# Reindex
fgp pg reindex users

# Table stats
fgp pg stats users

Multiple Databases

# Connect to specific database
fgp pg "SELECT 1" --database otherdb

# With full connection string
fgp pg "SELECT 1" --url "postgres://user:pass@host/db"

# Switch default
fgp pg use "postgres://user:pass@host/newdb"

Available Commands

Command Description Example
(query) Run SQL fgp pg "SELECT..."
tables List tables fgp pg tables
describe Describe table fgp pg describe users
columns List columns fgp pg columns users
indexes List indexes fgp pg indexes users
explain Explain query fgp pg explain "..."
size Database size fgp pg size
vacuum Vacuum table fgp pg vacuum users

Output Formats

# Table (default)
fgp pg "SELECT * FROM users"
┌────┬──────────┬─────────────────────┐
│ id │   name   │        email        │
├────┼──────────┼─────────────────────┤
│  1 │ John     │ john@example.com    │
│  2 │ Jane     │ jane@example.com    │
└────┴──────────┴─────────────────────┘

# JSON
fgp pg "SELECT * FROM users" --format json
[{"id": 1, "name": "John", "email": "john@example.com"}, ...]

# CSV
fgp pg "SELECT * FROM users" --format csv
id,name,email
1,John,john@example.com

Example Workflows

Quick data check

fgp pg "SELECT COUNT(*) FROM orders WHERE created_at > NOW() - INTERVAL '1 day'"

Debug slow query

fgp pg explain "SELECT * FROM orders o JOIN users u ON o.user_id = u.id WHERE o.status = 'pending'" --analyze --buffers

Export data

fgp pg "SELECT * FROM users WHERE created_at > '2024-01-01'" --format csv > new_users.csv

Safe migration

fgp pg --transaction --file add_column.sql

Troubleshooting

Connection failed

Error: Connection refused

Check host, port, and that Postgres is running.

Authentication failed

Error: Password authentication failed

Check username and password.

Database not found

Error: Database "x" does not exist

Check database name.

Permission denied

Error: Permission denied for table users

Check user permissions.

Architecture

  • libpq or pure Rust postgres driver
  • Connection pooling (configurable pool size)
  • UNIX socket at ~/.fgp/services/postgres/daemon.sock
  • Prepared statements for repeated queries