> ## Documentation Index
> Fetch the complete documentation index at: https://akua-1dce587a.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Database Operations

> Run SQL queries, check Redis memory, and inspect databases, all through exec

![An exec call carrying a command that crosses into a pod container to run psql and redis-cli shells, returning a table-size report and a Redis memory stat as evidence](https://mintcdn.com/akua-1dce587a/AEEz0U2s7Do2sYaM/images/heros/ai-database-operations-light.svg?fit=max\&auto=format\&n=AEEz0U2s7Do2sYaM\&q=85\&s=88f412ea3f8539c44e157218cf6a20e2)

The [exec endpoint](https://akua-1dce587a.mintlify.site/ai/kubernetes-access.md#command-execution) isn't just for running `echo hello`. Agents use it to interact with databases, caches, and any CLI tool running inside a container, turning natural language into actual application-level operations.

## PostgreSQL: Table size report

An agent asked "what's the largest table in my Postgres?" runs `psql` inside the container:

```js theme={null}
async () => {
  const clusterId = "cls_abc123"; // resolved by the agent from conversation

  const res = await platform.request({
    method: "POST",
    path: `/v1/clusters/${clusterId}:exec`,
    body: {
      namespace: "default",
      pod: "postgres-0",
      container: "postgresql",
      command: ["psql", "-U", "postgres", "-c", `
        SELECT schemaname, tablename,
               pg_size_pretty(pg_total_relation_size(schemaname || '.' || tablename)) AS total_size,
               pg_size_pretty(pg_relation_size(schemaname || '.' || tablename)) AS data_size,
               pg_size_pretty(pg_indexes_size(schemaname || '.' || quote_ident(tablename))) AS index_size,
               n_live_tup AS row_count
        FROM pg_stat_user_tables
        ORDER BY pg_total_relation_size(schemaname || '.' || tablename) DESC
        LIMIT 15;
      `]
    }
  });
  return res.body;
}
```

The agent gets back formatted SQL output with table sizes, index sizes, and row counts. It can then reason about which tables need vacuuming, which indexes are bloated, or whether a migration is needed.

## Redis: Memory analysis

```js theme={null}
async () => {
  const clusterId = "cls_abc123"; // resolved by the agent from conversation

  const info = await platform.request({
    method: "POST",
    path: `/v1/clusters/${clusterId}:exec`,
    body: {
      namespace: "default",
      pod: "redis-0",
      container: "redis",
      command: ["redis-cli", "INFO", "memory"]
    }
  });

  const stats = await platform.request({
    method: "POST",
    path: `/v1/clusters/${clusterId}:exec`,
    body: {
      namespace: "default",
      pod: "redis-0",
      container: "redis",
      command: ["redis-cli", "INFO", "keyspace"]
    }
  });

  return { memory: info.body.output, keyspace: stats.body.output };
}
```

## Chaining queries

The agent can chain multiple queries in a single execution, checking replication lag and then inspecting the slowest queries:

```js expandable theme={null}
async () => {
  const clusterId = "cls_abc123"; // resolved by the agent from conversation

  const exec = (command) => platform.request({
    method: "POST",
    path: `/v1/clusters/${clusterId}:exec`,
    body: {
      namespace: "default",
      pod: "postgres-0",
      container: "postgresql",
      command: ["psql", "-U", "postgres", "-t", "-A", "-c", command]
    }
  }).then(r => r.body.output.trim());

  const [replLag, slowQueries, connCount, dbSize] = await Promise.all([
    exec("SELECT CASE WHEN pg_is_in_recovery() THEN extract(epoch FROM now() - pg_last_xact_replay_timestamp())::int || 's' ELSE 'primary' END"),
    exec("SELECT query, calls, mean_exec_time::int || 'ms' FROM pg_stat_statements ORDER BY mean_exec_time DESC LIMIT 5"),
    exec("SELECT count(*) FROM pg_stat_activity WHERE state = 'active'"),
    exec("SELECT pg_size_pretty(pg_database_size(current_database()))"),
  ]);

  return { replication_lag: replLag, slow_queries: slowQueries, active_connections: connCount, database_size: dbSize };
}
```

Four `psql` queries in parallel: replication lag, slowest queries, active connections, database size. All from one `execute` call.

## Why this matters

Database operations through traditional MCP tools would need a dedicated tool per database type (`postgres-query`, `redis-info`, `mongo-stats`), each with their own schema, parameters, and maintenance burden.

With exec + Code Mode, the agent writes the exact command it needs. It knows `psql` flags, `redis-cli` subcommands, and `mongosh` syntax from its training data. No pre-built tools required. The agent composes the right command for any database, any query.

> [!NOTE]
>
> Exec is non-interactive with a 30-second timeout. It's ideal for read queries and diagnostics. For long-running operations or interactive sessions, use the dashboard terminal.

## Related topics

> **[Full-stack dashboard in minutes](https://akua-1dce587a.mintlify.site/ai/examples/dashboard-in-minutes.md)**
>
> Combine database exec queries with cluster health in one dashboard.

> **[Kubernetes access](https://akua-1dce587a.mintlify.site/ai/kubernetes-access.md)**
>
> The exec endpoint request and response shape.

> **[Incident debugging](https://akua-1dce587a.mintlify.site/ai/examples/incident-debugging.md)**
>
> Adaptive SRE triage using pod health, events, and logs.

> **[Code Mode in action](https://akua-1dce587a.mintlify.site/ai/code-mode-in-action.md)**
>
> How agents chain multiple operations in one call.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.