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

# PostgreSQL

> Run PostgreSQL in your infrastructure with continuous backups and point-in-time restore, and connect services to it.

The PostgreSQL add-on runs a PostgreSQL database inside your infrastructure, managed by [CloudNativePG](https://cloudnative-pg.io). It's backed up continuously to your own cloud account, and you can restore it to any point inside the retention window.

## Install

In the **App Store**, choose **PostgreSQL** and fill in:

| Field | Notes |
| - | - |
| **Infrastructure** | Where the database runs |
| **Instance name** | How services refer to it, for example `main`. Can't be changed later. |
| **Postgres version** | 16, 17 or 18. The default is 18. |
| **Backup hour (UTC)** | When the daily base backup runs. The default is 03:00. |
| **Memory** and **Storage** | The database's size |

The first install asks you to run a short script that creates the identity PostgreSQL writes its backups with. Until you run it and click **Verify**, nothing is created.

## Connect a service

```yaml inframan.yaml theme={null}
services:
  api:
    port: 8080
    connections:
      DATABASE_URL: postgres/main
```

`DATABASE_URL` receives a URL of the form:

```text theme={null}
postgresql://<user>:<password>@<host>.svc.cluster.local:<port>/<database>?sslmode=require
```

The connection requires TLS. The database is reachable only from inside the cluster.

## Backups

* **Continuous:** every change is archived as it's written, through PostgreSQL's write-ahead log.
* **Daily:** a full base backup at the backup hour you chose.
* **Retention:** 7 days on non-production infrastructures.
* **On demand:** click **Back up now** on the **Backups** tab.

Backups are stored in your cloud account.

## Restore

A restore never overwrites your database. It creates a **new** PostgreSQL instance on the same infrastructure, so the original stays exactly as it was until you decide what to do with it.

1. Open the instance and select the **Backups** tab.
2. Choose to restore, then pick what to **Recover to**: a backup, or a **Point in time** within the retention window.
3. Name the new instance and create it.
4. Point your services at the new instance by changing their connection, for example `DATABASE_URL: postgres/main-restored`, and deploy.

## Monitoring

The instance's **Monitoring** tab charts capacity, persistence, throughput, connections and resources. The **Overview** tab runs health checks for:

* The database being down.
* Connections close to the limit.
* Transaction ID wraparound risk.

A connected AI assistant can read 16 PostgreSQL metrics by name, including `connections`, `cache_hit_rate`, `database_size`, `deadlocks`, `replication_lag` and `longest_transaction`.

## Limits

* One tier, **Basic**: a single PostgreSQL instance.
* On Google Cloud the database gets its own node pool, which uses Spot nodes. When a node is reclaimed, the database restarts on a new one from its persistent volume.
* Importing an existing database from a dump isn't available on AWS.


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