Skip to content

Commit 5de8264

Browse files
committed
v2.18.1: Add retries on shard activation; fix race condition in shards activation; support full host:port/db format in microsharding_migration_after()
1 parent 5ffa69d commit 5de8264

24 files changed

+488
-162
lines changed

README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,13 @@ export const cluster = new Cluster({
297297

298298
### Microsharding Debug Views
299299

300-
The `microsharding_migration_after()` function creates so-called "debug views" for each sharded table in your cluster. For instance, it you have `sh0001.users`, `sh0002.users` etc. tables. then it will create a debug view `public.users` with the definition like:
300+
The `microsharding_migration_after()` function creates so-called "debug views" for each sharded table in your cluster:
301+
302+
```sql
303+
SELECT microsharding.microsharding_migration_after();
304+
```
305+
306+
For instance, it you have `sh0001.users`, `sh0002.users` etc. tables, then it will create a debug view `public.users` with the definition like:
301307

302308
```sql
303309
-- This is what pg-microsharding creates automatically.
@@ -309,9 +315,13 @@ CREATE VIEW public.users AS
309315
...;
310316
```
311317

312-
Even more, if you pass the list of all PostgreSQL hosts, and those hosts can access each other without a password (e.g. they have `/var/lib/postgresql/N/.pgpass` files), then those debug views will work **across all shards on all nodes, including the remote ones** (using [foreign-data wrapper](https://www.postgresql.org/docs/current/postgres-fdw.html) functionality).
318+
Even more, if you pass the list of all PostgreSQL hosts, and those hosts can access each other without a password (e.g. they have `/var/lib/postgresql/N/.pgpass` files), then those debug views will work **across all shards on all nodes, including the remote ones** (using [foreign-data wrapper](https://www.postgresql.org/docs/current/postgres-fdw.html) functionality):
313319

314-
So **for debugging purposes**, you'll be able to run queries across all microshards in your `psql` sessions. This is typically very convenient.
320+
```sql
321+
SELECT microsharding.microsharding_migration_after('host1,host2,host3');
322+
```
323+
324+
So **for debugging purposes**, you'll be able to run queries _across all microshards on all hosts_ in your `psql` sessions.
315325

316326
Of course those **debug views are not suitable for production traffic**: cross-node communication in PostgreSQL, as well as query planning, work not enough inefficiently. Do not even try, use application-level microshards routing, like e.g. [Ent Framework](https://ent-framework.org/) provides.
317327

@@ -324,6 +334,12 @@ postgres=# SELECT shard, email FROM users
324334
-- debugging purposes only.
325335
```
326336

327-
As of `microsharding_migration_before()`, you must call it before any changes are applied to your microsharded tables. The function drops all of the debug views mentioned above. E.g. if you remove a column from a table, PostgreSQL would not allow you to do it it this column is mentioned in any of the views, so it's important to drop the views and re-create them afterwards.
337+
As of `microsharding_migration_before()`, you must call it before any changes are applied to your microsharded tables:
338+
339+
```sql
340+
SELECT microsharding.microsharding_migration_before();
341+
```
342+
343+
The function drops all of the debug views mentioned above. E.g. if you remove a column from a table, PostgreSQL would not allow you to do it it this column is mentioned in any of the views, so it's important to drop the views and re-create them afterwards.
328344

329345
Typically, you just call `microsharding_migration_before()` in your pre-migration sequence and then call `microsharding_migration_after()` in your post-migration steps.

docs/README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,13 @@ export const cluster = new Cluster({
301301

302302
### Microsharding Debug Views
303303

304-
The `microsharding_migration_after()` function creates so-called "debug views" for each sharded table in your cluster. For instance, it you have `sh0001.users`, `sh0002.users` etc. tables. then it will create a debug view `public.users` with the definition like:
304+
The `microsharding_migration_after()` function creates so-called "debug views" for each sharded table in your cluster:
305+
306+
```sql
307+
SELECT microsharding.microsharding_migration_after();
308+
```
309+
310+
For instance, it you have `sh0001.users`, `sh0002.users` etc. tables, then it will create a debug view `public.users` with the definition like:
305311

306312
```sql
307313
-- This is what pg-microsharding creates automatically.
@@ -313,9 +319,13 @@ CREATE VIEW public.users AS
313319
...;
314320
```
315321

316-
Even more, if you pass the list of all PostgreSQL hosts, and those hosts can access each other without a password (e.g. they have `/var/lib/postgresql/N/.pgpass` files), then those debug views will work **across all shards on all nodes, including the remote ones** (using [foreign-data wrapper](https://www.postgresql.org/docs/current/postgres-fdw.html) functionality).
322+
Even more, if you pass the list of all PostgreSQL hosts, and those hosts can access each other without a password (e.g. they have `/var/lib/postgresql/N/.pgpass` files), then those debug views will work **across all shards on all nodes, including the remote ones** (using [foreign-data wrapper](https://www.postgresql.org/docs/current/postgres-fdw.html) functionality):
317323

318-
So **for debugging purposes**, you'll be able to run queries across all microshards in your `psql` sessions. This is typically very convenient.
324+
```sql
325+
SELECT microsharding.microsharding_migration_after('host1,host2,host3');
326+
```
327+
328+
So **for debugging purposes**, you'll be able to run queries _across all microshards on all hosts_ in your `psql` sessions.
319329

320330
Of course those **debug views are not suitable for production traffic**: cross-node communication in PostgreSQL, as well as query planning, work not enough inefficiently. Do not even try, use application-level microshards routing, like e.g. [Ent Framework](https://ent-framework.org/) provides.
321331

@@ -328,6 +338,12 @@ postgres=# SELECT shard, email FROM users
328338
-- debugging purposes only.
329339
```
330340

331-
As of `microsharding_migration_before()`, you must call it before any changes are applied to your microsharded tables. The function drops all of the debug views mentioned above. E.g. if you remove a column from a table, PostgreSQL would not allow you to do it it this column is mentioned in any of the views, so it's important to drop the views and re-create them afterwards.
341+
As of `microsharding_migration_before()`, you must call it before any changes are applied to your microsharded tables:
342+
343+
```sql
344+
SELECT microsharding.microsharding_migration_before();
345+
```
346+
347+
The function drops all of the debug views mentioned above. E.g. if you remove a column from a table, PostgreSQL would not allow you to do it it this column is mentioned in any of the views, so it's important to drop the views and re-create them afterwards.
332348

333349
Typically, you just call `microsharding_migration_before()` in your pre-migration sequence and then call `microsharding_migration_after()` in your post-migration steps.

docs/functions/move.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
> **move**(`__namedParameters`): `Promise`\<`void`\>
1010
11-
Defined in: [src/api/move.ts:26](https://github.com/clickup/pg-microsharding/blob/master/src/api/move.ts#L26)
11+
Defined in: [src/api/move.ts:27](https://github.com/clickup/pg-microsharding/blob/master/src/api/move.ts#L27)
1212

1313
Moves a shard from one master DB to another.
1414

0 commit comments

Comments
 (0)