-
Notifications
You must be signed in to change notification settings - Fork 892
docs: Setup external PostgreSQL server #4901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mtojek
merged 4 commits into
coder:main
from
mtojek:3508-instructions-external-postgresql
Nov 4, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ran into this as well when testing it the first time. I love that you added it! ❤️ |
||
|
||
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could consider creating a lower privilege user and granting all on the
coder
database instead. But this is for sure simpler. So up to you 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Frankly speaking, I would rather keep it simple here. Those, who want to configure the database considering the security requirements can always tweak it :)