# Database Postgresql

> PostgreSQL database inspection and queries. Use when investigating table schemas, running queries, checking locks, replication status, or long-running queries.

- **Type:** Skill
- **Install:** `agentstack add skill-swapnildahiphale-opensre-database-postgresql`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [swapnildahiphale](https://agentstack.voostack.com/s/swapnildahiphale)
- **Installs:** 0
- **Category:** [Databases](https://agentstack.voostack.com/c/databases)
- **Latest version:** 0.1.0
- **License:** Apache-2.0
- **Upstream author:** [swapnildahiphale](https://github.com/swapnildahiphale)
- **Source:** https://github.com/swapnildahiphale/OpenSRE/tree/main/sre-agent/.claude/skills/database-postgresql
- **Website:** https://opensre.in

## Install

```sh
agentstack add skill-swapnildahiphale-opensre-database-postgresql
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# PostgreSQL Database

## Authentication

**IMPORTANT**: Credentials are injected automatically by a proxy layer. Do NOT check for `POSTGRES_PASSWORD` in environment variables - it won't be visible to you. Just run the scripts directly; authentication is handled transparently.

Configuration environment variables you CAN check (non-secret):
- `POSTGRES_HOST` - Database host
- `POSTGRES_PORT` - Database port (default: 5432)
- `POSTGRES_DATABASE` - Database name
- `POSTGRES_SCHEMA` - Default schema (default: public)

---

## MANDATORY: Schema-First Investigation

**Understand the schema before running queries.**

```
LIST TABLES → DESCRIBE TABLE → EXECUTE QUERY → CHECK HEALTH
```

## Available Scripts

All scripts are in `.claude/skills/database-postgresql/scripts/`

### list_tables.py - List Tables (START HERE)
```bash
python .claude/skills/database-postgresql/scripts/list_tables.py [--schema public]
```

### describe_table.py - Table Schema Details
```bash
python .claude/skills/database-postgresql/scripts/describe_table.py --table TABLE_NAME [--schema public]
```

### execute_query.py - Run SQL Queries
```bash
python .claude/skills/database-postgresql/scripts/execute_query.py --query "SELECT * FROM users WHERE created_at > now() - interval '1 hour'" [--limit 100]
```

### list_indexes.py - Index Information
```bash
python .claude/skills/database-postgresql/scripts/list_indexes.py [--table TABLE_NAME] [--schema public]
```

### get_table_sizes.py - Table Size Analysis
```bash
python .claude/skills/database-postgresql/scripts/get_table_sizes.py [--table TABLE_NAME] [--schema public]
```

### get_locks.py - Current Locks & Blocking Queries
```bash
python .claude/skills/database-postgresql/scripts/get_locks.py
```

### get_replication_status.py - Replication Health
```bash
python .claude/skills/database-postgresql/scripts/get_replication_status.py
```

### get_long_running_queries.py - Long-Running Queries
```bash
python .claude/skills/database-postgresql/scripts/get_long_running_queries.py [--min-duration 60]
```

---

## Investigation Workflow

### Lock Contention
```
1. get_locks.py (find blocking relationships)
2. get_long_running_queries.py --min-duration 30
3. execute_query.py --query "SELECT * FROM pg_stat_activity WHERE state = 'active'"
```

### Replication Lag
```
1. get_replication_status.py (check lag_bytes/lag_seconds)
2. get_long_running_queries.py (queries blocking replication)
```

### Table Growth Investigation
```
1. get_table_sizes.py (find largest tables)
2. list_indexes.py --table  (check index health)
3. describe_table.py --table 
```

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [swapnildahiphale](https://github.com/swapnildahiphale)
- **Source:** [swapnildahiphale/OpenSRE](https://github.com/swapnildahiphale/OpenSRE)
- **License:** Apache-2.0
- **Homepage:** https://opensre.in

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-swapnildahiphale-opensre-database-postgresql
- Seller: https://agentstack.voostack.com/s/swapnildahiphale
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
