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

# Run a PostgreSQL database

> An Azure infrastructure pattern, deployed with formae.

A managed PostgreSQL Flexible Server reachable from a chosen IP address and from
Azure services. One forma provisions the resource group, the PostgreSQL Flexible
Server, and two firewall rules that open access to your own IP address and to
other Azure services.

```mermaid theme={"languages":{"custom":["/languages/pkl.json"]}}
flowchart LR
  target["database-target-azure-2"]:::tgt

  subgraph stack["azure-database-westus"]
    direction LR
    rg["Resource group"]:::res
    pg["PostgreSQL server"]:::res
    myIp["AllowMyIP firewall rule"]:::res
    azSvc["Allow Azure services rule"]:::res

    rg --> pg
    rg --> myIp
    rg --> azSvc
    pg --> myIp
    pg --> azSvc
  end

  target --> stack

  classDef tgt fill:#FF8201,stroke:#B25900,color:#ffffff
  classDef res fill:#FFF3E6,stroke:#FF8201,color:#02024B
  style stack fill:#ffffff,stroke:#02024B,stroke-width:2px,stroke-dasharray:6 4,color:#02024B
```

**Deploy.** Apply the example forma. formae orders the resources by their
dependencies automatically, so the resource group comes up before the server,
and the server before its firewall rules:

```bash theme={"languages":{"custom":["/languages/pkl.json"]}}
formae apply --mode reconcile \
  /opt/pel/formae/examples/formae-plugin-azure/database/main.pkl
```

**Verify.** Once the command completes, the server is under management:

```bash theme={"languages":{"custom":["/languages/pkl.json"]}}
formae inventory resources --query="type:AZURE::DBforPostgreSQL::FlexibleServer"
```

**Tear down.** Remove everything the forma created:

```bash theme={"languages":{"custom":["/languages/pkl.json"]}}
formae destroy \
  /opt/pel/formae/examples/formae-plugin-azure/database/main.pkl
```

The full forma is in the
[database example](https://github.com/platform-engineering-labs/formae-plugin-azure/tree/main/examples/database).
