Skip to content

Commit ee10a50

Browse files
committed
Merge branch 'main' into colin/pd-metrics
2 parents c44dcf6 + 8dd567d commit ee10a50

File tree

3 files changed

+95
-4
lines changed

3 files changed

+95
-4
lines changed

cli/server.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,16 +516,14 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
516516
}
517517
defer closeUsersFunc()
518518

519-
closeWorkspacesFunc, err := prometheusmetrics.Workspaces(ctx, options.PrometheusRegistry, options.Database, 0)
519+
closeWorkspacesFunc, err := prometheusmetrics.Workspaces(ctx, options.PrometheusRegisterer, options.Database, 0)
520520
if err != nil {
521521
return xerrors.Errorf("register workspaces prometheus metric: %w", err)
522522
}
523523
defer closeWorkspacesFunc()
524524

525525
//nolint:revive
526-
defer serveHandler(ctx, logger, promhttp.InstrumentMetricHandler(
527-
options.PrometheusRegistry, promhttp.HandlerFor(options.PrometheusRegistry, promhttp.HandlerOpts{}),
528-
), cfg.Prometheus.Address.Value, "prometheus")()
526+
defer serveHandler(ctx, logger, promhttp.Handler(), cfg.Prometheus.Address.Value, "prometheus")()
529527
}
530528

531529
// We use a separate coderAPICloser so the Enterprise API

docs/install/database.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
## Recommendation
2+
3+
For production deployments, we recommend using an external [PostgreSQL](https://www.postgresql.org/) database (version 13 or higher).
4+
5+
## Basic configuration
6+
7+
Before starting the Coder server, prepare the database server by creating a role and a database.
8+
Remember that the role must have access to the created database.
9+
10+
With `psql`:
11+
12+
```sql
13+
CREATE ROLE coder LOGIN SUPERUSER PASSWORD 'secret42';
14+
```
15+
16+
With `psql -U coder`:
17+
18+
```sql
19+
CREATE DATABASE coder;
20+
```
21+
22+
Coder configuration is defined via [environment variables](../admin/configure.md).
23+
The database client requires the connection string provided via the `CODER_PG_CONNECTION_URL` variable.
24+
25+
```sh
26+
export CODER_PG_CONNECTION_URL="postgres://coder:secret42@localhost/coder?sslmode=disable"
27+
```
28+
29+
## Custom schema
30+
31+
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.
32+
33+
With `psql -U coder`:
34+
35+
```sql
36+
CREATE SCHEMA myschema;
37+
```
38+
39+
Once the schema is created, you can list all schemas with `\dn`:
40+
41+
```
42+
List of schemas
43+
Name | Owner
44+
-----------+----------
45+
myschema | coder
46+
public | postgres
47+
(2 rows)
48+
```
49+
50+
In this case the database client requires the modified connection string:
51+
52+
```sh
53+
export CODER_PG_CONNECTION_URL="postgres://coder:secret42@localhost/coder?sslmode=disable&search_path=myschema"
54+
```
55+
56+
The `search_path` parameter determines the order of schemas in which they are visited while looking for a specific table.
57+
The first schema named in the search path is called the current schema. By default `search_path` defines the following schemas:
58+
59+
```sql
60+
SHOW search_path;
61+
62+
search_path
63+
--------------
64+
"$user", public
65+
```
66+
67+
Using the `search_path` in the connection string corresponds to the following `psql` command:
68+
69+
```sql
70+
ALTER ROLE coder SET search_path = myschema;
71+
```
72+
73+
## Troubleshooting
74+
75+
### Coder server fails startup with "current_schema: converting NULL to string is unsupported"
76+
77+
Please make sure that the schema selected in the connection string `...&search_path=myschema` exists
78+
and the role has granted permissions to access it. The schema should be present on this listing:
79+
80+
```sh
81+
psql -U coder -c '\dn'
82+
```
83+
84+
## Next steps
85+
86+
- [Quickstart](../quickstart.md)
87+
- [Configuring Coder](../admin/configure.md)
88+
- [Templates](../templates.md)

docs/manifest.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
"description": "Run Coder in offline / air-gapped environments",
5656
"path": "./install/offline.md"
5757
},
58+
{
59+
"title": "External database",
60+
"description": "Use external PostgreSQL database",
61+
"path": "./install/database.md"
62+
},
5863
{
5964
"title": "Uninstall",
6065
"description": "Learn how to uninstall Coder",

0 commit comments

Comments
 (0)