Skip to content

Commit d9d66c7

Browse files
note ssl connection error and solution in managed postgres docs
1 parent 210e1e5 commit d9d66c7

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

docs/concepts/managed-storage/managed-postgres.mdx

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,43 @@ You can also set the following optional environment variables to configure the m
3737

3838
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.
3939

40+
#### SSL
41+
42+
By default, Defang configures managed Postgres instances to require SSL connections. To connect to the database, you will need to use a connection string that includes `sslmode=require`.
43+
44+
If your application does not connect using SSL, you will see an error message like the following:
45+
46+
```
47+
error: no pg_hba.conf entry for host "10.0.12.123", user "mydbuser", database "myappdatabase", no encryption
48+
```
49+
50+
We recommend setting a defang config variable for the `SSL_MODE`, and then using that variable in your connection string. That way you can keep it empty for local development, and set it to `require` for production.
51+
52+
```
53+
$ defang config set SSL_MODE=require
54+
```
55+
Then you can set up your `compose.yaml` file like this:
56+
```yaml
57+
app:
58+
# [...]
59+
environment:
60+
POSTGRES_HOST: database
61+
POSTGRES_USER: postgres
62+
POSTGRES_DB: postgres
63+
POSTGRES_PASSWORD: # load from defang config
64+
# Note: you can create a connection string by using interpolation,
65+
# reference config variables by using ${<config name>}
66+
POSTGRES_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}?sslmode=${SSL_MODE}
67+
db:
68+
image: postgres:18
69+
x-defang-postgres: true
70+
ports:
71+
- mode: host
72+
target: 5432
73+
environment:
74+
POSTGRES_PASSWORD: # load from defang config
75+
```
76+
4077
### Example
4178
4279
:::info
@@ -59,7 +96,7 @@ For a smoother experience with Defang, we recommend using Postgres 14 for your c
5996
# reference config variables by using ${<config name>}
6097
CONNECTURL: postgresql://postgres:${POSTGRES_PASSWORD}@database:5432/postgres?sslmode=require
6198
database:
62-
image: postgres:14
99+
image: postgres:18
63100
x-defang-postgres: true
64101
ports:
65102
- mode: host
@@ -92,13 +129,13 @@ Please note the upgrading will occur immediately and may result in the database
92129
93130
```
94131
database:
95-
image: postgres:15
132+
image: postgres:17
96133
```
97134
98135
to
99136
100137
```
101138
database:
102-
image: postgres:16
139+
image: postgres:18
103140
```
104141
*/}

0 commit comments

Comments
 (0)