2026-09-08 12:34:00 -04:00
---
title : Use Coder with an external database
---
2024-10-05 08:52:04 -07:00
2022-11-04 21:15:03 +01:00
## Recommendation
2026-10-15 11:24:40 -04:00
For production deployments, we recommend using an external [PostgreSQL ](https://www.postgresql.org/ ) database (version 13 or higher).
2022-11-04 21:15:03 +01:00
## Basic configuration
2026-10-15 11:24:40 -04:00
Before starting the control plane, prepare the database server by creating a role and a database.
Remember that the role must have access to the created database.
2022-11-04 21:15:03 +01:00
With `psql` :
```sql
CREATE ROLE coder LOGIN SUPERUSER PASSWORD 'secret42' ;
```
With `psql -U coder` :
```sql
CREATE DATABASE coder ;
```
2026-10-15 11:24:40 -04:00
Coder configuration is defined via [environment variables ](../admin/setup/index.md ).
The database client requires the connection string provided via the `CODER_PG_CONNECTION_URL` variable.
2022-11-04 21:15:03 +01:00
2026-07-15 14:07:09 -04:00
```sh
2022-11-04 21:15:03 +01:00
export CODER_PG_CONNECTION_URL = "postgres://coder:secret42@localhost/coder?sslmode=disable"
```
## Custom schema
2026-10-15 11:24:40 -04:00
For installations with elevated security requirements, it's advised to use a separate [schema ](https://www.postgresql.org/docs/current/ddl-schemas.html ) instead of the public one.
2022-11-04 21:15:03 +01:00
With `psql -U coder` :
```sql
CREATE SCHEMA myschema ;
```
Once the schema is created, you can list all schemas with `\dn` :
2026-07-15 14:07:09 -04:00
```txt
2025-01-03 18:12:59 +05:00
List of schemas
Name | Owner
2022-11-04 21:15:03 +01:00
-----------+----------
myschema | coder
public | postgres
(2 rows)
```
In this case the database client requires the modified connection string:
2026-07-15 14:07:09 -04:00
```sh
2022-11-04 21:15:03 +01:00
export CODER_PG_CONNECTION_URL = "postgres://coder:secret42@localhost/coder?sslmode=disable&search_path=myschema"
```
2026-10-15 11:24:40 -04:00
The `search_path` parameter determines the order of schemas in which they are visited while looking for a specific table.
The first schema named in the search path is called the current schema.
By default `search_path` defines the following schemas:
2022-11-04 21:15:03 +01:00
```sql
SHOW search_path ;
search_path
--------------
"$user" , public
```
2026-10-15 11:24:40 -04:00
Using the `search_path` in the connection string corresponds to the following `psql` command:
2022-11-04 21:15:03 +01:00
```sql
ALTER ROLE coder SET search_path = myschema ;
```
## Troubleshooting
2026-09-22 15:18:40 -04:00
### `coder server` fails startup with "current_schema: converting NULL to string is unsupported"
2022-11-04 21:15:03 +01:00
2026-10-23 21:18:34 -07:00
Make sure that the schema selected in the connection string `...&search_path=myschema` exists and the role has granted permissions to access it.
2026-10-15 11:24:40 -04:00
The schema should be present on this listing:
2022-11-04 21:15:03 +01:00
2026-07-15 14:07:09 -04:00
```sh
2022-11-04 21:15:03 +01:00
psql -U coder -c '\dn'
```