Skip to content

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
merged 4 commits into from
Nov 4, 2022

Conversation

mtojek
Copy link
Member

@mtojek mtojek commented Nov 4, 2022

Fixes: #3508

(preview)

This PR adds an extra documentation page about setting up the external PostgreSQL server and the connection string.

@mtojek mtojek self-assigned this Nov 4, 2022
@mtojek mtojek requested a review from a team November 4, 2022 15:49
@mtojek mtojek marked this pull request as ready for review November 4, 2022 15:49
Copy link
Member

@deansheather deansheather left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

The database client requires the connection string provided via the `CODER_PG_CONNECTION_URL` variable.

```sh
export CODER_PG_CONNECTION_URL="postgres://coder@localhost/coder?password=secret42&sslmode=disable"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've only seen the URL formatted as postgres://coder:secret42@localhost/coder?sslmode=disable before, does the password query param work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, these are interchangeable, but I can adjust to the standard pattern user:password.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We seem to actually be using a mixture of both. It might be a good idea for us to standardize behind one usage (see rg postgres:// in repo). But that would be something for a separate PR.

@deansheather deansheather requested review from ammario and bpmct November 4, 2022 15:52
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

With `psql`:

```sql
CREATE ROLE coder LOGIN SUPERUSER PASSWORD 'secret42';
Copy link
Member

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 😄

Copy link
Member Author

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 :)

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

```sql
SET search_path TO myschema;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we want to confuse readers, but this would also be an option:

ALTER ROLE coder SET search_path = myschema;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, once altered you don't need to set it every time.


## Troubleshooting

### Coder server fails startup with "current_schema: converting NULL to string is unsupported"
Copy link
Member

Choose a reason for hiding this comment

The 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! ❤️

mtojek and others added 3 commits November 4, 2022 18:04
Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
@mtojek mtojek merged commit dad8945 into coder:main Nov 4, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Nov 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add instructions to docs for setting up an external PostgreSQL server with Coder
3 participants