前端技术
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
[执行计划]的搜索结果
这里是文章列表。热门标签的颜色随机变换,标签颜色没有特殊含义。
点击某个标签可搜索标签相关的文章。
点击某个标签可搜索标签相关的文章。
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
MySQL
...SQL如何利用索引、执行计划等资源,进一步提升查询性能。 此外,针对大数据时代下的海量数据处理需求,许多企业开始采用分布式数据库架构,如Google Spanner、Amazon Aurora等,这些系统在设计之初就充分考虑了大规模数据统计查询的效率问题,通过分片、并行计算等技术手段显著提升了COUNT等聚合操作的响应速度。 同时,业界专家也强调了数据库设计阶段的重要性,提倡合理规划表结构与索引策略,例如避免NULL值过多、选择适合的数据类型以及适时进行数据归档清理等,这些都是提高MySQL COUNT函数性能不可或缺的基础工作。 综上所述,对于MySQL COUNT函数性能优化的探索不仅停留在函数本身的使用技巧层面,更需要结合最新的数据库技术发展动态、深入理解数据库底层原理,并在实践中灵活运用以应对日益增长的数据处理挑战。
2023-12-14 12:55:14
46
星河万里_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
繁华落尽
Spark
...机会,包括列式存储、执行计划优化以及与SQL引擎的无缝集成,使得数据处理过程更加高效和便捷。 Partitioner , 在Apache Spark中,Partitioner是一个用于决定如何将数据集划分为多个分区的策略。它在数据并行处理时起到关键作用,确保数据能够在集群节点间均衡分布,提高任务执行效率。当处理大量小文件时,可以通过自定义Partitioner来按照某种规则将小文件整合或分类,从而减少I/O开销,提升整体性能。 DataSource V2 , DataSource V2是Apache Spark 3.0版本引入的新接口,旨在提供更灵活、高效的读写数据源方式。它允许开发者实现更细粒度的数据分区和读取策略,尤其适用于处理大量小文件场景,可以降低磁盘I/O次数,提高数据读取速度,进而优化Spark的整体性能。 动态资源分配 , 动态资源分配是Apache Spark的一项资源管理特性,可根据当前作业负载动态调整各个Spark应用程序所占用的集群资源(如CPU核心数、内存大小等)。在处理大量小文件等复杂工作负载时,合理运用动态资源分配策略有助于提高系统资源利用率和作业执行效率。
2023-09-19 23:31:34
45
清风徐来-t
Impala
...足够的内存来缓存查询计划和执行状态,同时存储中间结果。内存的大小直接影响到并行度和缓存效果,进而影响查询性能。 - CPU:CPU的计算能力决定了查询执行的速度,尤其是在多线程环境下。合理的CPU分配可以显著提升查询速度。 - 网络:数据存储和计算之间的网络延迟也会影响查询性能,尤其是在分布式环境中。优化网络配置可以减少数据传输时间。 2. 实例代码 配置与优化 接下来,我们通过一段简单的代码实例,展示如何通过配置和优化来提升Impala的查询性能。 示例代码:查询性能调优配置 python 假设我们正在使用Cloudera Manager进行配置管理 调整Impala节点的内存配置 cloudera_manager.set_impala_config('memory', { 'query_mem_limit': '2GB', 根据实际需求调整查询内存限制 'coordinator_memory_limit': '16GB', 协调器的最大内存限制 'executor_memory_limit': '16GB' 执行器的最大内存限制 }) 调整CPU配额 cloudera_manager.set_impala_config('cpu', { 'max_threads_per_node': 8, 每个节点允许的最大线程数 'max_threads_per_core': 2 每个核心允许的最大线程数 }) 开启并行查询功能 cloudera_manager.set_impala_config('parallelism', { 'default_parallelism': 'auto' 自动选择最佳并行度 }) 运行查询前,确保表数据更新已同步到Impala cloudera_manager.refresh_table('your_table_name') cloudera_manager.compute_stats('your_table_name') print("配置已更新,查询性能调优已完成。") 这段代码展示了如何通过Cloudera Manager调整Impala节点的内存限制、CPU配额以及开启自动并行查询功能。通过这样的配置,我们可以针对特定的查询场景和数据集进行优化,提高查询性能。 3. 性能监控与诊断 为了确保硬件配置达到最佳状态,持续的性能监控和诊断至关重要。利用Impala自带的诊断工具,如Explain Plan和Profile,可以帮助我们深入了解查询执行的详细信息,包括但不限于执行计划、CPU和内存使用情况、I/O操作等。 Examine Plan 示例 bash 使用Explain Plan分析查询执行计划 impala-shell> EXPLAIN SELECT FROM your_table WHERE column = 'value'; 输出的结果将展示查询的执行计划,帮助识别瓶颈所在,为后续的优化提供依据。 4. 结语 Impala的查询性能与硬件配置息息相关,合理的配置不仅能提升查询效率,还能优化资源利用,降低运行成本。通过本文的探讨和示例代码的展示,希望能够激发读者对Impala性能优化的兴趣,并鼓励大家在实践中不断探索和尝试,以实现大数据分析的最佳效能。嘿,兄弟!你得明白,真正的硬仗可不只在找答案,而是在于找到那个对特定工作环境最合适的平衡点。这事儿啊,一半靠的是技巧,另一半还得靠点智慧。就像调鸡尾酒一样,你得知道加多少冰,放什么酒,才能调出那个完美的味道。所以,别急着去死记硬背那些公式和规则,多琢磨琢磨,多试试错,慢慢你会发现,找到那个平衡点,其实挺像在创作一首诗,又像是在解一道谜题。
2024-08-19 16:08:50
71
晚秋落叶
转载文章
...在服务类的方法上定义执行计划。这种方式不仅简化了配置流程,而且增强了代码的可读性和维护性。 另外,针对大规模分布式系统中的定时任务调度,Apache Eagle和Apollo等开源项目也提供了强大的解决方案。例如,Apollo拥有丰富的定时任务调度策略以及灵活的分片、依赖处理机制,能够有效应对高并发场景下的定时任务管理需求。 与此同时,云原生环境下的Kubernetes CronJob也是一个值得关注的方向。CronJob作为Kubernetes的一部分,可以根据Cron表达式在集群中调度容器化的定时任务,实现了与容器编排平台的高度集成。 此外,在深入研究定时任务原理时,可以追溯到操作系统级别的定时器和调度算法,如Linux系统的timerfd和POSIX信号定时器机制,这些底层技术为上层应用提供精确且高效的定时服务。 总之,随着技术的演进与发展,Java定时任务的实现方式日趋丰富多样,开发者应根据实际应用场景选择最适合的技术方案,同时关注社区前沿动态,以确保所采用的定时任务技术始终与时俱进。
2023-10-27 18:50:19
344
转载
转载文章
... 分析查询语句,生成执行计划 多个数据节点(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
转载
Java
...运行流。线程的启动和执行需要实现可运行接口或派生线程类。 // 实现可运行接口 class MyRunnable implements Runnable { public void run() { // 执行线程的代码 } } // 启动线程 Thread thread = new Thread(new MyRunnable()); thread.start(); 其中,线程的执行代码需要在run()函数中实现。通过实现可运行接口,创建一个线程对象,并调用start()函数来启动线程。 // 派生线程类 class MyThread extends Thread { public void run() { // 执行线程的代码 } } // 启动线程 MyThread thread = new MyThread(); thread.start(); 派生线程类来实现线程,需要重写run()函数,并在函数内部实现线程的执行代码。创建一个线程对象,并调用start()函数来启动线程。 在启动多个线程时,需要注意线程的调度和同步问题,避免出现资源竞争的现象。
2024-04-10 16:02:45
375
码农
Python
...项,还支持分布式任务执行和异常处理机制。用户可以通过schedule-ext更便捷地管理复杂的定时任务流程,实现多线程并行执行以及失败重试等功能。 与此同时,对于需要更高精度和稳定性的企业级场景,可考虑使用APScheduler库。该库除了支持基本的定时任务外,还具备cron风格的表达式调度,并且兼容多种后台运行模式,如配合Celery进行异步任务队列管理或结合Django等框架实现Web环境下的定时任务调度。 此外,深入探究Python定时任务的实际运用案例,例如NASA就利用Python定时任务技术对其空间站的数据采集系统进行定期维护与更新。通过灵活设定每日、每周甚至每月的任务计划,确保了系统能够按照预设时间点准确无误地完成数据同步及分析工作。 综上所述,在Python中实现高效稳定的定时任务方案,既可以借助如schedule这样的轻量级工具快速搭建原型,也可以根据实际需求选用更为强大的调度库如schedule-ext或APScheduler,从而在不同的业务场景下发挥关键作用。同时,众多现实应用的成功案例也证明了Python定时任务功能在各行业自动化流程中的重要价值。
2023-01-01 19:28:30
351
软件工程师
HTML
...一些预先设定的公式来执行计算。 <!-- 数学运算 --> <p>计算圆的圆周:C = 2πr</p> 在上面的程序内,我们运用了圆的圆周公式来呈现如何在 HTML 中计算公式。其中,“π”是一个已经预先设定好的数学标记,我们可以直接在程序内运用它。 <!-- 数学运算 --> <p>计算正方形的面积大小:A = a²</p> 同样地,在上面的程序内,我们运用了正方形面积大小的公式来执行计算。其中,“²”也是一个已经预先设定好的数学标记,它表示的是平方。 除了这些预先设定的数学标记之外,我们还可以运用一些特殊的代码来执行更加复杂的计算。例如,在下面的例子中,我们运用了一些特殊的代码来计算三角形的面积大小: <!-- 数学运算 --> <p>计算三角形的面积大小:A = ½bh</p> 在上面的程序内,“½”就是一个特殊的代码,表示的是除以二。同理,我们还可以运用“⅓”、“¼”等等来执行更加复杂的计算。 总之,数学运算在 HTML 中是非常重要的。借助运用预先设定的数学标记和特殊的代码,我们可以方便地执行复杂的计算,从而更加简便地创作出高质量的网页。
2023-04-01 16:00:57
321
电脑达人
VUE
...通过VS Code来执行Vue项目的配置、测试和打包等操作。此外,在使用Vue执行组件化开发时,VS Code也可以帮助我们更加方便地管理组件的代码。 export default { name: 'MyButton', data () { return { count: 0 } }, methods: { handleClick () { this.count++ } } } 综上所述,Vue和VS Code在前端开发中都扮演着关键的角色。Vue作为一个广泛使用的JavaScript结构,具有可塑性和延展性;而VS Code则是一个功能强劲的轻量级编辑器,具有丰富的插件和插件。在使用Vue执行开发时,VS Code可以提供许多方便的功能和软件,帮助我们更加方便地管理和编写Vue代码。因此,Vue和VS Code的结合是前端开发中必不可少的一部分。
2023-10-18 12:42:49
93
码农
NodeJS
...浏览器对于同源策略的执行更为严格。例如,Chrome浏览器计划逐步淘汰不安全的CORS机制,并提倡使用更安全的CORB(Cross-Origin Read Blocking)机制来防止恶意跨站数据泄露。 同时,针对API服务器的安全设计,越来越多开发者开始采用“细粒度”的跨域控制策略,比如根据请求来源、HTTP方法或者特定的自定义头部信息动态配置CORS规则。此外,配合OAuth 2.0、JWT等现代身份验证机制,可以更好地确保跨域访问过程中的安全性。 另一方面,对于开发框架如Express的新版本,也在持续优化和完善对CORS的支持。例如,在最新的Express文档中,详尽介绍了如何根据实际项目需求定制cors中间件的配置项,以适应各类复杂的跨域场景。 因此,开发者在实际项目中不仅要掌握如何快速解决跨域问题,还需关注行业动态和技术规范,确保所采用的解决方案既满足业务需求,又能符合日益严苛的安全标准。不断跟进学习并更新跨域处理策略,是保障Web服务高效稳定运行的关键所在。
2023-06-11 14:13:21
96
飞鸟与鱼-t
AngularJS
...似问题的开发者,还是计划迁移至Angular平台的团队,深入理解Angular的变更检测机制及其优化手段都显得至关重要。这不仅能确保应用程序的流畅性和用户体验,也能有效提升开发效率与代码质量。随着前端技术的不断演进,与时俱进地掌握框架特性已成为开发者持续精进的必修课。
2023-05-13 23:52:26
406
清风徐来
MySQL
...览和编辑信息、编写和执行SQL查询,以及管理用户帐户和权限等功能。同时,MySQL Manager 还支持信息备份和恢复、信息导入和导出等重要功能。 总结 移动MySQL管理软件可以帮助开发者在移动设备上操作和管理MySQL信息库,提高了信息管理的效率。在当代的移动化时代,这些软件无疑为开发者提供了更多选择,同时提高了团队的协作效率。
2024-01-03 20:49:40
142
数据库专家
Kibana
...格式,用于配置周期性执行的任务计划。在 Kibana 中设置 Cron Schedule 可以实现自动化报告按预设的时间间隔(如每小时、每天或每周)自动生成并更新。例如,“ ”表示每小时运行一次,即每隔一小时生成新的报告。
2023-07-18 21:32:08
302
昨夜星辰昨夜风-t
PHP
...全特性,使得开发者在执行SQL查询时能够更好地预防SQL注入等安全风险。 此外,数据库最佳实践也建议采用预编译语句( Prepared Statements)以提高查询效率并确保数据安全性。通过预编译,不仅可以有效防止SQL注入攻击,还能利用数据库缓存查询计划,从而加快后续同样结构查询的速度。 另外,针对数据库权限管理,应遵循最小权限原则,即为应用程序分配仅够完成其功能所需的最低限度数据库权限,以此降低因权限过高导致的数据泄露或破坏的风险。 总之,在实际项目开发中,除了掌握解决SQLQueryException的基本方法,还需紧跟技术发展动态,运用最新的安全策略和技术手段优化数据库操作,才能使项目在保证稳定性的前提下,实现更高的安全性与性能表现。
2023-05-04 22:50:29
88
月影清风-t
Hadoop
...化频率,自动调整备份计划,既能降低不必要的备份成本,又能确保关键数据得到及时有效的保护。 综上所述,在实际应用中,我们需要紧跟技术发展趋势,结合自身业务需求,不断优化和完善Hadoop及其他大数据处理框架中的数据备份与恢复方案,以应对日益复杂的大数据挑战。
2023-09-08 08:01:47
400
时光倒流-t
PostgreSQL
...让代码看起来更简洁,执行起来也更高效。今天我碰到了一个难题:怎么把两条SQL语句合二为一呢?本来以为挺简单的,结果发现里面有不少门道呢。接下来,让我们一起探讨如何通过一些巧妙的方法来解决这个问题。 2. 场景设定 假设我们有一个数据库,里面有两个表:employees 和 departments。employees 表记录了员工的信息,而 departments 表则记录了部门的信息。两个表之间的关系是通过 department_id 这个外键关联起来的。 表结构如下: - employees - id (INT, 主键) - name (VARCHAR) - department_id (INT, 外键) - departments - id (INT, 主键) - name (VARCHAR) 现在我们需要查询出所有员工的姓名以及他们所在的部门名称。按常规思维,我们会写出如下的两行SQL: sql SELECT e.name AS employee_name, d.name AS department_name FROM employees e JOIN departments d ON e.department_id = d.id; SELECT e.name AS employee_name, d.name AS department_name FROM employees e LEFT JOIN departments d ON e.department_id = d.id; 3. 合并思路 合并这两句SQL的初衷是为了减少数据库查询的次数,提高效率。那么,我们该如何做呢? 3.1 使用 UNION ALL 一个简单的思路是使用 UNION ALL 来合并这两条SQL语句。不过要注意,UNION ALL会把结果集拼在一起,但不会把重复的东西去掉。因此,我们可以先尝试这种方法: sql SELECT e.name AS employee_name, d.name AS department_name FROM employees e JOIN departments d ON e.department_id = d.id UNION ALL SELECT e.name AS employee_name, d.name AS department_name FROM employees e LEFT JOIN departments d ON e.department_id = d.id; 但是,这种方法可能会导致数据重复,因为 JOIN 和 LEFT JOIN 的结果集可能有重叠部分。所以,这并不是最优解。 3.2 使用条件判断 另一种方法是利用条件判断来处理 LEFT JOIN 的情况。你可以把 LEFT JOIN 的结果想象成一个备用值,当 JOIN 找不到匹配项时就用这个备用值。这样可以避免数据重复,同时也能达到合并的效果。 sql SELECT e.name AS employee_name, COALESCE(d.name, 'Unknown') AS department_name FROM employees e LEFT JOIN departments d ON e.department_id = d.id; 这里使用了 COALESCE 函数,当 d.name 为空时(即没有匹配到部门),返回 'Unknown'。这样就能保证所有的员工都有部门信息,即使该部门不存在。 3.3 使用 CASE WHEN 如果我们想在某些情况下返回不同的结果,可以考虑使用 CASE WHEN 语句。例如,如果某个员工的部门不存在,我们可以显示特定的提示信息: sql SELECT e.name AS employee_name, CASE WHEN d.id IS NULL THEN 'No Department' ELSE d.name END AS department_name FROM employees e LEFT JOIN departments d ON e.department_id = d.id; 这样,当 d.id 为 NULL 时,我们就可以知道该员工没有对应的部门信息,并显示相应的提示。 4. 总结与反思 通过上述几种方法,我们可以看到,合并SQL语句其实有很多方式。每种方式都有其适用场景和优缺点。在实际应用中,我们应该根据具体需求选择最合适的方法。这些招数不光让代码更好懂、跑得更快,还把我们的SQL技能磨得更锋利了呢! 在学习过程中,我发现,SQL不仅仅是机械地编写代码,更是一种逻辑思维的体现。每一次优化和改进都是一次对问题本质的深刻理解。希望这篇文章能帮助你更好地理解和掌握SQL语句的合并技巧,让你在数据库操作中更加游刃有余。
2025-03-06 16:20:34
54
林中小径_
Shell
...hell,它是GNU计划的一部分,基于Bourne shell发展而来,提供了更加强大且丰富的功能。作为命令行解释器,用户可以通过bash shell输入并执行各种命令和脚本来操作计算机系统,包括文件管理、程序运行、环境变量设置、脚本编程等任务。在本文推荐的学习资源中,《Learn the bash shell》是一本专门针对bash shell的入门书籍。
2023-08-08 22:29:15
82
冬日暖阳_t
转载文章
...werShell 来执行特定的命令以开启 Windows 10 的“卓越性能”模式。 GUID(全局唯一标识符) , 全局唯一标识符是一种由算法生成的长度固定、格式确定、保证全球唯一的字符串型标识符。在文章中提到的“电源方案 GUID”,指的是操作系统内部用于区分不同电源计划的独特标识,例如。 “卓越性能”模式 , 这是Windows 10操作系统中的一项高级电源管理模式,专为高性能硬件配置和专业应用场景设计,如企业版和工作站版用户。该模式旨在优化系统资源调度,减少不必要的后台活动,从而最大化提升处理器、内存和存储设备等硬件组件的性能表现,尤其适用于处理大量数据、进行复杂计算或运行高性能软件的专业场景。普通家庭版、商用版、专业版或教育版用户默认情况下无法看到此模式选项,但可通过特定命令开启。
2023-06-26 12:46:08
385
转载
Kotlin
...对集合中的每一个元素执行指定的操作。想象一下,当你有一堆数据需要逐一处理时,forEach就像是你的专属助手,帮你轻松搞定! 2. 如何使用forEach? 先别急着动手,让我们先来理清思路。首先,要想用forEach,你得有个集合对象,比如列表(List)、数组(Array)或者任何其他能遍历的东西。接着,你可以在调用那个对象的forEach方法时,给它传一个lambda表达式,这样就能指定你要对每个元素做啥操作了。 示例代码: kotlin val numbers = listOf(1, 2, 3, 4, 5) numbers.forEach { println(it) // 输出: 1 2 3 4 5 } 在这个例子中,我们创建了一个包含五个整数的列表numbers,然后使用forEach遍历了这个列表,并打印出了每个数字。是不是很简单呢?感觉就像在说:“嘿,老兄,把这些数字挨个儿念一遍!” 3. forEach与索引的结合 有时候,光知道当前处理的元素还不够,我们还想知道它在集合中的位置。这时候,就需要稍微修改一下我们的lambda表达式了。我们可以使用forEachIndexed方法,这样就可以同时获取到元素及其对应的索引值。 示例代码: kotlin val names = listOf("Alice", "Bob", "Charlie") names.forEachIndexed { index, name -> println("第 $index 个人的名字是 $name") // 输出: 第 0 个人的名字是 Alice 第 1 个人的名字是 Bob 第 2 个人的名字是 Charlie } 在这个例子中,我们使用了forEachIndexed,并在lambda表达式中添加了两个参数:index(索引)和name(元素)。这样我们就能在输出的时候不仅显示名字,还能显示它的位置啦!是不是觉得挺酷的? 4. 处理更复杂的情况 当然,实际开发中你可能会遇到更复杂的需求。比如,你想要挑出符合特定条件的元素,或者在查看每个项目时做一些决定。这个时候,forEach可能就显得有点力不从心了。不过不用担心,Kotlin还有其他强大的工具可以帮到你,比如filter、map等。 示例代码: kotlin val numbers = listOf(1, 2, 3, 4, 5) val evenNumbers = mutableListOf() numbers.forEach { if (it % 2 == 0) { evenNumbers.add(it) } } println(evenNumbers) // 输出: [2, 4] 在这个例子中,我们想找出所有偶数。所以我们建了个空的evenNumbers列表,在循环里挨个儿检查,看看哪个是偶数。如果是偶数,我们就把它添加到evenNumbers列表中。最后,我们打印出了结果,看到了所有的偶数都被正确地找出来了。 5. 总结 好了,小伙伴们,今天的内容就到这里啦!forEach确实是一个非常强大的工具,可以帮助我们轻松地处理集合中的每一个元素。无论你是初学者还是有一定经验的开发者,都能从中受益匪浅。希望今天的分享能让你对forEach有更深的理解,也期待你在未来的项目中能够灵活运用它。如果你有任何问题或想法,欢迎随时交流哦!
2025-02-13 16:29:29
65
诗和远方
DorisDB
...要性,并提倡在设计和执行升级计划时应充分考虑这些核心原则。 综上所述,无论是从最新的技术更新、业界最佳实践,还是理论层面的深入探讨,都为我们理解和解决DorisDB系统升级失败或稳定性问题提供了丰富的参考依据和实用建议。随着大数据处理需求的增长和技术的持续迭代,对DorisDB这类分布式数据库系统的升级管理能力将成为衡量企业IT运维水平的重要指标之一。
2023-06-21 21:24:48
384
蝶舞花间
站内搜索
用于搜索本网站内部文章,支持栏目切换。
知识学习
实践的时候请根据实际情况谨慎操作。
随机学习一条linux命令:
sort -nr 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
历史内容
快速导航到对应月份的历史文章列表。
随便看看
拉到页底了吧,随便看看还有哪些文章你可能感兴趣。
时光飞逝
"流光容易把人抛,红了樱桃,绿了芭蕉。"