前端技术
HTML
CSS
Javascript
前端框架和UI库
VUE
ReactJS
AngularJS
JQuery
NodeJS
JSON
Element-UI
Bootstrap
Material UI
服务端和客户端
Java
Python
PHP
Golang
Scala
Kotlin
Groovy
Ruby
Lua
.net
c#
c++
后端WEB和工程框架
SpringBoot
SpringCloud
Struts2
MyBatis
Hibernate
Tornado
Beego
Go-Spring
Go Gin
Go Iris
Dubbo
HessianRPC
Maven
Gradle
数据库
MySQL
Oracle
Mongo
中间件与web容器
Redis
MemCache
Etcd
Cassandra
Kafka
RabbitMQ
RocketMQ
ActiveMQ
Nacos
Consul
Tomcat
Nginx
Netty
大数据技术
Hive
Impala
ClickHouse
DorisDB
Greenplum
PostgreSQL
HBase
Kylin
Hadoop
Apache Pig
ZooKeeper
SeaTunnel
Sqoop
Datax
Flink
Spark
Mahout
数据搜索与日志
ElasticSearch
Apache Lucene
Apache Solr
Kibana
Logstash
数据可视化与OLAP
Apache Atlas
Superset
Saiku
Tesseract
系统与容器
Linux
Shell
Docker
Kubernetes
[OLAP]的搜索结果
这里是文章列表。热门标签的颜色随机变换,标签颜色没有特殊含义。
点击某个标签可搜索标签相关的文章。
点击某个标签可搜索标签相关的文章。
ClickHouse
...其在进行大数据分析、OLAP(在线分析处理)场景下,能大幅度提升查询性能和减少I/O开销。 外部表 , 在ClickHouse中,外部表是一种特殊的表类型,它并不直接存储数据,而是指向存储在文件系统或其他数据源中的数据。这意味着ClickHouse可以利用外部表功能来访问并处理位于其自身存储之外的数据,使得数据导入导出更为灵活,同时也能与多种数据源进行集成。 基于角色的访问控制(RBAC)机制 , 基于角色的访问控制是一种权限管理模型,在ClickHouse中用于精细化管理用户对数据库对象(如外部表)的操作权限。通过将权限分配给不同角色,并将这些角色赋予特定用户,管理员可以根据业务需求精确控制每个用户的读写权限,从而实现细粒度的安全管控,有效防止数据泄露或误操作风险。
2023-09-29 09:56:06
467
落叶归根
DorisDB
... ) ENGINE=OLAP DUPLICATE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 3 PROPERTIES ( "replication_num" = "1" ); -- 导入数据 LOAD LABEL example_label ( DATA INFILE("hdfs://localhost:9000/example.csv") INTO TABLE example_table COLUMNS TERMINATED BY "," (id, name, age) ); 4.1.2 使用事务机制 DorisDB支持事务机制,可以确保在复杂的数据迁移场景下保持数据的一致性。比如说,当你需要做多个插入操作时,可以用事务把它们包在一起。这样,这些操作就会像一个动作一样,要么全都成功,要么全都不算,确保数据的一致性。 示例代码 sql BEGIN; INSERT INTO example_table VALUES (1, 'Alice', 25); INSERT INTO example_table VALUES (2, 'Bob', 30); COMMIT; 4.2 迁移效率 4.2.1 利用分区和分片 DorisDB支持数据分区和分片,可以根据特定字段(如日期)对数据进行切分,从而提高查询效率。在搬数据的时候,如果能好好规划一下怎么分割和分布这些数据,就能大大加快导入速度。 示例代码 sql CREATE TABLE partitioned_table ( date DATE, value INT ) ENGINE=OLAP PARTITION BY RANGE(date) ( PARTITION p202301 VALUES LESS THAN ("2023-02-01"), PARTITION p202302 VALUES LESS THAN ("2023-03-01") ) DISTRIBUTED BY HASH(date) BUCKETS 3 PROPERTIES ( "replication_num" = "1" ); 4.2.2 并行导入 DorisDB支持并行导入,可以在多个节点上同时进行数据加载,极大地提升了导入速度。在实际应用中,可以通过配置多个数据源并行加载数据来达到最佳效果。 示例代码 sql -- 在多个节点上并行加载数据 LOAD LABEL example_label ( DATA INFILE("hdfs://localhost:9000/data1.csv") INTO TABLE example_table COLUMNS TERMINATED BY "," (id, name, age), DATA INFILE("hdfs://localhost:9000/data2.csv") INTO TABLE example_table COLUMNS TERMINATED BY "," (id, name, age) ); 4.3 兼容性问题 4.3.1 数据格式转换 在数据迁移过程中,可能会遇到不同数据源之间的格式不一致问题。DorisDB提供了强大的数据类型转换功能,可以方便地处理各种数据格式的转换。 示例代码 sql -- 将CSV文件中的字符串转换为日期类型 LOAD LABEL example_label ( DATA INFILE("hdfs://localhost:9000/data.csv") INTO TABLE example_table COLUMNS TERMINATED BY "," (id, CAST(date_str AS DATE), age) ); 4.3.2 使用ETL工具 除了直接使用DorisDB的功能外,还可以借助ETL(Extract, Transform, Load)工具来处理数据迁移过程中的兼容性问题。DorisDB与多种ETL工具(如Apache NiFi、Talend等)无缝集成,使得数据迁移变得更加简单高效。 5. 结论 通过以上讨论,我们可以看到DorisDB在数据迁移方面的强大能力和灵活性。不管你是想保持数据的一致性、加快搬家的速度,还是解决不同系统之间的兼容问题,DorisDB 都能给你不少帮手。作为一名数据库爱好者,我深深地被DorisDB的魅力所吸引。希望本文能帮助大家更好地理解和运用DorisDB进行数据迁移工作。 最后,我想说的是,技术永远是为人服务的。不管多牛的技术,归根结底都是为了让我们生活得更爽,更方便,过得更滋润。让我们一起努力,探索更多可能性吧!
2025-02-28 15:48:51
35
素颜如水
Kylin
...进行复杂的多维分析(OLAP),处理起超大规模的数据来毫不含糊。这个项目最早是eBay的大佬们搞出来的,后来他们把它交给了Apache基金会,让它成为大家共同的宝贝。在用Kylin的时候,我真是遇到了一堆麻烦事儿,从设置到安装,再到调整性能,每一步都像是在闯关。嘿,今天我打算分享点实用的东西。基于我个人的经验,咱们来聊聊在配置和部署Kylin时会遇到的一些常见坑,还有我是怎么解决这些麻烦的。准备好了吗?让我们一起避开这些小陷阱吧! 2. Kylin环境搭建 首先,我们来谈谈环境搭建。搭建Kylin环境需要一些基本的软件支持,如Java、Hadoop、HBase等。我刚开始的时候就因为没有正确安装这些软件而走了不少弯路。比如我以前试过用Java 8跑Kylin,结果发现好多功能都用不了。后来才知道是因为Java版本太低了,怪自己当初没注意。所以在启动之前,记得检查一下你的电脑上是不是已经装了Java 11或者更新的版本,最好是长期支持版(LTS),这样Kylin才能乖乖地跑起来。 java 检查Java版本 java -version 接下来是Hadoop和HBase的安装。如果你用的是Cloudera CDH或者Hortonworks HDP,那安装起来就会轻松不少。但如果你是从源码编译安装,那么可能会遇到更多问题。比如说,我之前碰到过Hadoop配置文件里的一些参数不匹配,结果Kylin就启动不了。要搞定这个问题,关键就是得仔仔细细地检查一下配置文件,确保所有的参数都跟官方文档上说的一模一样。 xml 在hadoop-env.sh中设置JAVA_HOME export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 3. Kylin配置详解 在完成环境搭建后,我们需要对Kylin进行配置。Kylin的配置主要集中在kylin.properties文件中。这个文件包含了Kylin运行所需的几乎所有参数。我头一回设置的时候,因为对那些参数不太熟悉,结果Kylin愣是没启动起来。后来经过多次尝试和查阅官方文档,我才找到了正确的配置方法。 一个常见的问题是,如何设置Kylin的存储位置。默认情况下,Kylin会将元数据存储在HBase中。不过,如果你想把元数据存在本地的文件系统里,只需要调整一下kylin.metadata.storage这个参数就行啦。这可以显著提高开发阶段的效率,但在生产环境中并不推荐这样做。 properties 设置Kylin元数据存储为本地文件系统 kylin.metadata.storage=fs:/path/to/local/directory 另一个重要的配置是Kylin的Cube构建策略。Cube是Kylin的核心概念之一,它用于加速查询响应时间。不同的Cube构建策略会影响查询性能和存储空间的占用。我曾经因为选择了错误的构建策略而导致Cube构建速度极慢。后来,通过调整kylin.cube.algorithm参数,我成功地优化了Cube构建过程。 properties 设置Cube构建策略为INMEM kylin.cube.algorithm=INMEM 4. Kylin部署与监控 最后,我们来谈谈Kylin的部署与监控。Kylin提供了多种部署方式,包括单节点部署、集群部署等。对于初学者来说,单节点部署可能更易于理解和操作。但是,随着数据量的增长,单节点部署很快就会达到瓶颈。这时,就需要考虑集群部署方案。 在部署过程中,我遇到的一个主要问题是服务之间的依赖关系。Kylin依赖于Hadoop和HBase,如果这些服务没有正确配置,Kylin将无法启动。要搞定这个问题,就得细细排查每个服务的状况,确保它们都乖乖地在运转着。 bash 检查Hadoop服务状态 sudo systemctl status hadoop-hdfs-namenode 部署完成后,监控Kylin的运行状态变得非常重要。Kylin提供了Web界面和日志文件两种方式来进行监控。你可以直接在网页上看到Kylin的各种数据指标,就像看仪表盘一样。至于Kylin的操作记录嘛,就都记在日志文件里头了。我经常使用日志文件来排查问题,因为它能提供更多的上下文信息。 bash 查看Kylin日志文件 tail -f /opt/kylin/logs/kylin.log 结语 通过这次分享,我希望能让大家对Kylin的配置与部署有一个更全面的理解。尽管在过程中会碰到各种难题,但只要咱们保持耐心,不断学习和探索,肯定能找到解决的办法。Kylin 的厉害之处就在于它超级灵活,还能随意扩展,这正是我们在大数据分析里头求之不得的呢。希望你们在使用Kylin的过程中也能感受到这份乐趣! --- 希望这篇技术文章对你有所帮助!如果你有任何疑问或需要进一步的帮助,请随时联系我。
2024-12-31 16:02:29
28
诗和远方
Kylin
...绕过的强大工具。它在OLAP这个领域里,凭借其超强的性能、神速的预计算本领,以及能够轻松应对超大型数据集的能力,迅速闯出了自己的一片天,赢得了大家的交口称赞。今天,咱们就手拉手,一起把Kylin项目的神秘面纱给掀起来,瞅瞅它从哪儿来,聊聊它到底牛在哪。咱再通过几个活灵活现的代码实例,实实在在地感受一下这个项目在实际应用中的迷人之处。 一、项目背景(2) 1.1 大数据挑战(2.1) 在大数据时代背景下,随着数据量的爆炸式增长,传统的数据处理技术面临严峻挑战。在面对大量数据需要实时分析的时候,特别是那种涉及多个维度、错综复杂的查询情况,传统的用关系型数据库和现成的查询方案经常会显得力有未逮,就像是老爷车开上高速路,响应速度慢得像蜗牛,资源消耗大到像是大胃王在吃自助餐,让人看着都替它们捏一把汗。 1.2 Kylin的诞生(2.2) 在此背景下,2012年,阿里巴巴集团内部孵化出了一个名为“麒麟”的项目,以应对日益严重的海量数据分析难题。这就是Apache Kylin的雏形。它的目标其实很接地气,就是想在面对超级海量的PB级数据时,能够快到眨眼间完成那些复杂的OLAP查询,就像闪电侠一样迅速。为此,它致力于研究一套超高效的“大数据立方体预计算技术”,让那些商业智能工具即使是在浩如烟海的大数据环境里,也能游刃有余、轻松应对,就像是给它们装上了涡轮引擎,飞速运转起来。 二、Kylin核心技术与原理概述(3) 2.1 立方体构建(3.1) Kylin的核心思想是基于Hadoop平台进行多维数据立方体的预计算。通过定义维度和度量,Kylin将原始数据转化为预先计算好的聚合结果存储在分布式存储系统中,大大提升了查询效率。 java // 示例:创建Kylin Cube CubeInstance cube = new CubeInstance(); cube.setName("sales_cube"); cube.setDesc("A cube for sales analysis"); List tableRefs = ...; // 指定源表信息 cube.setTableRefs(tableRefs); List segments = ...; // 配置分段和维度度量 cube.setSegments(segments); kylinServer.createCube(cube); 2.2 查询优化(3.2) 用户在执行查询时,Kylin会将查询条件映射到预计算好的立方体上,直接返回结果,避免了实时扫描大量原始数据的过程。 java // 示例:使用Kylin进行查询 KylinQuery query = new KylinQuery(); query.setCubeName("sales_cube"); Map dimensions = ...; // 设置维度条件 Map metrics = ...; // 设置度量条件 query.setDimensions(dimensions); query.setMetrics(metrics); Result result = kylinServer.execute(query); 三、Kylin的应用价值探讨(4) 3.1 性能提升(4.1) 通过上述代码示例我们可以直观地感受到,Kylin通过预计算策略极大程度地提高了查询性能,使得企业能够迅速洞察业务趋势,做出决策。 3.2 资源优化(4.2) 此外,Kylin还能有效降低大数据环境下硬件资源的消耗,帮助企业节省成本。这种通过时间换空间的方式,符合很多企业对于大数据分析的实际需求。 结语(5) Apache Kylin在大数据分析领域的成功,正是源自于对现实挑战的深度洞察和技术层面的创新实践。每一个代码片段都蕴含着开发者们对于优化数据处理效能的执着追求和深刻思考。现如今,Kylin已经成功进化为全球众多企业和开发者心头好,他们把它视为处理大数据的超级神器。它持续不断地帮助企业,在浩瀚的数据海洋里淘金,挖出那些深藏不露的价值宝藏。 以上只是Kylin的一小部分故事,更多关于Kylin如何改变大数据处理格局的故事,还有待我们在实际操作与探索中进一步发现和书写。
2023-03-26 14:19:18
77
晚秋落叶
转载文章
Saiku
...用Java开发的开源OLAP数据可视化工具,说白了,并不是一款编程语言或者库。所以呢,我就没法给你直接甩出一段代码示例来啦。不过,我可以手把手给您写一份超级详细的“Saiku在不同网络环境下的配置和使用攻略”,绝对会竭尽全力满足您的各种需求。 1. 引言 在大数据分析领域中,Saiku以其灵活、直观的数据探索能力和强大的多维数据分析功能广受青睐。不管是在我们自己的地盘——本地环境,还是在那云端的神秘服务器,甚至是在跨越网络环境进行部署的时候,都得让我们亲自出手,给Saiku量身定制一套合适的配置和设置方案。这篇指南将手把手带你探索如何在各种网络环境下,成功玩转Saiku的配置和使用。咱俩一边走一边聊,会随时扯到那些可能绊住你的小石头(也就是问题啦),以及如何把它们踢开的独家秘籍(就是解决策略哈)。 2. Saiku的基本概念与架构 (这里可以简要介绍下Saiku的基础知识,如它依赖于Mondrian OLAP引擎,支持多种数据库连接等,帮助读者建立背景知识) 3. 在本地环境配置和使用Saiku (1) 安装与启动 - 首先,你需要下载并安装Saiku Server。就像咱们平时捣鼓个小项目那样,首先得把文件给解压开来,接着麻溜地跳进目录里头。然后,就像启动魔法咒语一样,咱们运行那个特定的启动脚本,就比如说叫“start-saiku.sh”。最后,只需在你的浏览器地址栏输入localhost,再加上指定的那个端口数字,嗖一下,就能打开Saiku酷炫的界面啦! (2) 配置数据源 - 虽然不能给出具体代码示例,但在此环节,你需在Saiku的配置文件中添加你的数据库连接信息,就像人类在面对新环境时需要找到“水源”一样重要。例如,为MySQL配置数据源时,需要填写诸如URL、用户名、密码以及数据立方体名称等详细参数。 4. 在云端服务器配置和使用Saiku (1) 远程部署 - 当Saiku需要在云端服务器上运行时,我们需要考虑网络延迟、安全性和资源分配等问题。首先,你可以通过SSH这类工具,把Saiku服务像打包行李一样上传到服务器上。接着,就像启动一台新电脑那样,在服务器上输入神秘的启动命令,确保这个服务能够在云端畅快地跑起来。 (2) 跨域访问与安全配置 - 如果你的应用跨越了不同网络环境,可能会遇到跨域问题。这时,你可以在Nginx或Apache等反向代理服务器上做相应配置,允许外部网络访问Saiku服务。同时,别忘了加强安全性,比如启用HTTPS,配置防火墙规则等。 5. 针对复杂网络环境的高级配置技巧 - 在复杂的网络环境下,可能涉及多个子网、VPC或者混合云架构,这就需要更精细的路由规划和网络策略设定。比如说,假如Saiku服务藏在一个私有子网里头,而用户又在另一个不同的网络环境里玩,这时候可能就需要捣鼓一下NAT网关啦,或者搞个VPC对等连接什么的,目的就是为了确保大家能既安全又准确地“摸”到Saiku服务。 6. 结语 配置和使用Saiku的过程,就像是在迷宫中寻找出路,需要我们不断地尝试、理解并解决问题。尽管没有具体的代码片段,但每个步骤背后都蕴含着丰富的技术细节和实践经验。只有彻底搞懂每一步操作背后的门道和原理,你才能在任何网络环境里都像老司机那样,轻松玩转这款强大的数据分析神器。 以上内容虽未包含实际代码,但在实践中,每一项配置和设置都会转化为对配置文件或系统参数的具体操作。希望这篇指南能像一位贴心的朋友,手把手带你掌握在各种网络环境下配置和使用Saiku的大招秘籍,而且读完之后,你还能兴奋地想要去解锁更多关于它的新技能呢!
2023-08-17 15:07:18
166
百转千回
Saiku
...Saiku这款超棒的OLAP工具,或者你对数据仓库和数据分析挺感兴趣的,那你可得看看这篇文章,说不定能帮到你! 首先,让我们简单回顾一下什么是Saiku。Saiku是一款开源的BI工具,它能够帮助用户通过直观的界面与OLAP数据源进行交互,从而实现数据的探索和分析。然而,就像任何软件一样,Saiku也有其脆弱的一面。特别是当涉及到系统的稳定性和恢复能力时,如果准备不足,那后果可能是灾难性的。 2. 系统恢复的重要性 想象一下,你的数据库突然崩溃了,所有的分析工作都停止了,这时候你会怎么办?是的,你需要一个可靠的系统恢复计划。这个计划应该包括但不限于定期备份、故障转移策略以及详细的恢复步骤。不过呢,很多人用Saiku的时候,都不太重视系统的恢复,结果就给自己惹了不少麻烦。 举个例子,假设你是一名数据分析师,每天都会使用Saiku来分析销售数据。有一天,由于服务器硬盘损坏,所有的数据都丢失了。要是没提前准备好恢复的招数,那你可就得从头再来,重建整个数据库了。而且这事儿可不小,你得花大把时间去重新找齐所有的原始数据。这样的经历,相信谁都不想再经历第二次。 3. 实践中的问题 让我们深入探讨一些实际遇到的问题。在用Saiku的时候,我发现很多小伙伴都没有定期备份的好习惯,就算备份了,也不知道怎么用这些备份来快速恢复数据。另外,大家对故障转移这部分聊得不多,也就是说,如果主服务器挂了,整个系统可能就会直接瘫痪了。 这里我有一个小建议:为什么不试试编写一个脚本,让它自动执行备份任务呢?这样不仅能够节省时间,还能确保数据的安全性。比如说,你可以在Linux下用crontab设置定时任务,让它自动跑一个简单的bash脚本。这个脚本的作用就是调用MySQL的dump命令,生成数据库的备份文件。这样就不用担心忘记备份了,挺方便的。 bash 编辑crontab crontab -e 添加如下行,每周日凌晨两点执行一次备份 0 2 0 /usr/bin/mysqldump -u username -p'password' database_name > /path/to/backup/db_backup_$(date +\%Y\%m\%d).sql 4. 恢复策略的设计 现在我们已经了解了为什么需要一个好的恢复计划,接下来谈谈如何设计这样一个计划。首先,你需要明确哪些数据是最关键的。然后,根据这些数据的重要程度制定相应的恢复策略。比如说,如果你每天都在更新的数据,那就得时不时地备份一下,甚至可以每一小时就来一次。但如果是那种好几天都不动弹的数据,那就可以放宽心,不用那么频繁地备份了。 另外,别忘了测试你的恢复计划!只有经过实践检验的恢复流程才能真正发挥作用。你可以定期模拟一些常见故障场景,看看你的系统是否能够顺利恢复到正常状态。 5. 代码示例 为了让大家更好地理解,下面我会给出几个具体的代码示例,展示如何使用Saiku API来进行数据恢复操作。 示例1:连接到Saiku服务器 java import org.saiku.service.datasource.IDatasourceService; import org.saiku.service.datasource.MondrianDatasource; public class SaikuConnectionExample { public static void main(String[] args) { // 假设我们已经有了一个名为"myDataSource"的数据源实例 MondrianDatasource myDataSource = new MondrianDatasource(); myDataSource.setName("myDataSource"); // 使用datasource服务保存数据源配置 IDatasourceService datasourceService = ...; // 获取datasource服务实例 datasourceService.save(myDataSource); } } 示例2:从备份文件中恢复数据 这里假设你已经有一个包含所有必要信息的备份文件,比如SQL脚本。 java import java.io.BufferedReader; import java.io.FileReader; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; public class RestoreFromBackupExample { public static void main(String[] args) { try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "username", "password")) { Statement stmt = conn.createStatement(); // 读取备份文件内容并执行 BufferedReader reader = new BufferedReader(new FileReader("/path/to/backup/file.sql")); String line; StringBuilder sql = new StringBuilder(); while ((line = reader.readLine()) != null) { sql.append(line); if (line.trim().endsWith(";")) { stmt.execute(sql.toString()); sql.setLength(0); // 清空StringBuilder } } reader.close(); } catch (Exception e) { e.printStackTrace(); } } } 6. 结语 好了,到这里我们的讨论就告一段落了。希望今天聊的这些能让大家更看重系统恢复计划,也赶紧动手做点啥来提高自己的数据安全,毕竟防患于未然嘛。记住,预防总是胜于治疗,提前做好准备总比事后补救要好得多! 最后,如果你有任何想法或建议,欢迎随时与我交流。数据分析的世界充满了无限可能,让我们一起探索吧! --- 以上就是本次关于“Saiku的系统恢复计划不充分”的全部内容。希望这篇文章能够对你有所帮助,也欢迎大家提出宝贵的意见和建议。
2024-11-18 15:31:47
36
寂静森林
Kylin
...adoop的列式存储OLAP引擎,它通过预先计算并存储聚合数据来加速查询速度。而MySQL作为一个广泛使用的SQL数据库管理系统,提供了丰富的查询语言和存储能力。嘿,兄弟!你听过数据联接这事儿吗?它通常在咱们把数据从一个地方搬进另一个地方或者在查询数据的时候出现。就像拼图一样,对了,就是那种需要精准匹配才能完美组合起来的拼图。用对了联接策略,那操作效率简直能嗖的一下上去,比火箭还快呢!所以啊,小伙伴们,别小瞧了这个小小的联接步骤,它可是咱们大数据处理里的秘密武器! 三、策略一 优化联接条件 实践示例: sql -- 原始查询语句 SELECT FROM kylin_table JOIN mysql_table ON kylin_table.id = mysql_table.id; -- 优化后的查询语句 SELECT FROM kylin_table JOIN mysql_table ON kylin_table.id = mysql_table.id AND kylin_table.date >= '2023-01-01' AND kylin_table.date <= '2023-12-31'; 通过在联接条件中加入过滤条件(如时间范围),可以减少MySQL服务器需要处理的数据量,从而提高联接效率。 四、策略二 利用索引优化 实践示例: 在MySQL表上为联接字段创建索引,可以大大加速查询速度。同时,在Kylin中,确保相关维度的列已经进行了适当的索引,可以进一步提升性能。 sql -- MySQL创建索引 CREATE INDEX idx_kylin_table_id ON kylin_table(id); -- Kylin配置维度索引 id long true 通过这样的配置,不仅MySQL的查询速度得到提升,Kylin的聚合计算也更加高效。 五、策略三 批量导入与增量更新 实践示例: 对于大型数据集,考虑使用批量导入策略,而不是频繁的增量更新。哎呀,你瞧,咱们用批量导入这招,就像是给MySQL服务器做了一次减压操,让它不那么忙碌,喘口气。同时,借助Kylin的离线大法,我们就能让那些实时查询快如闪电,不拖泥带水。这样一来,不管是数据处理还是查询速度,都大大提升了,用户满意度也蹭蹭往上涨呢! bash 批量导入脚本示例 $ hadoop fs -put data.csv /input/ $ bin/hive -e "LOAD DATA INPATH '/input/data.csv' INTO TABLE kylin_table;" 六、策略四 优化联接模式 选择合适的联接模式(如内联接、外联接等)对于性能优化至关重要。哎呀,你得知道,在咱们实际干活的时候,选对了数据联接的方式,就像找到了开锁的金钥匙,能省下不少力气,避免那些没必要的数据大扫荡。比如说,你要是搞个报表啥的,用对了联接方法,数据就乖乖听话,找起来快又准,省得咱们一个个文件翻,一个个字段找,那得多费劲啊!所以,挑对工具,效率就是王道! 实践示例: 假设我们需要查询所有在特定时间段内的订单信息,并且关联了用户的基本信息。这里,我们可以使用内联接: sql SELECT FROM orders o INNER JOIN users u ON o.user_id = u.user_id WHERE o.order_date BETWEEN '2023-01-01' AND '2023-12-31'; 七、总结与展望 通过上述策略的实施,我们能够显著提升Kylin与MySQL联接操作的性能。哎呀,你知道优化数据库操作这事儿,可真是个门道多得很!比如说,调整联接条件啊,用上索引来提速啊,批量导入数据也是一大妙招,还有就是选对联接方式,这些小技巧都能让咱们的操作变得顺畅无比,响应速度嗖嗖的快起来。就像开车走高速,不堵车不绕弯,直奔目的地,那感觉,爽歪歪!哎呀,随着咱手里的数据越来越多,就像超市里的货物堆积如山,技术这玩意儿也跟咱们的手机更新换代一样快。所以啊,要想让咱们的系统运行得又快又好,就得不断调整和改进策略。就像是给汽车定期加油、保养,让它跑得既省油又稳定。这事儿,可得用心琢磨,不能偷懒!未来,随着更多高级特性如分布式计算、机器学习集成等的引入,Kylin与MySQL的联接优化将拥有更广阔的应用空间,助力数据分析迈向更高层次。
2024-09-20 16:04:27
104
百转千回
ElasticSearch
...引擎,其实更多的适合OLAP场景。当然也完全可以使用,因为比如clickhouse、starrocks等的查询速度已经发展的非常快。但你会发现在中文分词搜索上,实现起来有一定困扰。 所以,如果你不差机器,首选方案还是elasticsearch。 3. elasticsearch的适用场景 3.1 经典的日志搜索场景 提到elasticsearch不得不提到它的几个好朋友: 一些公司里经常用elasticsearch来收集日志,然后用kibana来展示和分析。 展开来说,举个例子,你的app打印日志打印到了线上日志文件,当app出现故障你需要做定位筛查的时候,可能需要登录线上机器用grep命令各种查看。 但如果你不差机器资源,可以搭建上述架构,app的日志会被收集到elasticsearch中,最终你可以在kibana中查看日志,kibana里面可以很方面的做各种筛查操作。 这个流畅大概是这样的: 3.2 通用搜索场景 但是没有上图的beats、logstash、kibana,elasticsearch可以自己工作吗?完全可以的! elasticsearch也支持单机部署,数据规模不是很大的情况下,表现也是不错的。所以,你也不用担心因为自己机器资源不够而对elasticsearch望而却步。当然,单机部署的情况下,更多的适合自己玩,对于可靠性的要求就不能太苛刻了。 如果你在用宝塔,那你可以在宝塔面板,左侧“软件商店”中直接找到elasticsearch,并“没有痛苦”的安装。 本篇文章主要讨论选型,所以不涉及安装细节。 3.2.1 性能顾虑 上面提到了“表现”,其实性能只是elasticsearch的一个方面,主要你的机器资源足够(机器资源?对,包括你的机器个数,elasticsearch可以非常方便的横向扩展,以及单机的配置,cpu+内存,内存越高越好,elasticsearch比较吃内存!),它一定会给你很好的性能反应。试想,公司里的app打印线上日志的行数其实可比一般业务系统产生的订单数量要大很多很多,elasticsearch都可以常在日志的实时分析,所以如果你要做通用场景,而且机器资源不是问题,这是完全行得通的。 3.2.2 易用性和可玩性 此外,在使用elasticsearch的时候,会有很多的可玩性。这里不引经据典,呈现很多elasticsearch官方文章的列举优秀特性(当然,确实很优秀!)。 这里举几个例子: (1)中文分词:第一章提到的其它引擎几乎很难实现,elasticsearch对分词器的支持是原生的,因为elasticsearch天生就为全文索引而生,elasticsearch的汉语名字就是“弹性搜索”。这家伙可是专门搞搜索的! 有的朋友可能不了解分词器,比如你的一个字段里存储“今天我要吃冰激凌”,在分词器的加持下,es最终会存储为“今天|我|要|吃|冰激凌”,并且使用倒排索引的形式进行存储。当你搜索“冰激凌”的时候,可以很快的反馈回来。 关于elasticsearch的原理,这里不展开说明,分词器和倒排索引是elasticsearch的最基本的概念。如果有不了解的朋友,可以自行百度一下。而且这两个概念,与elasticsearch其实不挂钩,是搜索中的通用概念。 关于倒排索引,其核心表现如下图: 如果你要用mysql、mongo实现中文分词,这......其实挺麻烦的,可能在后面的版本支持中会实现的很好,但在当前的流行版本中,它们对中文分词是不够友好的。 mysql5.7之后支持外挂第三方分词器,支持中文分词。而在数据量较大的情况下,mysql的多机器部署几乎很难实现,elasticsearch可以很容易的水平扩展。 mongo支持西方语言的分词,但不支持中文、日语、汉语等东方语言,你需要在自己的逻辑代码中实现分词器。 ngram分词,你看看效果:依旧是“今天我要吃冰激凌”,ngram二元分词后即将得到结果“今天、天我、我要、要吃、吃冰、冰激、激凌”。这....,那你搜索冰激凌就搜不出来!咋办呢,当然可以使用三元分词。但是更好的解决方案还是中文分词器,但它们原生并不支持的。 (2)自定义排名场景:比如你的搜索“冰激凌”,结果中返回了有10条,这10条应该有你想对它指定的顺序。最简单的就是用默认的得分,但是如果你想人为干预这个得分怎么办? elasticsearch支持function_score功能(可以不用,这个是增强功能),es会在计算最终得分之前回调这个你指定的function_score回调函数,传入原始得分、行的原始数据,你可以在里面做计算,比如查询其它参考表、或查看是否是广告位,以得到新的score返回给用户。 function_scrore的功能不展开描述,是一个在自定义得分场景下十分有用又简单易用的功能!下面是一个使用示例,不仅如此,它是支持自定义函数的,自由度非常高。 (3)文本高亮:你用mysql或mongo也可以实现,比如用户搜索“冰激凌”,你只需要在逻辑代码中对“冰激凌”替换为“<span class='highlight-term'>冰激凌</span>”,然后前端做样式即可。但如果用户搜索了“好吃的冰激凌”咋办呢?还有就是英文大小写的场景,用户搜索"MAIN",那结果及时匹配到了“main”(小写的),这个单词是否应该高亮呢?也许这时候你会用业务代码实现toLowerCase下基于位置下标的匹配。 挺麻烦的吧,elasticsearch,自动可以返回高亮字段!并且可以自由指定高亮的html前后标签。 (4)实在太多了....这家伙天生为索引而生,而且版本还在不断地迭代。不差机器的话,用用吧! 4. 退而求其次 4.1 普通数据库 尽管elasticsearch在搜索场景下,是非常好用的利器!但是它比较消耗机器资源,如果你的数据规模并不大,而且想快速实现功能。你可以使用mysql或mongo来代替,完全没有问题。 技术是为了解决特定业务场景下的问题,结合当前手头的资源,适合自己的才是最好的。也许你搞了一个单机器的elasticsearch,单机器内存只有2G,它的表现并不会比mysql、mongo来的好。 当然,如果你为了使用上边提到的一些优秀的独有的特性,那elasticsearch一定还是最佳选择! 对于mysql(关系型数据库)和mongo(文档数据库)的区别这里不展开描述了,但对于搜索而言,两种都合适。有时候选型也不用很纠结,其实都是差不太多的东西,适合自己的、自己熟悉的、运维起来顺手的,就是最好的。 4.2 普通数据库实现中文分词搜索的原理 尽管mysql在5.7以后支持外挂第三方分词器,mongo在截止目前的版本中也不支持中文分词(你可能会看到一些文章中说可以指定language为chinese,但其实会报错的)。 其实当你选择普通数据库,你就不得不在逻辑代码中自己实现一套索引分词+搜索分词逻辑。 索引分词+搜索分词?为什么分开写,如果你有用过elasticsearch或solr,你会知道,在指定字段的时候,需要指定index分词器和search分词器。 下面以mongo为例做简要说明。 4.2.1 index分词器 意思是当数据“索引”截断如何分词。首先,这里必须要承认,数据之后存储了,才能被查询。在搜索中,这句话可以换成是“数据只有被索引了,才能被搜索”。 这时候请求打过来了,要索引一条数据,其中某字段是“今天我要吃冰激凌”,分词后得到“今天|我|要|吃|冰激凌”,这个就可以入库了。 如果你使用elasticsearch或solr,这个过程是自动的。如果你使用不支持外观分词器的常规数据库,这个过程你就要手动了,并把分词后的结果用空格分开(最好使用空格,因为西方语言的分词规则就是按空格拆分,以及逗号句号),存入数据库的一个待搜索的字段上。 效果如下图: 本站的其它博文中有介绍IKAnalyzer:https://www.52itw.com/java/6268.html 4.2.2 search分词器 当用户的查询请求打过来,用户输入了“好吃的冰激凌”,分词后得到“好吃|冰激凌”(“的”作为停用词stopwords,被自动忽略了,IKAnalyzer可以指定停用词表)。 于是这时候就回去上图的数据库表里面搜索“好吃 冰激凌”(与index分词器结果统一,还是用空格分隔)。 当然,对于mongo而言,你需要事先开启全文索引db.xxx.ensureIndex({content: "text"}),xxx是集合名,content是字段名,text是全文索引的标识。 mongo搜索的时候用这个语法:db.xxx.find( { $text: { $search: "好吃 冰激凌" } },{ score: { $meta: "textScore" } }).sort( { score: { $meta: "textScore" } } ) 4.2.3 索引库和存储库分开 为了减少单表的大小,为了让普通的列表查询、普通筛选可以跑的更快,你可以对原有的数据原封不动的做一张表。 然后对于搜索场景,再单独对需要被搜索的字段单独拎一张表出来! 然后二者之间做增量信号同步或定时差额同步,可能会有延迟,这个就看你能容忍多长时间(悄悄告诉你,elasticsearch也需要指定这个refresh时间,一般是1s到几秒、甚至分钟级。当然,二者的这个时间对饮的底层目的是不一样的)。 这样,搜索的时候先查询搜索库,拿到一个指针id的列表,然后拿到指针id的列表区存储里把数据一次性捞出来。当然,也是支持分页的,你查询搜索库其实也是普通的数据库查询嘛,支持分页参数的。 4.3 存储库和索引库的延伸阅读 很多有名的开源软件也是使用的存储库与索引库分离的技术方案,如apache atlas: apache atlas对于大数据领域的数据资产元数据管理、数据血缘上可谓是专家,也涉及资产搜索的特性,它的实现思路就是:从搜索库中做搜索、拿到key、再去存储库中做查询。 搜索库:上图右下角,可以看到使用的是elasticsearch、solr或lucene,多个选一个 存储库:上图左下角,可以看到使用的是Cassandra、HBase或BerkeleyDB,多个选一个 虽然apache atlas在只有搜索库或只有存储库的时候也可以很好的工作,但只针对于数据量并不大的场景。 搜索库,擅长搜索!存储库,擅长海量存储!搜索库多样化搜索,然后去存储库做点查。 当你的数据达到海量的时候,es+hbase也是一种很好的解决方案,不在这里展开说明了。
2024-01-27 17:49:04
537
admin-tim
转载文章
...(RDBMS) 支持OLAP应用,采用MPP(Massively Parallel Processing:大规模并行处理系统)架构模式 支持OLTP应用,读写性能可扩展 集群级别的ACID特性 多租户安全 也可被用作分布式Key-Value存储 事务处理与数据分析处理混合型数据库 支持丰富的SQL语句类型,比如:关联子查询 支持绝大部分PostgreSQL的SQL语句 分布式多版本并发控制(MVCC:Multi-version Concurrency Control) 支持JSON和XML格式 Postgres-XL缺少的功能 内建的高可用机制 使用外部机制实现高可能,如:Corosync/Pacemaker 有未来功能提升的空间 增加节点/重新分片数据(re-shard)的简便性 数据重分布(redistribution)期间会锁表 可采用预分片(pre-shard)方式解决,在同台物理服务器上建立多个数据节点,每个节点存储一个数据分片。数据重分布时,将一些数据节点迁出即可 某些外键、唯一性约束功能 Postgres-XL架构 [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-M9lFuEIP-1640133702200)(./assets/postgre-xl.jpg)] 基于开源项目Postgres-XC XL增加了MPP,允许数据节点间直接通讯,交换复杂跨节点关联查询相关数据信息,减少协调器负载。 多个协调器(Coordinator) 应用程序的数据库连入点 分析查询语句,生成执行计划 多个数据节点(DataNode) 实际的数据存储 数据自动打散分布到集群中各数据节点 本地执行查询 一个查询在所有相关节点上并行查询 全局事务管理器(GTM:Global Transaction Manager) 提供事务间一致性视图 部署GTM Proxy实例,以提高性能 Postgre-XL主要组件 GTM (Global Transaction Manager) - 全局事务管理器 GTM是Postgres-XL的一个关键组件,用于提供一致的事务管理和元组可见性控制。 GTM Standby GTM的备节点,在pgxc,pgxl中,GTM控制所有的全局事务分配,如果出现问题,就会导致整个集群不可用,为了增加可用性,增加该备用节点。当GTM出现问题时,GTM Standby可以升级为GTM,保证集群正常工作。 GTM-Proxy GTM需要与所有的Coordinators通信,为了降低压力,可以在每个Coordinator机器上部署一个GTM-Proxy。 Coordinator --协调器 协调器是应用程序到数据库的接口。它的作用类似于传统的PostgreSQL后台进程,但是协调器不存储任何实际数据。实际数据由数据节点存储。协调器接收SQL语句,根据需要获取全局事务Id和全局快照,确定涉及哪些数据节点,并要求它们执行(部分)语句。当向数据节点发出语句时,它与GXID和全局快照相关联,以便多版本并发控制(MVCC)属性扩展到集群范围。 Datanode --数据节点 用于实际存储数据。表可以分布在各个数据节点之间,也可以复制到所有数据节点。数据节点没有整个数据库的全局视图,它只负责本地存储的数据。接下来,协调器将检查传入语句,并制定子计划。然后,根据需要将这些数据连同GXID和全局快照一起传输到涉及的每个数据节点。数据节点可以在不同的会话中接收来自各个协调器的请求。但是,由于每个事务都是惟一标识的,并且与一致的(全局)快照相关联,所以每个数据节点都可以在其事务和快照上下文中正确执行。 Postgres-XL继承了PostgreSQL Postgres-XL是PostgreSQL的扩展并继承了其很多特性: 复杂查询 外键 触发器 视图 事务 MVCC(多版本控制) 此外,类似于PostgreSQL,用户可以通过多种方式扩展Postgres-XL,例如添加新的 数据类型 函数 操作 聚合函数 索引类型 过程语言 安装 环境说明 由于资源有限,gtm一台、另外两台身兼数职。 主机名 IP 角色 端口 nodename 数据目录 gtm 192.168.20.132 GTM 6666 gtm /nodes/gtm 协调器 5432 coord1 /nodes/coordinator xl1 192.168.20.133 数据节点 5433 node1 /nodes/pgdata gtm代理 6666 gtmpoxy01 /nodes/gtm_pxy1 协调器 5432 coord2 /nodes/coordinator xl2 192.168.20.134 数据节点 5433 node2 /nodes/pgdata gtm代理 6666 gtmpoxy02 /nodes/gtm_pxy2 要求 GNU make版本 3.8及以上版本 [root@pg ~] make --versionGNU Make 3.82Built for x86_64-redhat-linux-gnuCopyright (C) 2010 Free Software Foundation, Inc.License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>This is free software: you are free to change and redistribute it.There is NO WARRANTY, to the extent permitted by law. 需安装GCC包 需安装tar包 用于解压缩文件 默认需要GNU Readline library 其作用是可以让psql命令行记住执行过的命令,并且可以通过键盘上下键切换命令。但是可以通过--without-readline禁用这个特性,或者可以指定--withlibedit-preferred选项来使用libedit 默认使用zlib压缩库 可通过--without-zlib选项来禁用 配置hosts 所有主机上都配置 [root@xl2 11] cat /etc/hosts127.0.0.1 localhost192.168.20.132 gtm192.168.20.133 xl1192.168.20.134 xl2 关闭防火墙、Selinux 所有主机都执行 关闭防火墙: [root@gtm ~] systemctl stop firewalld.service[root@gtm ~] systemctl disable firewalld.service selinux设置: [root@gtm ~]vim /etc/selinux/config 设置SELINUX=disabled,保存退出。 This file controls the state of SELinux on the system. SELINUX= can take one of these three values: enforcing - SELinux security policy is enforced. permissive - SELinux prints warnings instead of enforcing. disabled - No SELinux policy is loaded.SELINUX=disabled SELINUXTYPE= can take one of three two values: targeted - Targeted processes are protected, minimum - Modification of targeted policy. Only selected processes are protected. mls - Multi Level Security protection. 安装依赖包 所有主机上都执行 yum install -y flex bison readline-devel zlib-devel openjade docbook-style-dsssl gcc 创建用户 所有主机上都执行 [root@gtm ~] useradd postgres[root@gtm ~] passwd postgres[root@gtm ~] su - postgres[root@gtm ~] mkdir ~/.ssh[root@gtm ~] chmod 700 ~/.ssh 配置SSH免密登录 仅仅在gtm节点配置如下操作: [root@gtm ~] su - postgres[postgres@gtm ~] ssh-keygen -t rsa[postgres@gtm ~] cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys[postgres@gtm ~] chmod 600 ~/.ssh/authorized_keys 将刚生成的认证文件拷贝到xl1到xl2中,使得gtm节点可以免密码登录xl1~xl2的任意一个节点: [postgres@gtm ~] scp ~/.ssh/authorized_keys postgres@xl1:~/.ssh/[postgres@gtm ~] scp ~/.ssh/authorized_keys postgres@xl2:~/.ssh/ 对所有提示都不要输入,直接enter下一步。直到最后,因为第一次要求输入目标机器的用户密码,输入即可。 下载源码 下载地址:https://www.postgres-xl.org/download/ [root@slave ~] ll postgres-xl-10r1.1.tar.gz-rw-r--r-- 1 root root 28121666 May 30 05:21 postgres-xl-10r1.1.tar.gz 编译、安装Postgres-XL 所有节点都安装,编译需要一点时间,最好同时进行编译。 [root@slave ~] tar xvf postgres-xl-10r1.1.tar.gz[root@slave ~] ./configure --prefix=/home/postgres/pgxl/[root@slave ~] make[root@slave ~] make install[root@slave ~] cd contrib/ --安装必要的工具,在gtm节点上安装即可[root@slave ~] make[root@slave ~] make install 配置环境变量 所有节点都要配置 进入postgres用户,修改其环境变量,开始编辑 [root@gtm ~]su - postgres[postgres@gtm ~]vi .bashrc --不是.bash_profile 在打开的文件末尾,新增如下变量配置: export PGHOME=/home/postgres/pgxlexport LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATHexport PATH=$PGHOME/bin:$PATH 按住esc,然后输入:wq!保存退出。输入以下命令对更改重启生效。 [postgres@gtm ~] source .bashrc --不是.bash_profile 输入以下语句,如果输出变量结果,代表生效 [postgres@gtm ~] echo $PGHOME 应该输出/home/postgres/pgxl代表生效 配置集群 生成pgxc_ctl.conf配置文件 [postgres@gtm ~] pgxc_ctl prepare/bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxl/pgxc_ctl/pgxc_ctl_bash.ERROR: File "/home/postgres/pgxl/pgxc_ctl/pgxc_ctl.conf" not found or not a regular file. No such file or directoryInstalling pgxc_ctl_bash script as /home/postgres/pgxl/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxl/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxl/pgxc_ctl --configuration /home/postgres/pgxl/pgxc_ctl/pgxc_ctl.confFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxl/pgxc_ctl 配置pgxc_ctl.conf 新建/home/postgres/pgxc_ctl/pgxc_ctl.conf文件,编辑如下: 对着模板文件一个一个修改,否则会造成初始化过程出现各种神奇问题。 pgxcInstallDir=$PGHOMEpgxlDATA=$PGHOME/data pgxcOwner=postgres---- GTM Master -----------------------------------------gtmName=gtmgtmMasterServer=gtmgtmMasterPort=6666gtmMasterDir=$pgxlDATA/nodes/gtmgtmSlave=y Specify y if you configure GTM Slave. Otherwise, GTM slave will not be configured and all the following variables will be reset.gtmSlaveName=gtmSlavegtmSlaveServer=gtm value none means GTM slave is not available. Give none if you don't configure GTM Slave.gtmSlavePort=20001 Not used if you don't configure GTM slave.gtmSlaveDir=$pgxlDATA/nodes/gtmSlave Not used if you don't configure GTM slave.---- GTM-Proxy Master -------gtmProxyDir=$pgxlDATA/nodes/gtm_proxygtmProxy=y gtmProxyNames=(gtm_pxy1 gtm_pxy2) gtmProxyServers=(xl1 xl2) gtmProxyPorts=(6666 6666) gtmProxyDirs=($gtmProxyDir $gtmProxyDir) ---- Coordinators ---------coordMasterDir=$pgxlDATA/nodes/coordcoordNames=(coord1 coord2) coordPorts=(5432 5432) poolerPorts=(6667 6667) coordPgHbaEntries=(0.0.0.0/0)coordMasterServers=(xl1 xl2) coordMasterDirs=($coordMasterDir $coordMasterDir)coordMaxWALsernder=0 没设置备份节点,设置为0coordMaxWALSenders=($coordMaxWALsernder $coordMaxWALsernder) 数量保持和coordMasterServers一致coordSlave=n---- Datanodes ----------datanodeMasterDir=$pgxlDATA/nodes/dn_masterprimaryDatanode=xl1 主数据节点datanodeNames=(node1 node2)datanodePorts=(5433 5433) datanodePoolerPorts=(6668 6668) datanodePgHbaEntries=(0.0.0.0/0)datanodeMasterServers=(xl1 xl2)datanodeMasterDirs=($datanodeMasterDir $datanodeMasterDir)datanodeMaxWalSender=4datanodeMaxWALSenders=($datanodeMaxWalSender $datanodeMaxWalSender) 集群初始化,启动,停止 初始化 pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf init all 输出结果: /bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxc_ctl --configuration /home/postgres/pgxc_ctl/pgxc_ctl.conf/home/postgres/pgxc_ctl/pgxc_ctl.conf: line 189: $coordExtraConfig: ambiguous redirectFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxc_ctlStopping all the coordinator masters.Stopping coordinator master coord1.Stopping coordinator master coord2.pg_ctl: directory "/home/postgres/pgxc/nodes/coord/coord1" does not existpg_ctl: directory "/home/postgres/pgxc/nodes/coord/coord2" does not existDone.Stopping all the datanode masters.Stopping datanode master datanode1.Stopping datanode master datanode2.pg_ctl: PID file "/home/postgres/pgxc/nodes/datanode/datanode1/postmaster.pid" does not existIs server running?Done.Stop GTM masterwaiting for server to shut down.... doneserver stopped[postgres@gtm ~]$ echo $PGHOME/home/postgres/pgxl[postgres@gtm ~]$ ll /home/postgres/pgxl/pgxc/nodes/gtm/gtm.^C[postgres@gtm ~]$ pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf init all/bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxc_ctl --configuration /home/postgres/pgxc_ctl/pgxc_ctl.conf/home/postgres/pgxc_ctl/pgxc_ctl.conf: line 189: $coordExtraConfig: ambiguous redirectFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxc_ctlInitialize GTM masterERROR: target directory (/home/postgres/pgxc/nodes/gtm) exists and not empty. Skip GTM initilializationDone.Start GTM masterserver startingInitialize all the coordinator masters.Initialize coordinator master coord1.ERROR: target coordinator master coord1 is running now. Skip initilialization.Initialize coordinator master coord2.The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /home/postgres/pgxc/nodes/coord/coord2 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... creating cluster information ... oksyncing data to disk ... okfreezing database template0 ... okfreezing database template1 ... okfreezing database postgres ... okWARNING: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success.Done.Starting coordinator master.Starting coordinator master coord1ERROR: target coordinator master coord1 is already running now. Skip initialization.Starting coordinator master coord22019-05-30 21:09:25.562 EDT [2148] LOG: listening on IPv4 address "0.0.0.0", port 54322019-05-30 21:09:25.562 EDT [2148] LOG: listening on IPv6 address "::", port 54322019-05-30 21:09:25.563 EDT [2148] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"2019-05-30 21:09:25.601 EDT [2149] LOG: database system was shut down at 2019-05-30 21:09:22 EDT2019-05-30 21:09:25.605 EDT [2148] LOG: database system is ready to accept connections2019-05-30 21:09:25.612 EDT [2156] LOG: cluster monitor startedDone.Initialize all the datanode masters.Initialize the datanode master datanode1.Initialize the datanode master datanode2.The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /home/postgres/pgxc/nodes/datanode/datanode1 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... creating cluster information ... oksyncing data to disk ... okfreezing database template0 ... okfreezing database template1 ... okfreezing database postgres ... okWARNING: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success.The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /home/postgres/pgxc/nodes/datanode/datanode2 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... creating cluster information ... oksyncing data to disk ... okfreezing database template0 ... okfreezing database template1 ... okfreezing database postgres ... okWARNING: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success.Done.Starting all the datanode masters.Starting datanode master datanode1.WARNING: datanode master datanode1 is running now. Skipping.Starting datanode master datanode2.2019-05-30 21:09:33.352 EDT [2404] LOG: listening on IPv4 address "0.0.0.0", port 154322019-05-30 21:09:33.352 EDT [2404] LOG: listening on IPv6 address "::", port 154322019-05-30 21:09:33.355 EDT [2404] LOG: listening on Unix socket "/tmp/.s.PGSQL.15432"2019-05-30 21:09:33.392 EDT [2404] LOG: redirecting log output to logging collector process2019-05-30 21:09:33.392 EDT [2404] HINT: Future log output will appear in directory "pg_log".Done.psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"Done.psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"Done.[postgres@gtm ~]$ pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf stop all/bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxc_ctl --configuration /home/postgres/pgxc_ctl/pgxc_ctl.conf/home/postgres/pgxc_ctl/pgxc_ctl.conf: line 189: $coordExtraConfig: ambiguous redirectFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxc_ctlStopping all the coordinator masters.Stopping coordinator master coord1.Stopping coordinator master coord2.pg_ctl: directory "/home/postgres/pgxc/nodes/coord/coord1" does not existDone.Stopping all the datanode masters.Stopping datanode master datanode1.Stopping datanode master datanode2.pg_ctl: PID file "/home/postgres/pgxc/nodes/datanode/datanode1/postmaster.pid" does not existIs server running?Done.Stop GTM masterwaiting for server to shut down.... doneserver stopped[postgres@gtm ~]$ pgxc_ctl/bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxc_ctl --configuration /home/postgres/pgxc_ctl/pgxc_ctl.conf/home/postgres/pgxc_ctl/pgxc_ctl.conf: line 189: $coordExtraConfig: ambiguous redirectFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxc_ctlPGXC monitor allNot running: gtm masterRunning: coordinator master coord1Not running: coordinator master coord2Running: datanode master datanode1Not running: datanode master datanode2PGXC stop coordinator master coord1Stopping coordinator master coord1.pg_ctl: directory "/home/postgres/pgxc/nodes/coord/coord1" does not existDone.PGXC stop datanode master datanode1Stopping datanode master datanode1.pg_ctl: PID file "/home/postgres/pgxc/nodes/datanode/datanode1/postmaster.pid" does not existIs server running?Done.PGXC monitor allNot running: gtm masterRunning: coordinator master coord1Not running: coordinator master coord2Running: datanode master datanode1Not running: datanode master datanode2PGXC monitor allNot running: gtm masterNot running: coordinator master coord1Not running: coordinator master coord2Not running: datanode master datanode1Not running: datanode master datanode2PGXC exit[postgres@gtm ~]$ pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf init all/bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxc_ctl --configuration /home/postgres/pgxc_ctl/pgxc_ctl.conf/home/postgres/pgxc_ctl/pgxc_ctl.conf: line 189: $coordExtraConfig: ambiguous redirectFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxc_ctlInitialize GTM masterERROR: target directory (/home/postgres/pgxc/nodes/gtm) exists and not empty. Skip GTM initilializationDone.Start GTM masterserver startingInitialize all the coordinator masters.Initialize coordinator master coord1.Initialize coordinator master coord2.The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /home/postgres/pgxc/nodes/coord/coord1 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... creating cluster information ... oksyncing data to disk ... okfreezing database template0 ... okfreezing database template1 ... okfreezing database postgres ... okWARNING: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success.The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /home/postgres/pgxc/nodes/coord/coord2 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... creating cluster information ... oksyncing data to disk ... okfreezing database template0 ... okfreezing database template1 ... okfreezing database postgres ... okWARNING: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success.Done.Starting coordinator master.Starting coordinator master coord1Starting coordinator master coord22019-05-30 21:13:03.998 EDT [25137] LOG: listening on IPv4 address "0.0.0.0", port 54322019-05-30 21:13:03.998 EDT [25137] LOG: listening on IPv6 address "::", port 54322019-05-30 21:13:04.000 EDT [25137] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"2019-05-30 21:13:04.038 EDT [25138] LOG: database system was shut down at 2019-05-30 21:13:00 EDT2019-05-30 21:13:04.042 EDT [25137] LOG: database system is ready to accept connections2019-05-30 21:13:04.049 EDT [25145] LOG: cluster monitor started2019-05-30 21:13:04.020 EDT [2730] LOG: listening on IPv4 address "0.0.0.0", port 54322019-05-30 21:13:04.020 EDT [2730] LOG: listening on IPv6 address "::", port 54322019-05-30 21:13:04.021 EDT [2730] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"2019-05-30 21:13:04.057 EDT [2731] LOG: database system was shut down at 2019-05-30 21:13:00 EDT2019-05-30 21:13:04.061 EDT [2730] LOG: database system is ready to accept connections2019-05-30 21:13:04.062 EDT [2738] LOG: cluster monitor startedDone.Initialize all the datanode masters.Initialize the datanode master datanode1.Initialize the datanode master datanode2.The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /home/postgres/pgxc/nodes/datanode/datanode1 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... creating cluster information ... oksyncing data to disk ... okfreezing database template0 ... okfreezing database template1 ... okfreezing database postgres ... okWARNING: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success.The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /home/postgres/pgxc/nodes/datanode/datanode2 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... creating cluster information ... oksyncing data to disk ... okfreezing database template0 ... okfreezing database template1 ... okfreezing database postgres ... okWARNING: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success.Done.Starting all the datanode masters.Starting datanode master datanode1.Starting datanode master datanode2.2019-05-30 21:13:12.077 EDT [25392] LOG: listening on IPv4 address "0.0.0.0", port 154322019-05-30 21:13:12.077 EDT [25392] LOG: listening on IPv6 address "::", port 154322019-05-30 21:13:12.079 EDT [25392] LOG: listening on Unix socket "/tmp/.s.PGSQL.15432"2019-05-30 21:13:12.114 EDT [25392] LOG: redirecting log output to logging collector process2019-05-30 21:13:12.114 EDT [25392] HINT: Future log output will appear in directory "pg_log".2019-05-30 21:13:12.079 EDT [2985] LOG: listening on IPv4 address "0.0.0.0", port 154322019-05-30 21:13:12.079 EDT [2985] LOG: listening on IPv6 address "::", port 154322019-05-30 21:13:12.081 EDT [2985] LOG: listening on Unix socket "/tmp/.s.PGSQL.15432"2019-05-30 21:13:12.117 EDT [2985] LOG: redirecting log output to logging collector process2019-05-30 21:13:12.117 EDT [2985] HINT: Future log output will appear in directory "pg_log".Done.psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"Done.psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"Done. 启动 pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf start all 关闭 pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf stop all 查看集群状态 [postgres@gtm ~]$ pgxc_ctl monitor all/bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxc_ctl --configuration /home/postgres/pgxc_ctl/pgxc_ctl.conf/home/postgres/pgxc_ctl/pgxc_ctl.conf: line 189: $coordExtraConfig: ambiguous redirectFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxc_ctlRunning: gtm masterRunning: coordinator master coord1Running: coordinator master coord2Running: datanode master datanode1Running: datanode master datanode2 配置集群信息 分别在数据节点、协调器节点上分别执行以下命令: 注:本节点只执行修改操作即可(alert node),其他节点执行创建命令(create node)。因为本节点已经包含本节点的信息。 create node coord1 with (type=coordinator,host=xl1, port=5432);create node coord2 with (type=coordinator,host=xl2, port=5432);alter node coord1 with (type=coordinator,host=xl1, port=5432);alter node coord2 with (type=coordinator,host=xl2, port=5432);create node datanode1 with (type=datanode, host=xl1,port=15432,primary=true,PREFERRED);create node datanode2 with (type=datanode, host=xl2,port=15432);alter node datanode1 with (type=datanode, host=xl1,port=15432,primary=true,PREFERRED);alter node datanode2 with (type=datanode, host=xl2,port=15432);select pgxc_pool_reload(); 分别登陆数据节点、协调器节点验证 postgres= select from pgxc_node;node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred | node_id-----------+-----------+-----------+-----------+----------------+------------------+-------------coord1 | C | 5432 | xl1 | f | f | 1885696643coord2 | C | 5432 | xl2 | f | f | -1197102633datanode2 | D | 15432 | xl2 | f | f | -905831925datanode1 | D | 15432 | xl1 | t | f | 888802358(4 rows) 测试 插入数据 在数据节点1,执行相关操作。 通过协调器端口登录PG [postgres@xl1 ~]$ psql -p 5432psql (PGXL 10r1.1, based on PG 10.6 (Postgres-XL 10r1.1))Type "help" for help.postgres= create database lei;CREATE DATABASEpostgres= \c lei;You are now connected to database "lei" as user "postgres".lei= create table test1(id int,name text);CREATE TABLElei= insert into test1(id,name) select generate_series(1,8),'测试';INSERT 0 8lei= select from test1;id | name----+------1 | 测试2 | 测试5 | 测试6 | 测试8 | 测试3 | 测试4 | 测试7 | 测试(8 rows) 注:默认创建的表为分布式表,也就是每个数据节点值存储表的部分数据。关于表类型具体说明,下面有说明。 通过15432端口登录数据节点,查看数据 有5条数据 [postgres@xl1 ~]$ psql -p 15432psql (PGXL 10r1.1, based on PG 10.6 (Postgres-XL 10r1.1))Type "help" for help.postgres= \c lei;You are now connected to database "lei" as user "postgres".lei= select from test1;id | name----+------1 | 测试2 | 测试5 | 测试6 | 测试8 | 测试(5 rows) 登录到节点2,查看数据 有3条数据 [postgres@xl2 ~]$ psql -p15432psql (PGXL 10r1.1, based on PG 10.6 (Postgres-XL 10r1.1))Type "help" for help.postgres= \c lei;You are now connected to database "lei" as user "postgres".lei= select from test1;id | name----+------3 | 测试4 | 测试7 | 测试(3 rows) 两个节点的数据加起来整个8条,没有问题。 至此Postgre-XL集群搭建完成。 创建数据库、表时可能会出现以下错误: ERROR: Failed to get pooled connections 是因为pg_hba.conf配置不对,所有节点加上host all all 192.168.20.0/0 trust并重启集群即可。 ERROR: No Datanode defined in cluster 首先确认是否创建了数据节点,也就是create node相关的命令。如果创建了则执行select pgxc_pool_reload();使其生效即可。 集群管理与应用 表类型说明 REPLICATION表:各个datanode节点中,表的数据完全相同,也就是说,插入数据时,会分别在每个datanode节点插入相同数据。读数据时,只需要读任意一个datanode节点上的数据。 建表语法: CREATE TABLE repltab (col1 int, col2 int) DISTRIBUTE BY REPLICATION; DISTRIBUTE :会将插入的数据,按照拆分规则,分配到不同的datanode节点中存储,也就是sharding技术。每个datanode节点只保存了部分数据,通过coordinate节点可以查询完整的数据视图。 CREATE TABLE disttab(col1 int, col2 int, col3 text) DISTRIBUTE BY HASH(col1); 模拟数据插入 任意登录一个coordinate节点进行建表操作 [postgres@gtm ~]$ psql -h xl1 -p 5432 -U postgrespostgres= INSERT INTO disttab SELECT generate_series(1,100), generate_series(101, 200), 'foo';INSERT 0 100postgres= INSERT INTO repltab SELECT generate_series(1,100), generate_series(101, 200);INSERT 0 100 查看数据分布结果: DISTRIBUTE表分布结果 postgres= SELECT xc_node_id, count() FROM disttab GROUP BY xc_node_id;xc_node_id | count ------------+-------1148549230 | 42-927910690 | 58(2 rows) REPLICATION表分布结果 postgres= SELECT count() FROM repltab;count -------100(1 row) 查看另一个datanode2中repltab表结果 [postgres@datanode2 pgxl9.5]$ psql -p 15432psql (PGXL 10r1.1, based on PG 10.6 (Postgres-XL 10r1.1))Type "help" for help.postgres= SELECT count() FROM repltab;count -------100(1 row) 结论:REPLICATION表中,datanode1,datanode2中表是全部数据,一模一样。而DISTRIBUTE表,数据散落近乎平均分配到了datanode1,datanode2节点中。 新增数据节点与数据重分布 在线新增节点、并重新分布数据。 新增datanode节点 在gtm集群管理节点上执行pgxc_ctl命令 [postgres@gtm ~]$ pgxc_ctl/bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxc_ctl --configuration /home/postgres/pgxc_ctl/pgxc_ctl.confFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxc_ctlPGXC 在服务器xl3上,新增一个master角色的datanode节点,名称是datanode3 端口号暂定5430,pool master暂定6669 ,指定好数据目录位置,从两个节点升级到3个节点,之后要写3个none none应该是datanodeSpecificExtraConfig或者datanodeSpecificExtraPgHba配置PGXC add datanode master datanode3 xl3 15432 6671 /home/postgres/pgxc/nodes/datanode/datanode3 none none none 等待新增完成后,查询集群节点状态: postgres= select from pgxc_node;node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred | node_id-----------+-----------+-----------+-----------+----------------+------------------+-------------datanode1 | D | 15432 | xl1 | t | f | 888802358datanode2 | D | 15432 | xl2 | f | f | -905831925datanode3 | D | 15432 | xl3 | f | f | -705831925coord1 | C | 5432 | xl1 | f | f | 1885696643coord2 | C | 5432 | xl2 | f | f | -1197102633(4 rows) 节点新增完毕 数据重新分布 由于新增节点后无法自动完成数据重新分布,需要手动操作。 DISTRIBUTE表分布在了node1,node2节点上,如下: postgres= SELECT xc_node_id, count() FROM disttab GROUP BY xc_node_id;xc_node_id | count ------------+-------1148549230 | 42-927910690 | 58(2 rows) 新增一个节点后,将sharding表数据重新分配到三个节点上,将repl表复制到新节点 重分布sharding表postgres= ALTER TABLE disttab ADD NODE (datanode3);ALTER TABLE 复制数据到新节点postgres= ALTER TABLE repltab ADD NODE (datanode3);ALTER TABLE 查看新的数据分布: postgres= SELECT xc_node_id, count() FROM disttab GROUP BY xc_node_id;xc_node_id | count ------------+--------700122826 | 36-927910690 | 321148549230 | 32(3 rows) 登录datanode3(新增的时候,放在了xl3服务器上,端口15432)节点查看数据: [postgres@gtm ~]$ psql -h xl3 -p 15432 -U postgrespsql (PGXL 10r1.1, based on PG 10.6 (Postgres-XL 10r1.1))Type "help" for help.postgres= select count() from repltab;count -------100(1 row) 很明显,通过 ALTER TABLE tt ADD NODE (dn)命令,可以将DISTRIBUTE表数据重新分布到新节点,重分布过程中会中断所有事务。可以将REPLICATION表数据复制到新节点。 从datanode节点中回收数据 postgres= ALTER TABLE disttab DELETE NODE (datanode3);ALTER TABLEpostgres= ALTER TABLE repltab DELETE NODE (datanode3);ALTER TABLE 删除数据节点 Postgresql-XL并没有检查将被删除的datanode节点是否有replicated/distributed表的数据,为了数据安全,在删除之前需要检查下被删除节点上的数据,有数据的话,要回收掉分配到其他节点,然后才能安全删除。删除数据节点分为四步骤: 1.查询要删除节点dn3的oid postgres= SELECT oid, FROM pgxc_node;oid | node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred | node_id -------+-----------+-----------+-----------+-----------+----------------+------------------+-------------11819 | coord1 | C | 5432 | datanode1 | f | f | 188569664316384 | coord2 | C | 5432 | datanode2 | f | f | -119710263316385 | node1 | D | 5433 | datanode1 | f | t | 114854923016386 | node2 | D | 5433 | datanode2 | f | f | -92791069016397 | dn3 | D | 5430 | datanode1 | f | f | -700122826(5 rows) 2.查询dn3对应的oid中是否有数据 testdb= SELECT FROM pgxc_class WHERE nodeoids::integer[] @> ARRAY[16397];pcrelid | pclocatortype | pcattnum | pchashalgorithm | pchashbuckets | nodeoids ---------+---------------+----------+-----------------+---------------+-------------------16388 | H | 1 | 1 | 4096 | 16397 16385 1638616394 | R | 0 | 0 | 0 | 16397 16385 16386(2 rows) 3.有数据的先回收数据 postgres= ALTER TABLE disttab DELETE NODE (dn3);ALTER TABLEpostgres= ALTER TABLE repltab DELETE NODE (dn3);ALTER TABLEpostgres= SELECT FROM pgxc_class WHERE nodeoids::integer[] @> ARRAY[16397];pcrelid | pclocatortype | pcattnum | pchashalgorithm | pchashbuckets | nodeoids ---------+---------------+----------+-----------------+---------------+----------(0 rows) 4.安全删除dn3 PGXC$ remove datanode master dn3 clean 故障节点FAILOVER 1.查看当前集群状态 [postgres@gtm ~]$ psql -h xl1 -p 5432psql (PGXL 10r1.1, based on PG 10.6 (Postgres-XL 10r1.1))Type "help" for help.postgres= SELECT oid, FROM pgxc_node;oid | node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred | node_id-------+-----------+-----------+-----------+-----------+----------------+------------------+-------------11739 | coord1 | C | 5432 | xl1 | f | f | 188569664316384 | coord2 | C | 5432 | xl2 | f | f | -119710263316387 | datanode2 | D | 15432 | xl2 | f | f | -90583192516388 | datanode1 | D | 15432 | xl1 | t | t | 888802358(4 rows) 2.模拟datanode1节点故障 直接关闭即可 PGXC stop -m immediate datanode master datanode1Stopping datanode master datanode1.Done. 3.测试查询 只要查询涉及到datanode1上的数据,那么该查询就会报错 postgres= SELECT xc_node_id, count() FROM disttab GROUP BY xc_node_id;WARNING: failed to receive file descriptors for connectionsERROR: Failed to get pooled connectionsHINT: This may happen because one or more nodes are currently unreachable, either because of node or network failure.Its also possible that the target node may have hit the connection limit or the pooler is configured with low connections.Please check if all nodes are running fine and also review max_connections and max_pool_size configuration parameterspostgres= SELECT xc_node_id, FROM disttab WHERE col1 = 3;xc_node_id | col1 | col2 | col3------------+------+------+-------905831925 | 3 | 103 | foo(1 row) 测试发现,查询范围如果涉及到故障的node1节点,会报错,而查询的数据范围不在node1上的话,仍然可以查询。 4.手动切换 要想切换,必须要提前配置slave节点。 PGXC$ failover datanode node1 切换完成后,查询集群 postgres= SELECT oid, FROM pgxc_node;oid | node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred | node_id -------+-----------+-----------+-----------+-----------+----------------+------------------+-------------11819 | coord1 | C | 5432 | datanode1 | f | f | 188569664316384 | coord2 | C | 5432 | datanode2 | f | f | -119710263316386 | node2 | D | 15432 | datanode2 | f | f | -92791069016385 | node1 | D | 15433 | datanode2 | f | t | 1148549230(4 rows) 发现datanode1节点的ip和端口都已经替换为配置的slave了。 本篇文章为转载内容。原文链接:https://blog.csdn.net/qianglei6077/article/details/94379331。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2023-01-30 11:09:03
94
转载
站内搜索
用于搜索本网站内部文章,支持栏目切换。
知识学习
实践的时候请根据实际情况谨慎操作。
随机学习一条linux命令:
mkdir -p dir1/dir2
- 创建多级目录。
推荐内容
推荐本栏目内的其它文章,看看还有哪些文章让你感兴趣。
2023-04-28
2023-08-09
2023-06-18
2023-04-14
2023-02-18
2023-04-17
2024-01-11
2023-10-03
2023-09-09
2023-06-13
2023-08-07
2023-03-11
历史内容
快速导航到对应月份的历史文章列表。
随便看看
拉到页底了吧,随便看看还有哪些文章你可能感兴趣。
时光飞逝
"流光容易把人抛,红了樱桃,绿了芭蕉。"