标签:删除节点 theme sele 个人 image 函数 HERE scom imp
使用citus 使用副本配置对于灾备处理是比较重要的,以下是一个简单的学习
使用docker-compose运行
version: "3"
services:
graphql-engine:
image: hasura/graphql-engine:v1.1.0
ports:
- "8080:8080"
environment:
HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:dalong@pg-citus-master:5432/postgres
HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set to "false" to disable console
HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
pg-citus-master:
container_name: pg-citus-master
image: dalongrong/pgspider:citus-9.1
volumes:
- "./csvfiles:/opt/csv"
- "./sql:/docker-entrypoint-initdb.d/"
ports:
- "5432:5432"
environment:
- "POSTGRES_PASSWORD=dalong"
pg-citus-worker:
container_name: pg-citus-worker
image: dalongrong/pgspider:citus-9.1
volumes:
- "./csvfiles:/opt/csv"
- "./sql:/docker-entrypoint-initdb.d/"
ports:
- "5433:5432"
pg-citus-worker2:
container_name: pg-citus-worker2
image: dalongrong/pgspider:citus-9.1
volumes:
- "./csvfiles:/opt/csv"
- "./sql:/docker-entrypoint-initdb.d/"
ports:
- "5434:5432"
-- wrap in transaction to ensure Docker flag always visible
BEGIN;
CREATE EXTENSION citus;
COMMIT;
curl https://examples.citusdata.com/tutorial/companies.csv > csvfiles/scompanies.csv
curl https://examples.citusdata.com/tutorial/campaigns.csv > csvfiles/campaigns.csv
curl https://examples.citusdata.com/tutorial/ads.csv > csvfiles/ads.csv
docker-compose up -d
master 节点操作,数据的导入在创建分布式表前后都可以的
CREATE TABLE companies (
id bigint NOT NULL,
name text NOT NULL,
image_url text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
?
CREATE TABLE campaigns (
id bigint NOT NULL,
company_id bigint NOT NULL,
name text NOT NULL,
cost_model text NOT NULL,
state text NOT NULL,
monthly_budget bigint,
blacklisted_site_urls text[],
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
?
CREATE TABLE ads (
id bigint NOT NULL,
company_id bigint NOT NULL,
campaign_id bigint NOT NULL,
name text NOT NULL,
image_url text,
target_url text,
impressions_count bigint DEFAULT 0,
clicks_count bigint DEFAULT 0,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE companies
ADD PRIMARY KEY (id);
ALTER TABLE campaigns
ADD PRIMARY KEY (id, company_id);
ALTER TABLE ads
ADD PRIMARY KEY (id, company_id);
SELECT
master_add_node (‘pg-citus-worker‘,
‘5432‘);
SELECT
master_add_node (‘pg-citus-worker2‘,
‘5432‘);
// 配置副本数为2,因为是2个worker,为了简单,同时测试灾备
SET citus.shard_replication_factor = 2;
SELECT create_distributed_table(‘companies‘, ‘id‘);
SELECT create_distributed_table(‘campaigns‘, ‘company_id‘);
SELECT create_distributed_table(‘ads‘, ‘company_id‘);
前边通过membership-manager 的原理大概也就知道了,就是删除节点的分片原数据,同时删除节点。
但是需要注意数据的迁移的处理(节点添加数据的reblance 才是比较难的)
docker-compose stop pg-citus-worker2
DELETE FROM pg_dist_placement WHERE groupid = (SELECT groupid FROM pg_dist_node WHERE nodename =‘pg-citus-worker2‘ AND nodeport = ‘5432‘ LIMIT 1);
SELECT master_remove_node(‘pg-citus-worker2‘, ‘5433‘)
citus 开源版本提供了一些操作函数,我们利用这些函数还是可以方便的维护citus 集群的,如果感觉维护费事,yugabyte 以及cockroachdb
都是可选的方案,但是个人推荐yugabyte
http://docs.citusdata.com/en/v9.2/admin_guide/cluster_management.html
https://github.com/citusdata/membership-manager/blob/master/manager.py
标签:删除节点 theme sele 个人 image 函数 HERE scom imp
原文地址:https://www.cnblogs.com/rongfengliang/p/12445004.html