简体   繁体   English

Citus:将现有数据库作为citus的工作节点

[英]Citus: make existing database as worker node of citus

I already have a database on one of my server used by a web app. 我已经有一个Web应用程序使用的服务器之一上的数据库。 Lets say D1 可以说D1

I want to make a new web app with new database D2 on some other server with some relations with D1 . 我想在其他与D1有某些关系的服务器上使用新数据库D2创建一个新的Web应用程序。

I want to create citus data server and add both D1 and D2 as shard table and their worker node as their respective server. 我想创建citus数据服务器,并将D1D2都添加为分片表,并将其工作节点添加为各自的服务器。

What I found in citus documentations is that shard database tables are created on citus server and automatically distributed to available worker nodes. 我在citus文档中发现的是,碎片数据库表是在citus服务器上创建的,并自动分发到可用的工作程序节点。

How can I use existing database as worker node and shard table with a freshly new citus server . 如何将现有的数据库用作新的citus服务器的工作节点和分片表。

Question is little vague, I did not quite get what is being asked. 问题有点含糊,我不太了解所要问的问题。

We have 2 servers S1 and S2 containing 2 databases D1 and D2. 我们有2个服务器S1和S2,其中包含2个数据库D1和D2。 We would like to create a distributed database containing both D1 and D2, we will have a 3rd server S0 that we wanted to use as a citus coordinator. 我们想创建一个包含D1和D2的分布式数据库,我们将有一个第三服务器S0,我们希望将其用作citus协调器。

Using S1 (D1) and S2 (D2) as worker is not a problem. 将S1(D1)和S2(D2)用作工作程序不是问题。 Citus creates main tables at the coordinator node. Citus在协调器节点上创建主表。 Respective shards are created at workers. 分别在工人处创建碎片。 Assuming there would be name collision, shard tables can co-exist with the old tables. 假设会发生名称冲突,碎片表可以与旧表共存。

However, you can't blindly use existing data in D1 and D2 as it is and expect them to be shard tables. 但是,您不能盲目使用D1和D2中的现有数据,并期望它们是分片表。 Data needs to be re-sharded. 数据需要重新分片。

Steps 脚步

  1. read citus documentation on how to setup clusters, pick distribution keys, load data 阅读有关如何设置群集,选择分发密钥,加载数据的citus文档

  2. install/setup citus extension on S1, S2, and S0 (coordinator) 在S1,S2和S0上安装/设置citus扩展(协调器)

  3. add S1 and S2 as a worker nodes in S0 在S0中将S1和S2添加为工作节点

  4. Decide on table distribution. 确定表分配。 Some tables need to be on all nodes (reference tables), some of them is sharded according to some key. 有些表需要位于所有节点上(参考表),其中一些是根据某些键进行分片的。

  5. create tables on coordinator node, distributed them using create_distributed_table/create_reference_table function 在协调器节点上创建表,使用create_distributed_table / create_reference_table函数进行分配

  6. load data, this could be a problem. 加载数据,这可能是一个问题。 Easiest way is to export (copy out) existing data to an external file, and import (copy in) from that file to a citus cluster. 最简单的方法是将现有数据导出(复制)到外部文件,然后从该文件导入(复制)到citus集群。 You will need to use coordinator node (S0) while importing data. 导入数据时,您将需要使用协调器节点(S0)。

  7. test your application using the new cluster pretty well before switching. 在切换之前,请使用新集群很好地测试您的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM