|
| 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. |
0 commit comments