Skip to content

Commit e17e2d8

Browse files
ericpaulsenKatie Horne
andauthored
add timescale migration & clean up postgres stuff (coder#607)
* add timescale migration & clean up postgres stuff * colin's feedback * Edit text * Clarify user * Update manifest * fix code blocks Co-authored-by: Katie Horne <katie@coder.com>
1 parent fbe977b commit e17e2d8

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

guides/admin/timescale-migration.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
title: Database migration
3+
description: Learn how to migrate data from Coder's built-in database.
4+
---
5+
6+
By default, Coder deploys a built-in database in the installation's Kubernetes
7+
namespace. We recommend using this database _only_ for evaluation purposes.
8+
9+
At the end of your evaluation period, you may need to migrate the data from the
10+
built-in database to an out-of-cluster PostgreSQL database for production use.
11+
This article will walk you through the process of doing so.
12+
13+
> You must be a cluster admin for your Kubernetes cluster.
14+
15+
## Migration Steps
16+
17+
1. Access the database pod and dump the database into a file:
18+
19+
```console
20+
kubectl exec -it statefulset/timescale -n coder -- pg_dump -U coder -d coder > backup.sql
21+
```
22+
23+
1. **Optional**: If your database is large, you can truncate Coder's telemetry,
24+
metrics, and audit log data to reduce the file size:
25+
26+
```sql
27+
TRUNCATE metric_events;
28+
TRUNCATE environment_stats;
29+
TRUNCATE audit_logs;
30+
```
31+
32+
1. Access your PostgreSQL instance and create user `coder` and database `coder`
33+
34+
1. Import the data you exported in the first step into your external database:
35+
36+
```sql
37+
psql -U coder < backup.sql
38+
```
39+
40+
1. Connect your Coder instance to the database:
41+
42+
```console
43+
helm upgrade --reuse-values -n coder coder coder/coder \
44+
--set postgres.default.enable=false \
45+
--set postgres.host=<HOST_ADDRESS> \
46+
--set postgres.port=<PORT_NUMBER> \
47+
--set postgres.user=<DATABASE_USER> \
48+
--set postgres.database=<DATABASE_NAME> \
49+
--set postgres.passwordSecret=<secret-name> \
50+
--set postgres.sslMode=require
51+
```
52+
53+
1. **Optional**: If you'd like to delete the Timescale persistent volume, run:
54+
55+
```console
56+
kubectl delete pvc timescale-data-timescale-0 -n coder
57+
```
58+
59+
At this point, you should be able to log in to your Coder deployment
60+
successfully.

guides/deployments/postgres.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ streamline maintenance operations, such as backups and upgrades. The database
1616
state is _not_ backed up and will be lost when deleting the Kubernetes namespace
1717
or cluster.
1818

19+
## Configuration steps
20+
1921
> For optimal performance, it is important to ensure that the round-trip latency
2022
> between the Coder control plane services and the database is low. We recommend
2123
> ensuring that the database is within the same data center as the control

manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@
300300
{
301301
"path": "./guides/admin/resources.md"
302302
},
303+
{
304+
"path": "./guides/admin/timescale-migration.md"
305+
},
303306
{
304307
"path": "./guides/admin/helm-charts.md"
305308
},

setup/installation.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ kubectl config set-context --current --namespace=coder
8484

8585
```yaml
8686
postgres:
87-
useDefault: false
87+
default:
88+
enable: false
8889
host: HOST_ADDRESS
8990
port: PORT_NUMBER
9091
user: YOUR_USER_NAME

0 commit comments

Comments
 (0)