|
1 |
| -# db-lab |
| 1 | +# Database Lab - Thin clones for faster development |
| 2 | +Boost your development process |
2 | 3 |
|
| 4 | +<div align="center"> |
| 5 | +  |
| 6 | +</div> |
| 7 | + |
| 8 | +## Install |
| 9 | + |
| 10 | +*Currently, there are no ready-to-use binaries or a Docker image. The setup |
| 11 | +is to be done using the source code.* |
| 12 | + |
| 13 | +1. Get the source code: `git clone https://gitlab.com/postgres-ai/db-lab.git`. |
| 14 | +1. Golang is required. |
| 15 | + - Ubuntu: In some cases, standard Ubuntu package might not work. See |
| 16 | +https://gitlab.com/postgres-ai/db-lab/snippets/1918769. |
| 17 | + - On macOS: `brew install golang` |
| 18 | +1. Install ZFS (Ubuntu: https://gitlab.com/postgres-ai/db-lab/snippets/1918768). |
| 19 | + |
| 20 | +### ZFS Store |
| 21 | +1. Create a ZFS store with a clone of |
| 22 | +the production Postgres database (e.g. using WAL-E, WAL-G or Barman archive). |
| 23 | +1. Shutdown Postgres, create a new ZFS snapshot |
| 24 | +(`sudo zfs snapshot -r zpool@db_state_1`) and remember its name. It will |
| 25 | +be needed for further configuration (`initialSnapshot` option in |
| 26 | +`config/config.yml`). |
| 27 | +1. Start Postgres. |
| 28 | + |
| 29 | + |
| 30 | +## Run |
| 31 | + |
| 32 | +Deploy DB Lab instance in your infrastructure. You would need to: |
| 33 | +1. Create `config/config.yml` (see sample in `config/`). |
| 34 | +1. Build `make all` and run DB Lab with some token for REST API authorization |
| 35 | +`./bin/dblab -v some-token` (or, with log: `./bin/dblab -v some-token 2>&1 | tee -a dblab.log`). |
| 36 | + |
| 37 | + |
| 38 | +## REST API |
| 39 | + |
| 40 | +Instance statuses: |
| 41 | +- `OK` - instance functions well. |
| 42 | +- `WARNING` - still functional, but have some problems, e.g. disk space shortage, insecure connection (upcoming MRs). |
| 43 | + |
| 44 | +Clone statuses: |
| 45 | +- `OK` - clone is ready to accept postgres connections. |
| 46 | +- `CREATING` - clone is being created. |
| 47 | +- `DELETING` - clone is being deleted. |
| 48 | +- `FATAL` - fatal error happened (details in status message). |
| 49 | + |
| 50 | +Basic models: |
| 51 | +``` |
| 52 | +Clone |
| 53 | +{ |
| 54 | + id: "xxx", |
| 55 | + status: { |
| 56 | + code: "OK", |
| 57 | + message: "Database is ready" |
| 58 | + }, |
| 59 | + project: "proj1" |
| 60 | + snapshot: "" (optional, ID or timestamp) |
| 61 | + db: { |
| 62 | + username: "postgres" |
| 63 | + password: "" (never set on DB Lab side) |
| 64 | + host: "xxx", |
| 65 | + port: "xxx", |
| 66 | + connStr: "xxx" |
| 67 | + }, |
| 68 | + protected: true |
| 69 | + deleteAt: "" (timestamp), |
| 70 | + name: "", |
| 71 | + username: "", |
| 72 | + createdAt: "" |
| 73 | +} |
| 74 | +
|
| 75 | +Error |
| 76 | +{ |
| 77 | + code: "NOT_ENOUGH_DISK_SPACE", |
| 78 | + name: "Not enough disk space", |
| 79 | + hint: "Stop idle clones, change snapshot policy or increase disk size" |
| 80 | +} |
| 81 | +``` |
| 82 | + |
| 83 | +REST API: |
| 84 | +``` |
| 85 | +Get DB Lab instance status and list clones |
| 86 | +GET /status |
| 87 | +Response: |
| 88 | +{ |
| 89 | + status: { |
| 90 | + code: "OK", |
| 91 | + message: "DB Lab is ready" |
| 92 | + }, |
| 93 | + disk: { |
| 94 | + size: 1000.0, (bytes) |
| 95 | + free: 1200.0 |
| 96 | + }, |
| 97 | + expectedCloningTime: 8.0, (secondss) |
| 98 | + numClones: 10, |
| 99 | + clones: [{ |
| 100 | + id: "id" |
| 101 | + status: { |
| 102 | + code: "OK", |
| 103 | + message: "Database is ready" |
| 104 | + }, |
| 105 | + ... |
| 106 | + }, ... ], |
| 107 | + snapshots: [{ |
| 108 | + id: "xxx", |
| 109 | + timestamp: "123" |
| 110 | + }, ... ] |
| 111 | +} |
| 112 | +
|
| 113 | +Create a clone |
| 114 | +POST /clone/ |
| 115 | +Request: |
| 116 | +{ |
| 117 | + project: "proj1", |
| 118 | + snapshot: (optional): "", |
| 119 | + db: { |
| 120 | + username: "xxx", |
| 121 | + password: "xxx" |
| 122 | + } |
| 123 | + username: "xxx", |
| 124 | + name: "xxx" |
| 125 | +} |
| 126 | +Response: |
| 127 | +{ |
| 128 | + id: "xxx" |
| 129 | +} |
| 130 | +
|
| 131 | +Update a clone |
| 132 | +PATCH /clone/:id |
| 133 | +
|
| 134 | +Reset a clone |
| 135 | +POST /clone/:id/reset |
| 136 | +
|
| 137 | +Delete a clone |
| 138 | +DELETE /clone/:id |
| 139 | +
|
| 140 | +Get status of a clone |
| 141 | +GET /clone/:id |
| 142 | +Response: |
| 143 | +{ |
| 144 | + id: "xxx", |
| 145 | + status: { |
| 146 | + code: "OK", |
| 147 | + message: "Database clone is ready" |
| 148 | + }, |
| 149 | + cloneSize: 1000.0, |
| 150 | + cloningTime: 5, |
| 151 | + project: "xxx", |
| 152 | + snapshot: "xxx", |
| 153 | + db: { |
| 154 | + username: "xxx", |
| 155 | + host: "xxx", |
| 156 | + port: "xxx", |
| 157 | + connStr: "xxx" |
| 158 | + }, |
| 159 | + protected: true, |
| 160 | + deleteAt: "", |
| 161 | + name: "xxx", |
| 162 | + username: "xxx", |
| 163 | + createdAt: "123" |
| 164 | +} |
| 165 | +``` |
0 commit comments