See DOCTRINE.md.
Fast PostgreSQL database operations via FGP protocol. Connect to any PostgreSQL database with connection pooling and low-latency queries.
# Set connection via environment
export DATABASE_URL="postgres://user:pass@localhost:5432/mydb"
# Start daemon
fgp-postgres start
# Or run in foreground for debugging
fgp-postgres start -f
# Quick query (no daemon needed)
fgp-postgres query "SELECT NOW()"cargo install --path .
# Or build from source
cargo build --release# Standard DATABASE_URL
export DATABASE_URL="postgres://user:pass@localhost:5432/mydb"
# Or libpq-style variables
export PGHOST=localhost
export PGPORT=5432
export PGUSER=myuser
export PGPASSWORD=mypass
export PGDATABASE=mydbCreate ~/.fgp/auth/postgres/connections.json:
{
"default": "local",
"connections": {
"local": {
"host": "localhost",
"port": 5432,
"user": "postgres",
"password": "secret",
"database": "mydb"
},
"production": {
"url": "postgres://user:pass@prod.example.com:5432/proddb?sslmode=require"
}
}
}Then use named connections:
fgp-postgres start --connection production
fgp-postgres query "SELECT 1" --connection local# Daemon management
fgp-postgres start # Start daemon (background)
fgp-postgres start -f # Start in foreground
fgp-postgres stop # Stop daemon
fgp-postgres status # Check daemon status
# Quick operations (no daemon)
fgp-postgres query "SELECT * FROM users LIMIT 5"
fgp-postgres tables # List tables
fgp-postgres tables --schema myschema # Tables in specific schema
fgp-postgres connections # List configured connections| Method | Description | Parameters |
|---|---|---|
postgres.query |
Execute SELECT query | sql (required) |
postgres.execute |
Execute INSERT/UPDATE/DELETE | sql (required) |
postgres.transaction |
Execute statements in transaction | statements[] (required) |
postgres.tables |
List tables in schema | schema (default: "public") |
postgres.schema |
Get table schema | table (required), schema (default: "public") |
postgres.schemas |
List all schemas | - |
postgres.stats |
Database statistics | - |
# Via socket (with running daemon)
echo '{"id":"1","v":1,"method":"query","params":{"sql":"SELECT * FROM users LIMIT 5"}}' \
| nc -U ~/.fgp/services/postgres/daemon.sock
# Response
{
"id": "1",
"ok": true,
"result": {
"rows": [
{"id": 1, "name": "Alice", "email": "alice@example.com"},
{"id": 2, "name": "Bob", "email": "bob@example.com"}
],
"row_count": 2,
"columns": ["id", "name", "email"]
}
}{
"method": "postgres.transaction",
"params": {
"statements": [
"UPDATE accounts SET balance = balance - 100 WHERE id = 1",
"UPDATE accounts SET balance = balance + 100 WHERE id = 2",
"INSERT INTO transfers (from_id, to_id, amount) VALUES (1, 2, 100)"
]
}
}{
"method": "postgres.schema",
"params": {
"table": "users",
"schema": "public"
}
}Response includes columns, constraints, and indexes.
With connection pooling and warm connections:
| Operation | Cold Start | Warm (FGP) |
|---|---|---|
| Simple query | ~50-100ms | ~5-15ms |
| Complex query | ~100-500ms | ~50-200ms |
| Transaction | ~150-300ms | ~20-50ms |
Default: ~/.fgp/services/postgres/daemon.sock
Override with --socket:
fgp-postgres start --socket /tmp/my-postgres.sock- Passwords in
DATABASE_URLor config files are stored in plaintext - Consider using environment variables for production
- The daemon runs with the permissions of the user who started it
- SSL/TLS is supported via
sslmodeparameter in connection URL
# Check if PostgreSQL is running
pg_isready -h localhost -p 5432
# Check connection manually
psql postgres://user:pass@localhost:5432/mydb -c "SELECT 1"# Check socket permissions
ls -la ~/.fgp/services/postgres/
# Remove stale socket
rm ~/.fgp/services/postgres/daemon.sock# Run in foreground to see errors
fgp-postgres start -f
# Check logs
RUST_LOG=debug fgp-postgres start -f