Files
coder/docs/tutorials/external-database.md
T
Nick Vigilante c58ac71ca3 docs(docs/tutorials): reformat to one sentence per line (#30703)
Reformats the tutorials under `docs/tutorials` to one sentence per line,
as the [docs style
guide](https://github.com/coder/coder/blob/main/docs/.style/style-guide/formatting.md#one-sentence-per-line)
requires. Hard-wrapped paragraphs are unwrapped and lines holding
several sentences are split, so a later edit to one sentence shows up as
a one-line diff.

Apart from the exception below, only whitespace inside paragraphs and
list items changes, and the rendered pages are the same. Comparing the
changed files against `main` word for word, ignoring whitespace and
blockquote `>` markers, finds differences only on the reworded lines.
`git diff --word-diff` is easier to read than the line diff.

9 lines that already contained an em or en dash were reworded by hand,
because `lint/emdash` treats every reflowed line as newly added. Each
uses a parenthetical, a separate sentence, or a colon after a lead-in.
Dashes on lines the reflow did not touch are left alone. The two reverse
proxy tutorials also write `*.coder.example.com` in backticks instead of
escaping the asterisk, which the formatter would otherwise drop.

Applied with an in-progress formatter, limited to pages listed in
`docs/manifest.json` and excluding generated reference docs. This is one
of a batch of PRs that split the docs by area (19 files changed, 656
insertions(+), 1265 deletions(-)).

---
🤖 Built with AI assistance.
2026-10-15 11:24:40 -04:00

2.2 KiB

title
title
Use Coder with an external database

Recommendation

For production deployments, we recommend using an external PostgreSQL database (version 13 or higher).

Basic configuration

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.

With psql:

CREATE ROLE coder LOGIN SUPERUSER PASSWORD 'secret42';

With psql -U coder:

CREATE DATABASE coder;

Coder configuration is defined via environment variables. The database client requires the connection string provided via the CODER_PG_CONNECTION_URL variable.

export CODER_PG_CONNECTION_URL="postgres://coder:secret42@localhost/coder?sslmode=disable"

Custom schema

For installations with elevated security requirements, it's advised to use a separate schema instead of the public one.

With psql -U coder:

CREATE SCHEMA myschema;

Once the schema is created, you can list all schemas with \dn:

List of schemas
 Name      | Owner
-----------+----------
 myschema  | coder
 public    | postgres
(2 rows)

In this case the database client requires the modified connection string:

export CODER_PG_CONNECTION_URL="postgres://coder:secret42@localhost/coder?sslmode=disable&search_path=myschema"

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:

SHOW search_path;

search_path
--------------
 "$user", public

Using the search_path in the connection string corresponds to the following psql command:

ALTER ROLE coder SET search_path = myschema;

Troubleshooting

coder server fails startup with "current_schema: converting NULL to string is unsupported"

Please make sure that the schema selected in the connection string ...&search_path=myschema exists and the role has granted permissions to access it. The schema should be present on this listing:

psql -U coder -c '\dn'