????pg_shard?????PostgreSQL??sharding extension??????????Shards??Replicates tables?????á?????????????Applications?????????????????????????SQL??????????????extension??pg_shard????????NOSQL???????????
?????????pg_shard??Cluster?????PG????????Master node??Worker node????Master node??????????洢metadata????????в????????
???????????Cluster?е????????PG node???Master????????????Workers??
?????????????????????????????????Master??Worker????????????????????????PG??????????????????????????“localhost”???Worker node?????????????????????????????PG????????????????????????????????????????????£??????????ЩPG????????????????????????postgresql.conf??listen_address??????pg_hba.conf???????????????????Master????????????TCP???????????Workder Node??
????pg_shard???????
?????????pg_shard
???????postgresql.conf?????shared_preload_libraries=’pg_shard’
????????pg_shard?????????pg_worker_list.conf???????????£?
????# hostname port-number
????worker-1 5432
????worker-2 5433
??????????????Master node??
??????Table???з???????
??????Master??????
????CREATE EXTENSION pg_shard;
????SELECT master_create_distributed_table(‘table_name’??’partition_column’);
??????Worker??????
????SELECT master_create_worker_shards(‘table_name’??’shards_num’??’rep_num’);
?????????????shards????????Cluster????в?????????UPDATE??DELETE?????WHERE????????а???Partition Column??
????pg_shard????????
????pgs_distrubution_metadata.partition;
????pgs_distrubution_metadata.shard;
????pgs_distrubution_metadata.shard_placement;
????pg_shard?????????
????1????????shard??????
????2??????????partition key??foreign key??????column??????
????3???????Distrubuted Join????pg_shard?????????CITUSDB???????????汾?в?????
????pg_shard????????
????1???????????????????????????????????Worker?????
????2??DROP TABLE
????3??INSERT INTO ...select...
???????????????????????????????????????á?????????ó?????????????????á????磺
????tbl_example (id integer??val jsonb);
?????????????????????mongodb??????
???????????????????????
????---------------------------------------------------------------------------
?????????????????????????????????????????????????????ERROR????????ο???
?????????????master + 3??worker
??????????shard??
????sharddb=# SELECT master_create_distributed_table('customer_reviews'?? 'customer_id');
????sharddb=# SELECT master_create_worker_shards('customer_reviews'?? 16?? 2);
????????????????????????????
master??
sharddb=# d+
List of relations
Schema | Name | Type | Owner | Size | Description
-----{}---------------{}-------+----------
public | customer_reviews | table | postgres | 32 kB |
(1 row)
worker-1??
sharddb=# d+
List of relations
Schema | Name | Type | Owner | Size | Description
-----{}---------------------{}-------+----------
public | customer_reviews_10000 | table | postgres | 32 kB |
......
public | customer_reviews_10015 | table | postgres | 32 kB |
(11 rows)
worker-2??
sharddb=# d+
List of relations
Schema | Name | Type | Owner | Size | Description
-----{}---------------------{}-------+----------
public | customer_reviews_10000 | table | postgres | 32 kB |
......
public | customer_reviews_10015 | table | postgres | 32 kB |
(11 rows)
worker-3??
sharddb=# d+
List of relations
Schema | Name | Type | Owner | Size | Description
-----{}---------------------{}-------+----------
public | customer_reviews_10001 | table | postgres | 32 kB |
......
public | customer_reviews_10014 | table | postgres | 32 kB |
(10 rows)
??????????worker??????????????????????????16????????????????渱???????????????