Skip to content

Commit a09d2af

Browse files
author
Katie Horne
authored
chore: add basic postgres instructions for byo databases (#2430)
1 parent 0c9ff3a commit a09d2af

File tree

2 files changed

+103
-1
lines changed

2 files changed

+103
-1
lines changed

docs/manifest.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@
1111
"title": "Installation",
1212
"description": "How to install and deploy Coder",
1313
"icon": "<svg class=\"MuiSvgIcon-root jss172\" focusable=\"false\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M22.7 19l-9.1-9.1c.9-2.3.4-5-1.5-6.9-2-2-5-2.4-7.4-1.3L9 6 6 9 1.6 4.7C.4 7.1.9 10.1 2.9 12.1c1.9 1.9 4.6 2.4 6.9 1.5l9.1 9.1c.4.4 1 .4 1.4 0l2.3-2.3c.5-.4.5-1.1.1-1.4z\"></path></svg>",
14-
"path": "./install.md"
14+
"path": "./install.md",
15+
"children": [
16+
{
17+
"title": "Postgres",
18+
"description": "Learn how to create and use your own Postgres database.",
19+
"path": "./postgres.md"
20+
}
21+
]
1522
},
1623
{
1724
"title": "Quickstart",

docs/postgres.md

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# PostgreSQL
2+
3+
Coder ships with a built-in PostgreSQL database, but if you'd like to set up and
4+
use your own, refer to the following instructions.
5+
6+
For in-depth information, please see the [PostgreSQL
7+
documentation](https://www.postgresql.org/docs/current/tutorial-start.html).
8+
9+
## Step 1: Install and start PostgreSQL
10+
11+
### macOS with Homebrew
12+
13+
1. Install with Homebrew:
14+
15+
```console
16+
brew install postgres
17+
```
18+
19+
1. Start PostgreSQL with brew
20+
21+
```console
22+
brew services start postgresql
23+
```
24+
25+
1. Connect to PostgreSQL:
26+
27+
```console
28+
psql postgres
29+
```
30+
31+
### Debian/Ubuntu
32+
33+
1. Install PostgreSQL:
34+
35+
```console
36+
sudo apt-get install -y postgresql
37+
```
38+
39+
1. Start PostgreSQL:
40+
41+
```console
42+
sudo systemctl enable postgresql
43+
sudo systemctl start postgresql
44+
```
45+
46+
1. Connect to PostgreSQL:
47+
48+
```console
49+
sudo -u postgresql psql
50+
```
51+
52+
## Step 2: Create a database and user for Coder
53+
54+
1. Create the `coderuser` role:
55+
56+
```console
57+
create role coderuser with login;
58+
```
59+
60+
1. Create a database called `coder` and assign the owner:
61+
62+
```console
63+
create database coder owner coder;
64+
```
65+
66+
1. Set the password for `coderuser`:
67+
68+
```console
69+
\password coder # enter password when prompted
70+
```
71+
72+
1. Assign rights to the database to your user:
73+
74+
```console
75+
grant all privileges on database coder to coderuser;
76+
```
77+
78+
## Using your PostgreSQL database with Coder
79+
80+
To use your Postgres database with Coder, provide the `CODER_PG_CONNECTION_URL`
81+
variable:
82+
83+
```console
84+
postgresql://[user[:password]@][networkLocation][:port][/dbname][?param1=value1&...]
85+
```
86+
87+
Append to `coder server` to start your deployment. For example:
88+
89+
```console
90+
CODER_PG_CONNECTION_URL="postgres://<databaseUsername>@0.0.0.0/<databaseName>?sslmode=disable&password=<password>" \
91+
coder server -a 0.0.0.0:3000 --verbose
92+
```
93+
94+
> If you [installed Coder manually](install.md), you can add the `CODER_PG_CONNECTION_URL`
95+
variable to `/etc/coder.d/coder.env`.

0 commit comments

Comments
 (0)