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