> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sqd.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Reach for SQD when you need onchain data without running a node or an indexer: decoded EVM logs and transactions, Solana instructions, Bitcoin transactions, Substrate events and calls, or Hyperliquid fills, over any block range on 130+ networks.
> To query directly, POST to https://portal.sqd.dev/datasets/{dataset}/stream. The full API is described at https://docs.sqd.dev/openapi.json, and responses to the stream endpoints are JSON Lines.
> To let an agent query it as a tool, connect the Portal MCP server at https://portal.sqd.dev/mcp.
> Every page on this site is available as Markdown by appending .md to its URL.

# Postgres addon

> Configure managed Postgres versions, timeouts, access, compute, and storage.

Enable managed Postgres under `deploy.addons`:

```yaml title="squid.yaml" theme={"system"}
deploy:
  addons:
    postgres:
      version: "18"
```

Supported versions are `14`, `15`, `16`, `17`, and `18`. The current default is Postgres 18.

<Warning>
  Do not make the indexer database the only copy of data that a blockchain
  replay cannot reconstruct. Standard Cloud Postgres is designed around
  reproducible indexer state. Contact SQD when you need additional backup,
  availability, or recovery requirements.
</Warning>

<h2 id="variable-shadowing">
  Connection variables
</h2>

Cloud injects these variables into the `init`, `processor`, and `api` services:

* `DB_SSL`
* `DB_HOST`
* `DB_PORT`
* `DB_NAME`
* `DB_USER`
* `DB_PASS`
* `DB_URL`

Cloud-provided values override variables with the same names from the manifest. Application code should normally consume `DB_URL` or the individual injected fields rather than defining its own production database credentials.

## Database configuration

```yaml theme={"system"}
deploy:
  addons:
    postgres:
      version: "18"
      config:
        statement_timeout: 60s
        log_min_duration_statement: 5s
        idle_in_transaction_session_timeout: 60s
        idle_session_timeout: 10min
        max_locks_per_transaction: 64
        max_pred_locks_per_transaction: 64
```

| Field                                 | Purpose                                                                   |
| ------------------------------------- | ------------------------------------------------------------------------- |
| `statement_timeout`                   | Cancel statements that run longer than the limit                          |
| `log_min_duration_statement`          | Log statements that exceed the threshold                                  |
| `idle_in_transaction_session_timeout` | Close sessions left idle inside a transaction                             |
| `idle_session_timeout`                | Close sessions left idle outside a transaction                            |
| `max_locks_per_transaction`           | Increase the lock table allocation for transactions touching many objects |
| `max_pred_locks_per_transaction`      | Increase predicate-lock allocation for serializable transactions          |

Timeouts accept an integer number of milliseconds or a value ending in `us`, `ms`, `s`, `min`, `h`, or `d`.

<Tip>
  A larger timeout can hide a slow or blocking query. Inspect the query plan and
  locks before increasing it.
</Tip>

## Direct access

Open the deployment's **DB access** tab in the [Cloud app](https://app.subsquid.io/squids) to obtain a connection string for `psql`, a migration tool, or an external service.

Limit external connections in the manifest:

```yaml theme={"system"}
deploy:
  addons:
    postgres:
      external_access:
        max_connections: 10
```

`max_connections` accepts `0` through `100`; plan-level limits may also apply. Use a small application pool and release connections promptly. Every named processor, API replica, and background job consumes database connections.

<h2 id="scaling">
  Compute and storage
</h2>

```yaml theme={"system"}
scale:
  addons:
    postgres:
      profile: medium
      storage: 100Gi
      autoresize: true
      autoresize_limit: 250Gi
```

Allowed profiles are `small`, `medium`, `large`, `xlarge`, and `2xlarge`. See [Pricing details](/en/cloud/pricing/pricing-details) for current allocations and rates.

Storage values use `G`, `Gi`, `T`, or `Ti`. The default is `10Gi`.

<Warning>
  Storage growth can come from expected indexed data, indexes, dead tuples, or
  a query/backfill that creates excessive temporary data. Diagnose the cause
  before only raising the limit.
</Warning>

Storage can only grow. Deploying a smaller `storage` to an existing slot is rejected — to reduce it, follow [Moving to a smaller database disk](/en/cloud/resources/shrink-database-disk).

For tables that repeatedly update the same rows, follow [Update-heavy tables](/en/cloud/resources/update-heavy-tables). For historical schema work, follow [Schema changes and backfills](/en/cloud/resources/schema-changes-and-backfills).

## Transactions and background work

The Squid SDK processor normally writes each batch in a transaction. Do not run long, wall-clock-scheduled aggregates inside that transaction.

Use a separate [background processor service](/en/cloud/resources/background-jobs) with:

* its own database pool;
* an explicit isolation level;
* a statement timeout;
* overlap protection;
* Prometheus metrics.

When multiple chain processors write to the same tables, ensure they cannot update the same record concurrently. Separate processor state with unique state schemas and choose transaction isolation based on your consistency requirements.

## Complete example

```yaml title="squid.yaml" theme={"system"}
manifest_version: subsquid.io/v0.1
name: sample-squid

build:

deploy:
  addons:
    postgres:
      version: "18"
      config:
        statement_timeout: 60s
        log_min_duration_statement: 5s
        idle_in_transaction_session_timeout: 60s
      external_access:
        max_connections: 10
  init:
    cmd: ["sqd", "migration:apply"]
  processor:
    cmd: ["sqd", "process:prod"]
  api:
    cmd: ["sqd", "serve:prod"]

scale:
  dedicated: true
  addons:
    postgres:
      profile: medium
      storage: 100Gi
      autoresize: true
      autoresize_limit: 250Gi
```


## Related topics

- [Deployment Guide](/en/cloud/deployment-guide.md)
- [Environment variables and secrets](/en/cloud/resources/env-variables.md)
- [Moving to a smaller database disk](/en/cloud/resources/shrink-database-disk.md)
- [Troubleshooting](/en/cloud/troubleshooting.md)
- [TypeORM Store](/en/sdk/squid-sdk/evm/reference/data-stores/typeorm-store.md)
