前端技术
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
[物理执行计划]的搜索结果
这里是文章列表。热门标签的颜色随机变换,标签颜色没有特殊含义。
点击某个标签可搜索标签相关的文章。
点击某个标签可搜索标签相关的文章。
Impala
...SQL语句转化为高效执行计划。它就像个精打细算的小能手,会先摸底各种可能的执行方案,挨个评估、对比,最后选出那个花钱最少(或者说预计跑得最快的)的最优路径来实施。这个过程犹如一位精密的导航员,在海量数据的大海中为我们的查询找到最优航线。 03 查询优化器工作流程 1. 解析与验证阶段 当我们提交一条SQL查询时,优化器首先对其进行词法和语法解析,确保SQL语句结构正确。例如: sql -- 示例SQL查询 SELECT FROM employees WHERE department = 'IT' ORDER BY salary DESC; 2. 逻辑优化阶段 解析后的SQL被转化为逻辑执行计划,如关系代数表达式。在此阶段,优化器会进行子查询展开、常量折叠等逻辑优化操作。 3. 物理优化阶段 进一步地,优化器会生成多种可能的物理执行计划,并计算每种计划的执行代价(如I/O代价、CPU代价)。比如,拿刚才那个查询来说吧,我们可能会琢磨两种不同的处理方法。一种呢,是先按照部门给它筛选一遍,然后再来个排序;另一种嘛,就是先不管三七二十一,先排个序再说,完了再进行过滤操作。 4. 计划选择阶段 根据各种物理执行计划的代价估算,优化器会选择出代价最低的那个计划。最终,Impala将按照选定的最优执行计划来执行查询。 04 实战示例:观察查询计划 让我们实际动手,通过EXPLAIN命令观察Impala如何优化查询: sql -- 使用EXPLAIN命令查看查询计划 EXPLAIN SELECT FROM employees WHERE department = 'IT' ORDER BY salary DESC; 运行此命令后,Impala会返回详细的执行计划,其中包括了各个阶段的操作符、输入输出以及预估的行数和代价。从这些信息中,我们可以窥见查询优化器背后的“智慧”。 05 探讨与思考 理解查询优化器的工作机制,有助于我们在编写SQL查询时更好地利用Impala的性能优势,比如合理设计索引、避免全表扫描等。同时呢,咱们也得明白这么个道理,虽然现在这查询优化器已经聪明到飞起,但在某些特定的情况下,它可能也会犯迷糊,没法选出最优解。这时候啊,就得我们这些懂业务、又摸透数据库原理的人出手了,瞅准时机,亲自上阵给它来个手工优化,让事情变得美滋滋的。 总结来说,Impala查询优化器是我们在大数据海洋中探寻宝藏的重要工具,只有深入了解并熟练运用,才能让我们的数据探索之旅更加高效顺畅。让我们一起携手揭开查询优化器的秘密,共同探索这片充满无限可能的数据世界吧!
2023-10-09 10:28:04
408
晚秋落叶
转载文章
...史数据动态优化SQL执行计划,显著提升系统性能。此外,增强的云基础设施支持能力,使得跨公有云、私有云及本地环境的多云数据库资源得以统一管理,简化混合云环境下的运维复杂性。 同时,针对数据库安全性的重视也在不断提升。Oracle Enterprise Manager提供了更为全面的安全审计与合规检查工具,确保数据库活动符合最新的安全标准与法规要求,有效防止潜在的数据泄露风险。 综上所述,随着企业数字化转型的加速推进,高效、智能且安全的数据库管理系统愈发重要。对于Oracle Enterprise Manager的用户而言,持续关注产品更新迭代并结合实际业务需求升级运维策略,将有助于提升整体IT运营效率与稳定性,以应对日益复杂的业务挑战和不断变化的技术环境。
2023-07-25 18:45:23
131
转载
DorisDB
...询语句自动选择最优的执行计划。但是,有时候我们需要手动调整优化器的行为。例如,我们可以使用EXPLAIN语句查看优化器选择的执行计划: sql EXPLAIN SELECT FROM table_name WHERE age > 18; 如果我们发现优化器选择的执行计划不是最优的,我们可以使用FORCE_INDEX语句强制优化器使用特定的索引: sql SELECT FROM table_name FORCE INDEX(idx_age) WHERE age > 18; 五、如何降低磁盘I/O操作? 1. 使用流式计算 流式计算是一种高效的处理大量数据的方式。在DorisDB中,我们可以使用INSERT INTO SELECT语句进行流式计算: sql INSERT INTO new_table SELECT FROM old_table WHERE age > 18; 这个语句会从old_table表中选择age大于18的数据,并插入到new_table表中。 2. 使用Bloom Filter Bloom Filter是一种空间换时间的数据结构,它可以快速判断一个元素是否存在于集合中。在DorisDB这个数据库里,我们有个小妙招,就是用Bloom Filter这家伙来帮咱们提前把一些肯定不存在的结果剔除掉。这样一来,就能有效减少磁盘I/O操作,让查询速度嗖嗖的提升。 总结,通过以上的方法,我们可以有效地提高DorisDB的查询性能。当然啦,这只是入门级别的小窍门,具体的优化方案咱们还得根据实际情况灵活变通,不断调整优化~希望这篇文章能够帮助你更好地理解和使用DorisDB。
2023-05-04 20:31:52
524
雪域高原-t
PostgreSQL
...按照该索引的顺序进行物理存储。在PostgreSQL中,通过CLUSTER命令可以创建聚簇索引,使得表中的行根据指定字段的值重新排列,并按照新的顺序构建索引。查询时,如果条件符合聚簇索引的排序规则,那么数据库可以直接定位到相关数据块,从而显著提高检索速度。 查询执行计划 , 查询执行计划是数据库管理系统对SQL查询语句的一种内部解析和优化过程的结果表现形式。它详细列出了数据库如何执行特定查询的步骤,包括将使用哪些索引、连接顺序以及操作的预计成本等信息。在PostgreSQL中,通过EXPLAIN或EXPLAIN ANALYZE命令可以获得查询执行计划,有助于我们了解查询性能瓶颈并优化索引策略。 覆盖索引 , 覆盖索引是指一个索引包含了满足查询所需的所有列,即查询结果可以直接从索引中获取而无需访问底层的数据行。这能极大地减少I/O操作,提高查询性能。在PostgreSQL中,虽然没有明确的“覆盖索引”概念,但可以通过创建包含所有需要查询字段的复合索引来实现类似效果,从而避免额外的数据块读取操作。
2023-07-04 17:44:31
345
梦幻星空_t
PostgreSQL
...漫画书一样,瞧瞧查询执行的“剧本”,一目了然地看到哪些字段正在被索引这位幕后英雄助力,又有哪些字段还在等待被发掘利用。这样我们就可以根据实际情况来决定是否需要创建索引。 sql EXPLAIN SELECT FROM users WHERE age > 20; 上面的SQL语句将会返回一个表格,其中包含了查询的执行计划。我们可以看到,age字段被使用到了索引,而name字段没有被使用到索引。 2. 观察SQL语句的执行情况 除了使用explain命令外,我们还可以直接观察SQL语句的执行情况,来判断是否需要创建索引。咱们可以翻翻数据库的日志文件,或者使使劲儿数据库监控工具这把“神器”,瞧瞧SQL语句执行花了多久、CPU被占用了多少、磁盘I/O的情况怎么样,这些信息都能一目了然。要是你发现某个SQL语句运行老半天还在转悠,或者CPU占用噌噌往上涨得离谱,那很可能就是因为你还没给它创建索引。 三、解决方法 知道了上述的原因后,我们就可以采取一些措施来解决这个问题了。首先,我们可以尽量减少索引的数量。这意味着我们需要更加精确地选择要创建索引的字段,避免无谓的开销。其次,咱们还可以时不时地给索引做个“大扫除”,重新构建一下,或者考虑用上一些特殊的索引技巧。比如,就像覆盖索引啦,唯一索引这些小玩意儿,都能让数据库更好地运转起来。最后,我们还可以琢磨一下采用数据库分区或者分片这招,让查询的压力能够分散开来,这样一来就不会把所有的“重活”都压在一块儿了。 四、总结 总的来说,索引是一个非常重要的概念,它能够极大地提高数据库的查询效率。然而,如果索引创建得过多,就会导致查询性能下降。因此,我们在创建索引时,一定要考虑到实际情况,避免盲目创建。同时呢,咱们也得不断给自己充电,学点新鲜的知识,掌握更多的技能才行。这样一来,面对各种难缠的问题,咱们就能更加游刃有余地解决它们了。只有这样,我们才能够成为一名真正的数据库专家。
2023-06-12 18:34:17
502
青山绿水-t
DorisDB
...基本理解,这包括查询计划的生成、数据分区的选择以及执行引擎的工作原理等。当你发现查询速度不尽如人意时,可以通过EXPLAIN命令来查看SQL语句的执行计划,如同医生检查病人的“体检报告”一样: sql -- 使用EXPLAIN获取查询计划 EXPLAIN SELECT FROM my_table WHERE key = 'some_value'; 通过分析这个执行计划,我们可以了解到查询涉及哪些分区、索引是否被有效利用等关键信息,从而为优化工作找准方向。 3. 优化策略一 合理设计表结构与分区策略 - 列选择性优化:由于DorisDB是列式存储,高选择性的列(即唯一或接近唯一的列)能更好地发挥其优势。例如,对于用户ID这样的列,将其设为主键或构建Bloom Filter索引,可以大幅提升查询性能。 sql -- 创建包含主键的表 CREATE TABLE my_table ( user_id INT PRIMARY KEY, ... ); - 分区设计:根据业务需求和数据分布特性,合理设计分区策略至关重要。比如,咱们可以按照时间段给数据分区,这样做的好处可多了。首先呢,能大大减少需要扫描的数据量,让查询过程不再那么费力;其次,还能巧妙地利用局部性原理,就像你找东西时先从最近的地方找起一样,这样就能显著提升查询的效率,让你的数据查找嗖嗖快! sql -- 按天分区 CREATE TABLE my_table ( ... ) PARTITION BY RANGE (dt) ( PARTITION p20220101 VALUES LESS THAN ("2022-01-02"), PARTITION p20220102 VALUES LESS THAN ("2022-01-03"), ... ); 4. 优化策略二 SQL查询优化 - 避免全表扫描:尽量在WHERE子句中指定明确的过滤条件,利用索引加速查询。例如,假设我们已经为user_id字段创建了索引,那么以下查询会更高效: sql SELECT FROM my_table WHERE user_id = 123; - 减少数据传输量:只查询需要的列,避免使用SELECT 。同时,合理运用聚合函数和分组,避免不必要的计算和排序。 sql -- 只查询特定列,避免全表扫描 SELECT user_name, email FROM my_table WHERE user_id = 123; -- 合理运用GROUP BY和聚合函数 SELECT COUNT(), category FROM my_table GROUP BY category; 5. 优化策略三 系统配置调优 DorisDB提供了丰富的系统参数供用户调整以适应不同场景下的性能需求。比方说,你可以通过调节max_scan_range_length这个参数,来决定每次查询时最多能扫描多少数据范围,就像控制扫地机器人的清扫范围那样。再者,通过巧妙调整那些和内存相关的设置,就能让服务器资源得到充分且高效的利用,就像精心安排储物空间,让每个角落都物尽其用。 6. 结语 优化DorisDB的SQL查询性能是一个综合且持续的过程,需要结合业务特点和数据特征,从表结构设计、查询语句编写到系统配置调整等多个维度着手。每个环节都需细心打磨,才能使DorisDB在大数据洪流中游刃有余,提供更为出色的服务。每一次对DorisDB的优化,都是我们携手这位好伙伴,一起摸爬滚打、不断解锁新技能、共同进步的重要印记。这样一来,咱的数据分析之路也能走得更顺溜,效率嗖嗖往上涨,就像坐上了火箭一样快呢!
2023-05-07 10:47:25
500
繁华落尽
转载文章
...d)方式解决,在同台物理服务器上建立多个数据节点,每个节点存储一个数据分片。数据重分布时,将一些数据节点迁出即可 某些外键、唯一性约束功能 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
转载
MySQL
...,以及定期分析并优化执行计划,都是提升MySQL数据库性能的关键手段。 此外,随着数据安全问题日益凸显,MySQL的安全配置和权限管理同样值得深入研究。学习如何设置复杂的密码策略、实现用户访问审计、利用SSL加密传输数据,以及对备份与恢复策略进行定制化设计,是确保数据库系统稳定运行和数据安全的重要步骤。 综上所述,在掌握了MySQL数据库的基础创建操作后,持续关注MySQL最新动态,深入了解数据库性能调优和安全管理领域,将极大地助力您在实际项目中构建更加健壮、高效的数据库架构。
2023-08-12 18:53:34
138
码农
MySQL
...XPLAIN分析查询执行计划、利用慢查询日志定位瓶颈,并结合实例探讨了分区表、分库分表策略在高并发场景下的应用。 综上所述,无论是紧跟MySQL最新技术动态,还是深化对数据库内部机制和性能优化的理解,都将为您的数据库管理工作带来显著提升。持续学习并实践这些进阶知识,能够帮助您更好地应对日益增长的数据管理和分析挑战。
2023-08-18 09:15:20
63
算法侠
MySQL
...解如何查看MySQL执行SQL语句所需时间并进行性能调优后,进一步关注数据库性能优化的实践和最新进展至关重要。近期,Percona在其官方博客上发布了一篇关于MySQL 8.0新特性的深度解析文章,其中详细介绍了如何利用新版本中的执行计划改进功能来优化查询性能(链接:[实际链接])。MySQL 8.0引入了对索引条件推断、半联接转换以及优化器提示等方面的增强,这些都能够显著影响SQL语句的执行效率。 同时,InfoQ网站近期报道了一项由阿里云团队主导的重大突破,他们在MySQL数据库性能优化方面取得新成果,通过智能SQL优化引擎,能够实时分析与优化线上运行的SQL语句,减少慢查询,提升整体数据库性能(链接:[实际链接])。这项技术结合机器学习算法,为大规模生产环境下的MySQL性能调优提供了有力支持。 此外,MariaDB也在其最新的5.5版本中推出了一系列性能优化工具及特性,如动态列压缩技术和更完善的资源组管理,旨在帮助企业用户更好地监控和调整数据库操作,降低SQL执行时间(链接:[实际链接])。 总之,在数据库性能优化领域,无论是开源的MySQL还是其分支MariaDB,都在不断演进和创新,以满足日益增长的数据处理需求。持续跟进相关领域的最新研究和技术动态,对于提高数据库系统效能、保障业务稳定运行具有不可忽视的意义。
2023-03-20 17:28:08
51
数据库专家
MySQL
...ery; 检查查找执行计划 3.查明数据库结构的问题 show create table tablename; 检查表信息 show index from tablename; 检查索引信息 select from information_schema.tables where table_name = 'tablename'\G; 检查表结构 4.效能调整问题 set global slow_query_log=1; 启动慢查找日志 set global long_query_time=2; 设定长查找时间阈值为2s show variables like '%query%'; 检查MySQL的查找相关变量 通过以上操作,我们可以更好地理解和解析在线MySQL的问题,确保数据库的高效运行。
2023-04-11 19:17:38
93
电脑达人
MyBatis
...SQL版已支持批处理执行计划功能,可以显著提升包括批量插入在内的大批量数据操作性能。通过智能分析SQL模式,实现对批量DML语句的合并执行,有效减少网络传输开销和数据库引擎内部的并发控制成本,进一步提高整体系统的吞吐量。 此外,在企业级应用开发中,结合MyBatis-Plus等增强工具集,开发者能够更加便捷地进行批量插入以及其他复杂操作,同时这些工具集也提供了更强大的插件机制,可无缝接入自定义拦截器,确保在进行高效数据操作的同时,满足日志记录、权限控制等多样化业务需求。 因此,对于持续追求高效率、高性能数据库操作的技术人员来说,关注数据库技术前沿动态,深入理解并灵活运用MyBatis框架及其周边生态工具,无疑将大大提升项目实施的成功率和系统的稳定性。
2023-10-03 13:28:23
116
林中小径_t
ElasticSearch
...策略以及更高效的查询执行计划,使得即使面对大规模数据集,也能在保证高精度的同时大大缩短响应时间。 深入理解并合理应用Elasticsearch的邻近关键字匹配技术,不仅有助于企业提升服务质量和客户满意度,也为未来构建智能化、个性化的搜索推荐系统提供了坚实的技术支撑。在大数据时代,掌握这一关键技术,无疑将为企业带来更大的竞争优势和发展潜力。
2023-05-29 16:02:42
463
凌波微步_t
Datax
...实现了资源利用与任务执行速度的最佳平衡。 另外,随着硬件技术的快速发展,例如高性能多核处理器以及高速网络设备的普及,为提高并行处理能力提供了更为广阔的空间。然而,这也对软件层面的并行设计提出了更高要求,如何更好地发挥硬件潜力,避免因过度并行导致的资源争抢和性能瓶颈,是当前大数据领域的重要研究课题。 同时,关于数据库系统的并行处理机制,PostgreSQL社区最近也发布了一系列改进措施,旨在优化大规模数据查询时的并行执行计划,从而提高处理海量数据的工作效率。这些实践同样可为DataX及其他类似工具在并行度优化方面提供参考和借鉴。 综上所述,并行度配置不仅是一个技术性问题,更是一个结合实际应用场景进行精细化调优的过程。在面对日益增长的数据处理需求时,理解并灵活运用并行处理原理将有助于我们在大数据时代实现更高效的数据迁移与处理。
2023-11-16 23:51:46
639
人生如戏-t
MySQL
...断优化内存管理和查询执行计划,使得处理复杂关联查询的效率得到提升。 另外,针对大数据时代下对实时性要求极高的场景,如实时风控和智能推荐,业界开始采用更先进的技术方案,如图数据库与Elasticsearch结合的方式,通过图形模型表达实体间的关系,从而实现实时高效的多表关联查询。 综上所述,尽管Elasticsearch的join类型在特定场景下存在局限性,但通过持续的技术创新和最佳实践的应用,我们能够有效克服这些挑战,并充分利用Elasticsearch的优势服务于多元化的企业级搜索与分析需求。对于广大开发者和数据工程师而言,紧跟Elasticsearch的最新发展趋势,灵活运用各种查询方式,将有助于提升系统的整体性能和用户体验。
2023-12-03 22:57:33
46
笑傲江湖_t
转载文章
...inux系统中的一种计划任务调度工具,允许用户按照预设的时间间隔或特定时间点执行指定的命令或脚本。通过编辑crontab文件,用户可以灵活地安排各种周期性任务,例如系统日志清理、数据备份、应用程序更新等。每个系统用户都可以拥有独立的crontab任务列表,确保操作系统的自动化运维和管理。 LVM逻辑卷管理 , LVM(Logical Volume Manager)是Linux下的一种磁盘存储管理技术,通过将物理硬盘分区转换为逻辑卷,提供了一个更为灵活和动态的磁盘空间管理方案。LVM能够实现卷组的创建、扩展和缩减,以及逻辑卷的移动、快照和克隆等功能,无需关心底层物理存储的具体细节,极大地提高了存储资源的利用率和管理效率。在Linux环境中,当需要调整分区大小或重新分配存储空间时,LVM提供了比传统分区方式更为方便的操作手段。
2023-02-08 09:55:12
291
转载
Mongo
...cript函数,用于执行复杂的聚合操作,这些函数可以在$function操作符中被调用,以满足特定的数据处理需求。 $lookup , MongoDB的聚合操作符,用于在两个集合之间执行内连接,常用于关联查询或数据合并,有助于在数据处理过程中获取额外的相关信息。 $unwind , 用于展开嵌套文档数组,使得每个数组元素被视为单独的文档,便于后续的聚合操作。 $group , 聚合框架中的一个关键操作,用于将文档分组,并对每个组应用聚合函数,如计数、求和、平均等。 $sort , 用于对结果文档进行排序,可以根据指定字段的值进行升序或降序排列。 $limit , 限制聚合结果的数量,通常用于获取满足条件的前n条记录。 $explain , MongoDB提供的命令,用于查看聚合查询的执行计划,帮助开发者理解性能瓶颈和优化策略。
2024-04-01 11:05:04
139
时光倒流
Apache Solr
...文件大小控制以及增加物理内存等基础解决方案外,最新版本的Solr提供了更为精细和智能的内存管理机制。 例如,在Solr 8.x版本中引入了全新的内存分析工具,可以实时监控并可视化Java堆内存的使用情况,帮助用户更准确地定位内存瓶颈,并根据实际业务负载进行动态调整。此外,针对大规模分布式部署环境,Solr还支持在各个节点之间均衡内存资源,避免局部节点内存溢出的问题。 同时,社区及各大云服务商也持续推出针对Solr性能优化的实践指导和案例分享。例如,阿里云在其官方博客上就曾发布过一篇深度解析文章,详细介绍了如何结合Zookeeper配置、分片策略以及冷热数据分离等手段,实现Solr集群的高效内存利用和整体性能提升。 因此,对于正在或计划使用Apache Solr构建复杂搜索服务的用户来说,关注相关领域的最新研究进展和技术实践,将有助于更好地应对“java.lang.OutOfMemoryError: Java heap space”这类内存问题,从而确保系统的稳定性和用户体验。
2023-04-07 18:47:53
453
凌波微步-t
Impala
...在系统内存中。当用户执行与缓存分片相关的查询时,Impala可以从内存直接读取部分或全部所需数据,从而减少不必要的磁盘读取操作,提升查询效率。 Apache Impala , Apache Impala是一个开源、高性能的MPP(大规模并行处理)SQL查询引擎,专为Hadoop和云环境设计,支持实时查询分析海量数据。Impala通过集成内存计算、智能缓存策略以及优化查询执行计划等功能,能够在HDFS和HBase等大数据存储平台上实现亚秒级查询响应,极大提升了大数据分析的实时性和效率。
2023-07-22 12:33:17
550
晚秋落叶-t
Apache Atlas
...下,系统会终止程序的执行,以防止更多的资源被消耗。 在Apache Atlas中,内存溢出通常是由于元数据库(如HBase)加载过多的数据导致的。这是因为每当数据库里有新的元数据项加入时,Atlas就像个勤劳的小助手,会麻利地把这些新数据加载进来,以便更好地应对接下来的各项操作任务。如果数据库里的元数据项实在是多到爆炸,那么加载这些玩意儿的时候,很可能会像饿狼扑食一样,大口大口地“吃掉”大量的内存。 3. 解决方案 为了解决这个问题,我们可以采取以下几种策略: 1) 数据清理:定期对元数据库进行清理,删除不再需要的历史数据。这样可以减少数据库中的数据量,从而降低内存消耗。 java // 示例代码,使用HBase API删除指定列族的所有行 HTable table = new HTable(conf, tableName); Delete delete = new Delete(rowKey); for (byte[] family : columnFamilies) { delete.addFamily(family); } table.delete(delete); 2) 数据分片:将元数据数据库分成多个部分,然后分别在不同的服务器上存储。这样一来,每台服务器只需要分担一小部分数据的处理工作,就完全能够巧妙地避开那种因为数据量太大,内存承受不住,像杯子装满水会溢出来一样的尴尬情况啦。 java // 示例代码,使用HBase API创建新的表,并设置表的分片策略 TableName tableName = TableName.valueOf("my_table"); HColumnDescriptor columnDesc = new HColumnDescriptor("info"); HRegionInfo regionInfo = new HRegionInfo(tableName, null, null, false); table = TEST_UTIL.createLocalHTable(regionInfo, columnDesc); table.setSplitPolicy(new MySplitPolicy()); 3) 使用外部缓存:对于那些频繁访问但不经常更新的元数据项,可以将其存储在一个独立的缓存中。这样,即使缓存中的数据量很大,也不会对主服务器的内存产生太大的压力。 java // 示例代码,使用Memcached作为外部缓存 MemcachedClient client = new MemcachedClient( new TCPNonblockingServerSocketFactory(), new InetSocketAddress[] {new InetSocketAddress(host, port)}); client.set(key, expirationTimeInMilliseconds, value); 这些只是一些基本的解决方案,具体的实施方式还需要根据你的实际情况进行调整。总的来说,想要搞定Apache Atlas服务器启动时那个烦人的内存溢出问题,咱们得在设计和运维这两块儿阶段都得提前做好周全的打算和精心的布局。 4. 结语 在使用Apache Atlas进行元数据管理时,我们可能会遇到各种各样的问题。但是,只要我们有足够的知识和经验,总能找到解决问题的方法。希望这篇文章能对你有所帮助。
2023-02-23 21:56:44
521
素颜如水-t
PostgreSQL
...使用不当,导致SQL执行效率低下:PostgreSQL实战解析 在数据库管理领域,PostgreSQL凭借其强大的功能和稳定性赢得了众多开发者和企业的青睐。不过,在实际操作的时候,我们偶尔会碰到这种情况:即使已经启用了SQL优化工具,查询速度还是没法让人满意,感觉有点儿不尽人意。本文要带你踏上一段趣味横生的旅程,我们会通过一系列鲜活的例子,手把手教你如何巧妙地运用SQL优化工具,从而在PostgreSQL这个大家伙里头,成功躲开那些拖慢数据库效率的低效SQL问题。 1. SQL优化工具的作用与问题引入 SQL优化工具通常可以帮助我们分析SQL语句的执行计划、索引使用情况以及潜在的资源消耗等,以便于我们对SQL进行优化改进。在实际操作中,如果咱们对这些工具的认识和运用不够熟练精通的话,那可能会出现“优化”不成,反而帮了倒忙的情况,让SQL的执行效率不升反降。 例如,假设我们在一个包含数百万条记录的orders表中查找特定用户的订单: sql -- 不恰当的SQL示例 SELECT FROM orders WHERE user_id = 'some_user'; 虽然可能有针对user_id的索引,但如果直接运行此查询并依赖优化工具盲目添加或调整索引,而不考虑查询的具体内容(如全表扫描),可能会导致SQL执行效率下降。 2. 理解PostgreSQL的查询规划器与执行计划 在PostgreSQL中,查询规划器负责生成最优的执行计划。要是我们没找准时机,灵活运用那些SQL优化神器,那么这个规划器小家伙,可能就会“迷路”,选了一条并非最优的执行路线。比如,对于上述例子,更好的方式是只选择需要的列而非全部: sql -- 更优的SQL示例 SELECT order_id, order_date FROM orders WHERE user_id = 'some_user'; 同时,结合EXPLAIN命令查看执行计划: sql EXPLAIN SELECT order_id, order_date FROM orders WHERE user_id = 'some_user'; 这样,我们可以清晰地了解查询是如何执行的,包括是否有效利用了索引。 3. 错误使用索引优化工具的案例分析 有时候,我们可能过于依赖SQL优化工具推荐的索引创建策略。例如,工具可能会建议为每个经常出现在WHERE子句中的字段创建索引。但这样做并不总是有益的,尤其是当涉及多列查询或者数据分布不均匀时。 sql -- 错误的索引创建示例 CREATE INDEX idx_orders_user ON orders (user_id); 如果user_id字段值分布非常均匀,新创建的索引可能不会带来显著性能提升。相反,综合考虑查询模式创建复合索引可能会更有效: sql -- 更合适的复合索引创建示例 CREATE INDEX idx_orders_user_order_date ON orders (user_id, order_date); 4. 结论与反思 面对SQL执行效率低下,我们需要深度理解SQL优化工具背后的原理,并结合具体业务场景进行细致分析。只有这样,才能避免因为工具使用不当而带来的负面影响。所以呢,与其稀里糊涂地全靠自动化工具,咱们还不如踏踏实实地去深入了解数据库内部是怎么运转的,既要明白表面现象,更要摸透背后的原理。这样一来,咱就能更接地气、更靠谱地制定出高效的SQL优化方案了。 总之,在PostgreSQL的世界里,SQL优化并非一蹴而就的事情,它要求我们具备严谨的逻辑思维、深入的技术洞察以及灵活应变的能力。让我们在实践中不断学习、思考和探索,共同提升PostgreSQL的SQL执行效率吧! 注:全表扫描在数据量巨大时往往意味着较低的查询效率,尤其当仅需少量数据时。
2023-09-28 21:06:07
263
冬日暖阳
Kibana
...缓存机制以及对分布式执行计划的精细控制,这些都将有助于改善Discover页面的数据加载速度。 同时,Kibana也在其最新的8.x系列中引入了智能采样功能,该功能可以在不影响分析结果的前提下,大幅度减少需要从Elasticsearch检索的数据量,对于处理大规模数据时显著提升Discover页面的响应速度。此外,官方文档提供了详尽的调优指南和最佳实践,建议用户结合实际场景进行深入学习和应用。 值得一提的是,在实际运维过程中,除了软件层面的优化,硬件配置和网络环境同样对Elasticsearch集群性能有直接影响。例如,采用SSD存储而非HDD可以有效缩短I/O延迟,而部署在低延迟、高带宽的网络环境下,则能够降低网络传输对查询响应时间的影响。 综上所述,持续关注技术发展动态并结合实际情况采取多维度优化策略,是确保Kibana Discover页面高效加载数据、提升大数据分析体验的重要手段。而对于企业级用户而言,借助专业服务团队进行深度调优与架构设计,将更好地应对复杂业务场景下的性能挑战。
2023-08-21 15:24:10
298
醉卧沙场
站内搜索
用于搜索本网站内部文章,支持栏目切换。
知识学习
实践的时候请根据实际情况谨慎操作。
随机学习一条linux命令:
uniq file.txt
- 移除连续重复行。
推荐内容
推荐本栏目内的其它文章,看看还有哪些文章让你感兴趣。
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
历史内容
快速导航到对应月份的历史文章列表。
随便看看
拉到页底了吧,随便看看还有哪些文章你可能感兴趣。
时光飞逝
"流光容易把人抛,红了樱桃,绿了芭蕉。"