docs: Setup external PostgreSQL server (#4901)

* docs: Setup external PostgreSQL server

* Update docs/install/database.md

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

* Use user:password pattern

* Fix

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
This commit is contained in:
Marcin Tojek 2022-11-04 21:15:03 +01:00 committed by GitHub
parent 8f4ae5b6ac
commit dad89453d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 93 additions and 0 deletions

88
docs/install/database.md Normal file
View File

@ -0,0 +1,88 @@
## Recommendation
For production deployments, we recommend using an external [PostgreSQL](https://www.postgresql.org/) database (version 13 or higher).
## Basic configuration
Before starting the Coder server, prepare the database server by creating a role and a database.
Remember that the role must have access to the created database.
With `psql`:
```sql
CREATE ROLE coder LOGIN SUPERUSER PASSWORD 'secret42';
```
With `psql -U coder`:
```sql
CREATE DATABASE coder;
```
Coder configuration is defined via [environment variables](../admin/configure.md).
The database client requires the connection string provided via the `CODER_PG_CONNECTION_URL` variable.
```sh
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](https://www.postgresql.org/docs/current/ddl-schemas.html) instead of the public one.
With `psql -U coder`:
```sql
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:
```sh
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:
```sql
SHOW search_path;
search_path
--------------
"$user", public
```
Using the `search_path` in the connection string corresponds to the following `psql` command:
```sql
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:
```sh
psql -U coder -c '\dn'
```
## Next steps
- [Quickstart](../quickstart.md)
- [Configuring Coder](../admin/configure.md)
- [Templates](../templates.md)

View File

@ -55,6 +55,11 @@
"description": "Run Coder in offline / air-gapped environments",
"path": "./install/offline.md"
},
{
"title": "External database",
"description": "Use external PostgreSQL database",
"path": "./install/database.md"
},
{
"title": "Uninstall",
"description": "Learn how to uninstall Coder",