Skip to content

Commit 7dd1b99

Browse files
committed
v2.24.5: Add copy action to README
1 parent 5f004f0 commit 7dd1b99

File tree

4 files changed

+163
-106
lines changed

4 files changed

+163
-106
lines changed

README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ See also [TypeScript API documentation](https://github.com/clickup/pg-microshard
77
The [pg-microsharding](https://www.npmjs.com/package/@clickup/pg-microsharding) CLI tool enables microshard schemas management across multiple PostgreSQL servers. You can do the following:
88

99
* Add and remove microshard schemas.
10-
* Activate and deactivate schemas.
11-
* Enumerate active microshard schemas.
12-
* View the entire cluster layout: what microshard schemas are where, of what size, and how many reads/writes do the experience.
1310
* Move a microshard from one PostgreSQL server to another with no downtime.
1411
* Automatically rebalance microshards among multiple servers, so that each server will become of approximately the same size.
12+
* Copy regular PostgreSQL schemas (unrelated to microshards) from one host to another without downtime (think of no-downtime dump-restore workflow).
13+
* Activate and deactivate microshards.
14+
* Enumerate active microshard schemas.
15+
* View the entire cluster layout: what microshard schemas are where, of what size, and how many reads/writes do the experience.
1516
* Weighted rebalancing: when one server looks overloaded, you can "dissolve out" some shards from it to other servers to achieve equal load.
1617

1718
Each microshard is a PostgreSQL schema with numeric suffix. Microshard schemas have the same set of tables with same names; it's up to the higher-level tools to keep the schemas of all those tables in sync (e.g. see [pg-mig](https://www.npmjs.com/package/@clickup/pg-mig) tool).
@@ -27,6 +28,7 @@ pg-microsharding list | ls
2728
[--weight-sql='SELECT returning weight with optional unit']
2829
[--verbose]
2930
[--dsn=DSN | --dsns=DNS1,DSN2,...]
31+
[--json]
3032
3133
pg-microsharding allocate
3234
--shard=N | --shards=N-M
@@ -56,6 +58,14 @@ pg-microsharding rebalance
5658
5759
pg-microsharding cleanup
5860
[--dsn=DSN | --dsns=DNS1,DSN2,...]
61+
62+
pg-microsharding copy
63+
--schema=SCHEMA-NAME
64+
--from=DSN-OR-DSN-PREFIX-OR
65+
--to=DSN-OR-DSN-PREFIX
66+
[--wait]
67+
[--max-replication-lag-sec=N]
68+
[--dsns=DNS1,DSN2,...]
5969
```
6070

6171
## Environment Variables
@@ -136,6 +146,8 @@ pg-microsharding list
136146

137147
This action prints the list of all PostgreSQL islands (pointed by DNSn), microshards and some statistics.
138148

149+
If `--json` flag is passed, prints a JSON version of the output. Otherwise, prints a pseudo-graphic representation.
150+
139151
In `--verbose` mode, also prints detailed statistics about insert/update/delete, index scans and seqscans.
140152

141153
<div align="center"><figure><img src="https://raw.githubusercontent.com/dimikot/ent-framework/refs/heads/main/gitbook/.gitbook/assets/pg-microsharding-list.png" alt="" width="563"><figcaption></figcaption></figure></div>
@@ -242,6 +254,19 @@ When you run `pg-microsharding factor --factor="*1.2"`, the tool artificially in
242254
243255
The "weight increase factor" is technically stored as a SQL comment on the microshard schema, and it travels along with the microshard when you move it.
244256
257+
### Dump-Restore a Schema with no Downtime: pg-microsharding copy
258+
259+
```bash
260+
pg-microsharding copy \
261+
--schema=my-schema --from=host1 --to=host2 \
262+
--wait \
263+
--max-replication-lag-sec=20
264+
```
265+
266+
This action works very similarly to the move action, but it doesn't deactivate/activate microshards, so it may be used for other regular PostgreSQL schemas. Unlike when using regular `pg_dump` and restoring, you may continue sending writes to the source host, and the changes will eventually be replayed on the destination while the action is running.
267+
268+
It is very convenient to run this action with `--wait` flag: in this case, it will ask for the user confirmation right before removing the logical subscription, so you'll have a chance to stop writes on the source host and quickly reroute the traffic to destination before finishing the action and removing the logical subscription.
269+
245270
### Replication Lag Prevention
246271
247272
The tool tries hard to not affect the replication lag of the destination nodes when moving or rebalancing microshards. It waits until the lag drops below `--max-replication-lag-sec` seconds before running heavy operations (or until the user presses Shift+S to force-continue).

docs/README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ See also [TypeScript API documentation](https://github.com/clickup/pg-microshard
1111
The [pg-microsharding](https://www.npmjs.com/package/@clickup/pg-microsharding) CLI tool enables microshard schemas management across multiple PostgreSQL servers. You can do the following:
1212

1313
* Add and remove microshard schemas.
14-
* Activate and deactivate schemas.
15-
* Enumerate active microshard schemas.
16-
* View the entire cluster layout: what microshard schemas are where, of what size, and how many reads/writes do the experience.
1714
* Move a microshard from one PostgreSQL server to another with no downtime.
1815
* Automatically rebalance microshards among multiple servers, so that each server will become of approximately the same size.
16+
* Copy regular PostgreSQL schemas (unrelated to microshards) from one host to another without downtime (think of no-downtime dump-restore workflow).
17+
* Activate and deactivate microshards.
18+
* Enumerate active microshard schemas.
19+
* View the entire cluster layout: what microshard schemas are where, of what size, and how many reads/writes do the experience.
1920
* Weighted rebalancing: when one server looks overloaded, you can "dissolve out" some shards from it to other servers to achieve equal load.
2021

2122
Each microshard is a PostgreSQL schema with numeric suffix. Microshard schemas have the same set of tables with same names; it's up to the higher-level tools to keep the schemas of all those tables in sync (e.g. see [pg-mig](https://www.npmjs.com/package/@clickup/pg-mig) tool).
@@ -31,6 +32,7 @@ pg-microsharding list | ls
3132
[--weight-sql='SELECT returning weight with optional unit']
3233
[--verbose]
3334
[--dsn=DSN | --dsns=DNS1,DSN2,...]
35+
[--json]
3436
3537
pg-microsharding allocate
3638
--shard=N | --shards=N-M
@@ -60,6 +62,14 @@ pg-microsharding rebalance
6062
6163
pg-microsharding cleanup
6264
[--dsn=DSN | --dsns=DNS1,DSN2,...]
65+
66+
pg-microsharding copy
67+
--schema=SCHEMA-NAME
68+
--from=DSN-OR-DSN-PREFIX-OR
69+
--to=DSN-OR-DSN-PREFIX
70+
[--wait]
71+
[--max-replication-lag-sec=N]
72+
[--dsns=DNS1,DSN2,...]
6373
```
6474

6575
## Environment Variables
@@ -140,6 +150,8 @@ pg-microsharding list
140150

141151
This action prints the list of all PostgreSQL islands (pointed by DNSn), microshards and some statistics.
142152

153+
If `--json` flag is passed, prints a JSON version of the output. Otherwise, prints a pseudo-graphic representation.
154+
143155
In `--verbose` mode, also prints detailed statistics about insert/update/delete, index scans and seqscans.
144156

145157
<div align="center"><figure><img src="https://raw.githubusercontent.com/dimikot/ent-framework/refs/heads/main/gitbook/.gitbook/assets/pg-microsharding-list.png" alt="" width="563"><figcaption></figcaption></figure></div>
@@ -246,6 +258,19 @@ When you run `pg-microsharding factor --factor="*1.2"`, the tool artificially in
246258
247259
The "weight increase factor" is technically stored as a SQL comment on the microshard schema, and it travels along with the microshard when you move it.
248260
261+
### Dump-Restore a Schema with no Downtime: pg-microsharding copy
262+
263+
```bash
264+
pg-microsharding copy \
265+
--schema=my-schema --from=host1 --to=host2 \
266+
--wait \
267+
--max-replication-lag-sec=20
268+
```
269+
270+
This action works very similarly to the move action, but it doesn't deactivate/activate microshards, so it may be used for other regular PostgreSQL schemas. Unlike when using regular `pg_dump` and restoring, you may continue sending writes to the source host, and the changes will eventually be replayed on the destination while the action is running.
271+
272+
It is very convenient to run this action with `--wait` flag: in this case, it will ask for the user confirmation right before removing the logical subscription, so you'll have a chance to stop writes on the source host and quickly reroute the traffic to destination before finishing the action and removing the logical subscription.
273+
249274
### Replication Lag Prevention
250275
251276
The tool tries hard to not affect the replication lag of the destination nodes when moving or rebalancing microshards. It waits until the lag drops below `--max-replication-lag-sec` seconds before running heavy operations (or until the user presses Shift+S to force-continue).

0 commit comments

Comments
 (0)