|
| 1 | +--- |
| 2 | +title: Managed Postgres |
| 3 | +description: Defang can help you provision managed Postgres. |
| 4 | +sidebar_position: 1000 |
| 5 | +--- |
| 6 | + |
| 7 | +# Managed Postgres |
| 8 | + |
| 9 | +Postgres, or PostgreSQL, is an advanced open-source relational database system known for its robustness, extensibility, and compliance with SQL standards, making it a popular choice for complex applications requiring reliable data integrity and sophisticated querying capabilities. |
| 10 | + |
| 11 | +## Current Support |
| 12 | + |
| 13 | +| Provider | Managed Postgres | |
| 14 | +| --- | --- | |
| 15 | +| [Playground](/docs/providers/playground) | ❌ | |
| 16 | +| [AWS](/docs/providers/aws/aws.md#managed-postgres) | ✅ | |
| 17 | + |
| 18 | +## How to use Managed Postgres |
| 19 | + |
| 20 | +To use managed Postgres, in your `compose.yaml` file, use the `x-defang-postgres` extension to define your Postgres service. Adding the extension will tell Defang to provision a managed instance, rather than running Postgres as a service. |
| 21 | + |
| 22 | +### Required Configuration |
| 23 | + |
| 24 | +When using managed Postgres, you **must** set a password for the database using `defang config set POSTGRES_PASSWORD`. If you do not provide the password, the deployment will fail. You can can assign the password in the service's environment variables (to learn more about how this works, read about [configuration](../configuration.md)). |
| 25 | + |
| 26 | +### Optional Configuration |
| 27 | + |
| 28 | +You can also set the following environment variables to configure the managed Postgres instance: |
| 29 | + |
| 30 | +- `POSTGRES_USER`: The user for the managed Postgres instance. The default is `postgres`. |
| 31 | +- `POSTGRES_DB`: The database name for the managed Postgres instance. The default is `postgres`. |
| 32 | + |
| 33 | +### Connecting to Managed Postgres |
| 34 | + |
| 35 | +You can connect to the managed Postgres instance using the name of your service as the hostname, `POSTGRES_USER`, `POSTGRES_DB`, and `POSTGRES_PASSWORD` environment variables. |
| 36 | + |
| 37 | +### Example |
| 38 | + |
| 39 | +```yaml |
| 40 | + app: |
| 41 | + # [...] |
| 42 | + environment: |
| 43 | + POSTGRES_HOST: database |
| 44 | + POSTGRES_USER: postgres |
| 45 | + POSTGRES_DB: postgres |
| 46 | + // highlight-start |
| 47 | + # Note: by leaving the value empty, Defang will use the |
| 48 | + # value set using `defang config set POSTGRES_PASSWORD` |
| 49 | + POSTGRES_PASSWORD: |
| 50 | + // highlight-end |
| 51 | + database: |
| 52 | + image: postgres:15 |
| 53 | + x-defang-postgres: true |
| 54 | + restart: unless-stopped |
| 55 | + ports: |
| 56 | + - mode: host |
| 57 | + target: 5432 |
| 58 | + environment: |
| 59 | + // highlight-start |
| 60 | + # Note: by leaving the value empty, Defang will use the |
| 61 | + # value set using `defang config set POSTGRES_PASSWORD` |
| 62 | + POSTGRES_PASSWORD: |
| 63 | + // highlight-end |
| 64 | + |
| 65 | +``` |
0 commit comments