前端技术
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
[pg_stat_user_indexes...]的搜索结果
这里是文章列表。热门标签的颜色随机变换,标签颜色没有特殊含义。
点击某个标签可搜索标签相关的文章。
点击某个标签可搜索标签相关的文章。
Docker
...况下其用户的uid(User ID)被设置为999。你可能心里正犯嘀咕,为啥我们偏偏对这个数字情有独钟,而不是其他的呢?在这篇文里,咱们就一起手拉手,像解密探险一样揭开这个谜团吧!我会带着大伙儿,通过实实在在的例子和深入的讨论,来摸清楚这背后究竟藏着啥讲究。 1. Docker容器与用户权限 首先,让我们简要回顾一下Docker容器内的用户权限模型。你知道吗,Docker那个小家伙,默认情况下启动容器时,会直接动用到root大权限,这在安全性和隔离性方面,可不是什么顶呱呱的优秀操作。为了让大家用得更安心,我常常建议这样做:别让你在容器里运行的应用权限太高了,最好能把它们映射到宿主机上的普通用户级别,这样一来就更加安全啦。就像是让这些应用从VIP房间搬到了经济舱,虽然待遇没那么高,但是安全性却大大提升,避免惹出什么乱子来。这就引出了uid的概念——它是Unix/Linux系统中标识用户身份的重要标识符。 2. 默认uid的选择 999的秘密 那么,为什么许多Docker官方或社区制作的镜像倾向于将应用运行时的用户uid设为999呢?答案其实并不复杂: - 避免冲突:在大多数Linux发行版中,系统用户的uid从100开始分配给普通用户,因此选取大于100但又不是特别大的数字(如999),可以最大程度地减少与宿主机现有用户的uid冲突的可能性。 - 保留空间:选择一个高于常规uid范围的值,确保了不会意外覆盖宿主机上的任何重要用户账号。 - 一致性与约定俗成:随着时间推移,选用999作为非root用户的uid逐渐成为一种行业惯例和最佳实践,尤其是在创建需要低权限运行的应用程序镜像时。 3. 实践示例 自定义uid的Dockerfile 下面是一个简单的Dockerfile片段,展示如何在构建镜像时创建并使用uid为999的用户: dockerfile 首先,基于某个基础镜像 FROM ubuntu:latest 创建一个新的系统用户,指定uid为999 RUN groupadd --gid 999 appuser && \ useradd --system --uid 999 --gid appuser appuser 设置工作目录,并确保所有权归新创建的appuser所有 WORKDIR /app RUN chown -R appuser:appuser /app 以后的所有操作均以appuser身份执行 USER appuser 示例安装和运行一个应用程序 RUN npm install 假设我们要运行一个Node.js应用 CMD ["node", "index.js"] 在这个例子中,我们创建了一个名为appuser的新用户,其uid和gid都被设置为999。然后呢,咱就把容器里面的那个 /app 工作目录的所有权,给归到该用户名下啦。这样一来,应用在跑起来的时候,就能够顺利地打开、编辑和保存文件,不会因为权限问题卡壳。 4. 深入思考 uid映射与安全策略 虽然999是一个常见选项,但它并不是硬性规定。实际上,根据具体的部署环境和安全需求,你可以灵活调整uid。比如,在某些情况下,可能需要把容器里面的用户uid,对应到宿主机上的某个特定用户,这样一来,我们就能对文件系统的权限进行更精准的调控了,就像拿着钥匙开锁那样,该谁访问就给谁访问的权利。这时,可以通过Docker的--user参数或者在Dockerfile中定义用户来实现uid的精确映射。 总而言之,Docker容器中用户uid为999这一现象,体现了开发者们在追求安全、便捷和兼容性之间所做的权衡和智慧。随着我们对容器技术的领悟越来越透彻,这些原则就能被我们玩转得更加游刃有余,随时适应各种实际场景下的需求变化,就像是给不同的应用场景穿上量身定制的衣服一样。而这一切的背后,都离不开我们持续的探索、试错和优化的过程。
2023-05-11 13:05:22
463
秋水共长天一色_
Impala
...ATE TABLE users ( user_id INT, name STRING, email VARCHAR(255) ); 对于用户名称和电子邮件地址这种信息,我们可以使用 STRING 类型。如果知道字段的最大长度,推荐使用 VARCHAR,这样可以节省一些存储空间。 3.4 日期时间的选择 示例代码: sql CREATE TABLE orders ( order_id INT, order_date TIMESTAMP, delivery_date TIMESTAMP ); 在处理订单日期和交货日期这样的信息时,TIMESTAMP 类型是最直接的选择。这个不仅能存日期,还能带上具体的时间,特别适合用来做时间上的研究和分析。 3.5 布尔型的选择 示例代码: sql CREATE TABLE active_users ( user_id INT, is_active BOOLEAN ); 如果你有一个字段需要表示某种状态是否开启(如用户账户是否激活),那么 BOOLEAN 类型就是最佳选择。它只有两种取值:TRUE 和 FALSE,非常适合用来简化逻辑判断。 4. 性能优化技巧 4.1 减少数据冗余 尽量避免不必要的数据冗余。例如,在多个表中重复存储相同的字符串数据(如用户姓名)。可以考虑使用外键或者创建一个独立的字符串存储表来减少重复数据。 4.2 使用分区表 分区表可以帮助我们更好地管理和优化大型数据集。把数据按时间戳之类的东西分个区,查询起来会快很多,特别是当你 dealing with 时间序列数据的时候。 示例代码: sql CREATE TABLE sales ( year INT, month INT, day INT, amount DECIMAL(10,2) ) PARTITION BY (year, month); 在这个例子中,我们将 sales 表按年份和月份进行了分区,这样查询某个特定时间段的数据就会变得非常高效。 4.3 使用索引 合理利用索引可以大大提高查询速度。不过,在建索引的时候得好好想想,毕竟索引会吃掉一部分存储空间,而且在往里面添加或修改数据时,还得额外花工夫去维护。 示例代码: sql CREATE INDEX idx_user_email ON users(email); 通过在 email 字段上创建索引,我们可以快速查找特定邮箱的用户记录。 5. 结论 通过本文的学习,我们了解了如何在Impala中选择合适的数据类型以及如何通过这些选择来优化查询性能。希望这些知识能够帮助你在实际工作中做出更好的决策。记住啊,选数据类型和搞性能优化这事儿,就跟学骑自行车一样,得不停地练。别害怕摔跤,每次跌倒都是长经验的好机会!祝你在这个过程中找到乐趣,享受数据带来的无限可能!
2025-01-15 15:57:58
35
夜色朦胧
MemCache
...ef update_user_info(user_id, new_info): 先更新数据库 db.update_user(user_id, new_info) 清除MemCache中相关的缓存数据 memcached_client.delete(f'user_{user_id}') 另一种策略是引入消息队列,例如使用Redis Pub/Sub或者RabbitMQ等中间件,当数据库发生变更时,发布一条消息通知所有MemCache节点删除对应的缓存项。 4. MemCache节点的维护与监控 为了保证MemCache集群的稳定运行,我们需要定期对各个节点进行健康检查和性能监控,及时发现并处理可能出现的内存溢出、节点失效等问题。可以通过编写运维脚本定期检查,或者接入诸如Prometheus+Grafana这样的监控工具进行可视化管理。 bash 示例:简单的shell脚本检查MemCache节点状态 for node in $(cat memcache_nodes.txt); do echo "Checking ${node}..." telnet $node 11211 <<< stats | grep -q 'STAT bytes 0' if [ $? -eq 0 ]; then echo "${node} is down or not responding." else echo "${node} is up and running." fi done 总的来说,要在分布式环境中有效管理和维护多个MemCache节点,并实现数据的分布式存储与同步更新,不仅需要合理设计数据分布策略,还需要在应用层面对数据一致性进行把控,同时配合完善的节点监控和运维体系,才能确保整个缓存系统的高效稳定运行。在整个探险历程中,咱们得时刻动脑筋、动手尝试、灵活应变、优化咱的计划,这绝对是一个挑战多多、趣味盎然的过程,让人乐在其中。
2023-11-14 17:08:32
69
凌波微步
转载文章
...andshake($user,$buffer){ // getheaders and calcKey are confirmed working, can provide source ... 是。 独立的WebSocket服务器通常可以在任何端口上运行。 浏览器客户端打开与非HTTP(S)端口上的服务器的WebSocket连接没有问题。 默认端口为80/443的主要原因是它们是最可靠的大规模使用端口,因为它们能够遍历阻止所有其他端口上所有流量的许多企业防火墙。 如果这对您的受众来说不是问题(或者您有基于HTTP的回退),那么为WebSocket服务器使用备用端口是完全合理的(并且更容易)。 另一种选择是使用80/443端口,但使用单独的IP地址/主机名。 Yes. A standalo ... Tyrus抱怨Connection: keep-alive, Upgrade header。 Firefox在这里没有做错任何事。 关于如何处理Connection标头,Tyrus过于严格,没有遵循WebSocket规范( RFC-6455 )。 RFC 4.1中的RFC规定: 6. The request MUST contain a |Connection| header field whose value MUST include the "Upgrade" tok ... 说实话,我不能100%确定地说这是什么,但我有一个非常强烈的怀疑。 我的代码中包含了太多的命名空间,我相信在编译器等实际运行时会出现一些混乱。 显然,Microsoft.Web.Websockets和SignalR的命名空间都包含WebSocketHandler。 虽然我不知道SignalR的所有细节,但看起来THAT命名空间中的WebSocketHandler并不意味着在SignalR之外使用。 我相信这个类正在被引用,而不是Microsoft.Web.Websockets中的那个,因为它现在起 ... 您应该使用websocket处理程序,而不是请求处理程序,尝试使用此示例 You should use the websocket handler, not the request handler, try with this example 本篇文章为转载内容。原文链接:https://blog.csdn.net/weixin_34862561/article/details/119512220。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2023-03-19 12:00:21
52
转载
转载文章
...卡住了docker stats# 查看 cpu的状态 #es 是十分耗内存的,1.xG# 1核2G(学生机)! # 查看 docker stats 2、问题2:es 需要暴露的端口很多 -p (下载)启动 elasticsearch$ docker run -d --name elasticsearch01 -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.6.2 查看内存占用情况docker stats 先感觉stop一下docker stop ba18713ca536 3、es 十分耗内存的解决:增加内存的限制,修改配置文件 -e 环境配置修改 通过 -e 限制内存docker run -d --name elasticsearch02 -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" elasticsearch:7.6.2 [root@iZwz9535z41cmgcpkm7i81Z /] curl localhost:9200/{"name" : "14329968b00f","cluster_name" : "docker-cluster","cluster_uuid" : "0iDu-G_KTo-4X8KORDj1XQ","version" : {"number" : "7.6.2","build_flavor" : "default","build_type" : "docker","build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f","build_date" : "2020-03-26T06:34:37.794943Z","build_snapshot" : false,"lucene_version" : "8.4.0","minimum_wire_compatibility_version" : "6.8.0","minimum_index_compatibility_version" : "6.0.0-beta1"},"tagline" : "You Know, for Search"} 4、思考:用kibana连接elasticsearch? 思考(kibana连接elasticsearch)网络如何连接过去 ☺ 参考来源: 狂神的B站视频《【狂神说Java】Docker最新超详细版教程通俗易懂》 https://www.bilibili.com/video/BV1og4y1q7M4 如果本文对你有帮助的话记得给一乐点个赞哦,感谢! 本篇文章为转载内容。原文链接:https://blog.csdn.net/weixin_45630258/article/details/124785912。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2023-03-12 10:54:44
65
转载
Kylin
...NNER JOIN users u ON o.user_id = u.user_id WHERE o.order_date BETWEEN '2023-01-01' AND '2023-12-31'; 七、总结与展望 通过上述策略的实施,我们能够显著提升Kylin与MySQL联接操作的性能。哎呀,你知道优化数据库操作这事儿,可真是个门道多得很!比如说,调整联接条件啊,用上索引来提速啊,批量导入数据也是一大妙招,还有就是选对联接方式,这些小技巧都能让咱们的操作变得顺畅无比,响应速度嗖嗖的快起来。就像开车走高速,不堵车不绕弯,直奔目的地,那感觉,爽歪歪!哎呀,随着咱手里的数据越来越多,就像超市里的货物堆积如山,技术这玩意儿也跟咱们的手机更新换代一样快。所以啊,要想让咱们的系统运行得又快又好,就得不断调整和改进策略。就像是给汽车定期加油、保养,让它跑得既省油又稳定。这事儿,可得用心琢磨,不能偷懒!未来,随着更多高级特性如分布式计算、机器学习集成等的引入,Kylin与MySQL的联接优化将拥有更广阔的应用空间,助力数据分析迈向更高层次。
2024-09-20 16:04:27
104
百转千回
转载文章
... 设置副本数[-stat [format] <path> ...][-tail [-f] <file>][-test -[defsz] <path>][-text [-ignoreCrc] <src> ...][-touch [-a] [-m] [-t TIMESTAMP ] [-c] <path> ...][-touchz <path> ...][-truncate [-w] <length> <path> ...][-usage [cmd ...]]Generic options supported are:-conf <configuration file> specify an application configuration file-D <property=value> define a value for a given property-fs <file:///|hdfs://namenode:port> specify default filesystem URL to use, overrides 'fs.defaultFS' property from configurations.-jt <local|resourcemanager:port> specify a ResourceManager-files <file1,...> specify a comma-separated list of files to be copied to the map reduce cluster-libjars <jar1,...> specify a comma-separated list of jar files to be included in the classpath-archives <archive1,...> specify a comma-separated list of archives to be unarchived on the compute machinesThe general command line syntax is:command [genericOptions] [commandOptions] 查看详细命令 hadoop fs -help 命令(如cat) 更改hdfs的权限 vi core-site.xml <property><name>hadoop.http.staticuser.user</name><value>root</value></property> HDFS客户端API操作 Windows环境配置 将Windows依赖放到文件夹, 配置环境变量,添加HADOOP_HOME ,编辑Path添加%HADOOP_HOME%/bin 拷贝hadoop.dll和winutils.exe到C:\Windows\System32 创建java项目 配置 编辑pom.xml <dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version></dependency><dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-slf4j-impl</artifactId><version>2.12.0</version></dependency><dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-client</artifactId><version>3.1.3</version></dependency></dependencies> 在src/main/resources中建立log4j2.xml 打印日志到控制台 <?xml version="1.0" encoding="UTF-8"?><Configuration status="WARN"><Appenders><Console name="Console" target="SYSTEM_OUT"><PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/></Console></Appenders><Loggers><Root level="error"><AppenderRef ref="Console"/></Root></Loggers></Configuration> 编写代码 在/src/main/java/cn.zcx.hdfs创建TestHDFS类 public class TestHDFS {// 创建全局变量private FileSystem fs;private Configuration conf;private URI uri;private String user;// 从本地上传文件@Testpublic void testUpload() throws IOException {fs.copyFromLocalFile(false,true,new Path("F:\\Download\\使用前说明.txt"),new Path("/testhdfs"));}/ @Before 方法在@Test方法执行之前执行 /@Beforepublic void init() throws IOException, InterruptedException {uri = URI.create("hdfs://master:8020");conf = new Configuration();user = "root";fs = FileSystem.get(uri,conf,user);}/ @After方法在@Test方法结束后执行 /@Afterpublic void close() throws IOException {fs.close();}@Testpublic void testHDFS() throws IOException, InterruptedException {//1. 创建文件系统对象/URI uri = URI.create("hdfs://master:8020");Configuration conf = new Configuration();String user = "root";FileSystem fs = FileSystem.get(uri,conf,user);System.out.println("fs: " + fs);/// 2. 创建一个目录boolean b = fs.mkdirs(new Path("/testhdfs"));System.out.println(b);// 3. 关闭fs.close();} } 参数优先级 xxx-default.xml < xxx-site.xml < IDEA中resource中创建xxx-site.xml < 在代码中通过更改Configuration 参数 文件下载 @Testpublic void testDownload() throws IOException {fs.copyToLocalFile(false,new Path("/testhdfs/使用前说明.txt"),new Path("F:\\Download\\"),true);} 文件更改移动 //改名or移动(路径改变就可以)@Testpublic void testRename() throws IOException {boolean b = fs.rename(new Path("/testhdfs/使用前说明.txt"),new Path("/testhdfs/zcx.txt"));System.out.println(b);} 查看文件详细信息 // 查看文件详情@Testpublic void testListFiles() throws IOException {RemoteIterator<LocatedFileStatus> listFiles = fs.listFiles(new Path("/"), true);//迭代操作while (listFiles.hasNext()){LocatedFileStatus fileStatus = listFiles.next();//获取文件详情System.out.println("文件路径:"+fileStatus.getPath());System.out.println("文件权限:"+fileStatus.getPermission());System.out.println("文件主人:"+fileStatus.getOwner());System.out.println("文件组:"+fileStatus.getGroup());System.out.println("文件大小:"+fileStatus.getLen());System.out.println("文件副本数:"+fileStatus.getReplication());System.out.println("文件块位置:"+ Arrays.toString(fileStatus.getBlockLocations()));System.out.println("===============================");} } 文件删除 第二参数,true递归删除 //文件删除@Testpublic void testDelete() throws IOException {boolean b = fs.delete(new Path("/testhdfs/"), true);System.out.println(b);} NN与2NN工作原理 本篇文章为转载内容。原文链接:https://blog.csdn.net/Python1One/article/details/108546050。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2023-12-05 22:55:20
276
转载
转载文章
...stgre-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
转载
转载文章
...ed — most users don’t even know who maintains the software that they use.” “如今的人没有什么动力去为现有的开源项目做贡献”,来自DNS网络公司NS1的杰出工程师Jeremy Strech说,“因为通常来说,这没有直接的物质回报,也很少提供荣誉----大多数用户甚至不知道他们所用的软件是谁维护的。” The most common motivation among open source contributors is to add a feature that they themselves want to see, he said. “Once this has been achieved, the contributor rarely sticks around.” 他说,开源贡献者们最常见的动机就是添加他们自己想要的功能。“一旦实现了这一点,他们几乎都不会留下来。” Meanwhile, as a project becomes more popular, the burden on the core team of maintainers keeps increasing. 与此同时,随着项目的逐渐流行,对于维护方面的核心团队来说,他们的负担也在不断增加。 “More users means more feature requests and more bug reports — but not more maintainers,” Stretch said. “What was once an enjoyable hobby can quickly become a tedious chore, and many maintainers understandably opt to simply abandon their projects altogether.” “更多的用户意味有着更多的功能需求和错误报告----但不是更多的维护人员”,Stretch说。“曾经令人愉快的爱好很快就会变成一项乏味的项目,所以很多维护人员选择干脆完全放弃他们的项目,这也是可以理解的。” Part1The Tragedy of the Commons The open source software ecosystem is a perfect example of the “tragedy of the commons.” 开源软件的生态系统,就是“公地悲剧”的一个完美例子。 And the tragedy is — when everyone uses, but no one contributes, that resource — whether it’s an overrun park or an open source project — eventually collapses from overuse and underinvestment. Everyone loves using free stuff, but everyone expects someone else to take care of it. 这个悲剧就是---当一种资源,无论是一个超限的公园还是一个开源项目,所有人都在使用而没有人贡献之时,最终都会因为过度使用和投入不足而崩溃坍塌。 This approach can save you money in the short term, but it can become a fatal flaw over time. Especially since open source software is everywhere, running everything. 这种方式可以在短期内为你节省资金,但随着时间的推移,它可能会变成项目里致命的缺陷。 Linux, for example, the open source operating system, runs on 96% of the world’s top 1 million servers, and 90% of all cloud infrastructure is on Linux. Not to mention that 85% of all smartphones in the world run Linux, in the form of the Android OS. 拿Linux来说,这个开源操作系统在全球前100万台服务器中运行率在96%以上,且这些服务器90%的云基础设施也都在Linux上。更不用说世界上85%的智能手机都运行着Linux,即Android操作系统。 Then there’s Java, Apache, WordPress, Cassandra, Hadoop, MySQL, PHP, ElasticSearch, Kubernetes — the list of ubiquitous open source projects goes on and on. 还有Java, Apache, WordPress, Cassandra, Hadoop, MySQL, PHP, ElasticSearch, Kubernetes--这些常见开源项目的列表还在逐渐增加着。 Without open source, much of today’s technical infrastructure would immediately grind to a halt. 如果没有开源,今天的大部分技术基础设施的建设也将会戛然而止。 “It is a real problem,” said Danil Mikhailov, executive director at Data.org, a nonprofit backed by the Mastercard Center for Inclusive Growth and The Rockefeller Foundation that promotes the use of data science to tackle society’s greatest challenges. “这是一个很现实的问题”,Data.org的执行董事Danil Mikhailov说,该组织是由万事达包容性发展中心和洛克菲勒基金会支持,旨在促进使用数据科学来应对当今社会所面临的巨大挑战的非营利性组织。 While nearly all organizations use open source software, only a minority contribute to those projects. Forty-two percent of participants in a survey released in September by The New Stack, Linux Foundation Research, and the TODO Group said tthey contribute at least sometimes to open source projects. 虽然几乎所有组织都在使用着开源软件,但只有少数组织为这些项目作出了贡献。The New Stack、Linux Foundation Research 和 TODO Group 在 9 月发布的一项调查中,42% 的参与者表示,他们至少有时会为开源项目做出贡献。 The same study showed that only 36% of organizations train their engineers to contribute to open source. 而同一项研究表明,只有36%的组织会培训他们的工程师为开源作出贡献。 Individual companies should support projects that they use the most and are critical to their success, Mikhailov said: “If you use, you contribute.” 个体公司应该支持贡献这些他们使用最多且对他们成功至关重要的项目,Mikhailov认为:“如果你使用开源,你就应该为他做出属于你自己的贡献。” Part2OSPO Benefits:Less Tech Debt,Better Recruiting Participating in open source communities — especially when guided by an in-house open source program office (OSPO) — can help ensure the health of projects critical to your organization’s success, improve those projects’ security, and allow your engineers to have more impact in the projects’ development road map. 参与开源社区——特别是在内部开源项目办公室(OSPO)的指导下——不仅可以保证对组织成功至关重要项目的健康发展,还可以提高项目安全性,同时可以允许工程师在项目发展规划中起到更大的影响。 Say, for example, a company uses an open source tool and modifies it a little to make it better. If that improvement isn’t contributed back to the community, then the official version of the open source project will start to diverge from what the company is using 例如,如果一家公司使用了开源工具,并对其进行了一些调整使其变得更好。但如果这项改进没有反馈到开源社区,那么开源项目的正式版本就会一开始与该公司所使用的版本有所不同。 “You start to grow technical debt because when the original source changes and you’ve got a different version. Those differences grow rapidly, compounding daily. It doesn’t take long for you to be the proud user and maintainer of a one-of-a-kind open source project variant,” said Suzanne Ambiel, director, open source marketing and strategy at VMware. “当原始代码来源发生变化且你所使用的是不同的版本时,你的技术负债将越来越多。而这些差异是以天为单位迅速增长的。”VMware 开源营销和战略总监 Suzanne Ambiel 表示,“所以你很快就会变成一个开源项目里独一无二变体的‘自豪’用户和维护人员。” “The technical debt gets bigger and bigger and it gets very expensive for a company to manage.” “如果技术负债越来越多,那么公司的管理成本则会非常昂贵”。 Support for open source activity can also be a recruiting tool. “It’s really a talent magnet,” said Ambiel. “It’s one of the things that new hires look for.” 实际上对于开源活动的支持也变成了一种招聘途径。“这真是一块吸引人才的磁铁,”Ambiel说,“这也是新员工所寻求的“。 Some engineering managers might worry that open source contributions will detract from core product development, she said. Their rationale, she added, might run along the lines of, “I only have so much talent, and so many hours, and I need them to only work on things where I can measure and see the return on investment.” 她还提到,一些工程经理可能会对贡献开源而减损核心产品的开发的精力而感到担忧。她补充到,他们的理由有可能是这样的:“我只有有限的才华与时间,且我需要这些只做我认为可以度量且看到投资回报的事情。” But that attitude, she said, is shortsighted. Supporting employees who contribute to open source communities can build skills and develop talent, she said. 但她说,这是一种鼠目寸光的态度。支持开源社区并且作出贡献的员工,可以从中培养技能与增长才华。 Loris Degionni, chief technology officer and founder at Sysdig, a cloud security vendor, echoed this notion: “Finding employees who contribute to open source is a gold mine,” said. 云安全供应商 Sysdig 的首席技术官兼创始人 Loris Degionni 也赞同这一观点:“找出为开源做出贡献的员工无疑就找到一座金矿,”他说。 These employees are more capable of delivering features a company wants to use and merge them into community-supported standards, he said. And in a war for talent, companies that embrace open source are more attractive to developers. 他认为,这些参与开源的员工更具备公司想拥有的竞争力并将一些功能融入至社区所支持的标准中。且在人才争夺战中,拥抱开源的公司也更受到开发人员的青睐。 “Lastly, open source is driven by a community of technical experts you may not be able to hire,” he said. “When employees actively contribute and collaborate with these experts, they’ll be better informed of best practices and bring them back to your organization. “最后,开源项目是由你可能无法聘请的技术专家社区推动的”,他说,“当员工积极参与并于这些专家合作时,他们将能更好地深入这些最佳实践,并将这些收获带回到你的组织之中。” “You start to grow technical debt because when the original source changes and you’ve got a different version … It doesn’t take long for you to be the proud user and maintainer of a one-of-a-kind open source project variant.” —Suzanne Ambiel, director, open source marketing and strategy, VMware “当原始数据来源发生变化且你所使用的是不同的版本时,你的技术负债将越来越多...所以你很快就会变成一个开源项目里独一无二变体的”自豪“用户和维护人员。” — Suzanne Ambiel,VMware 开源营销和战略总监 “All of this should be rewarded — developers shouldn’t have to spend their free time honing their skills, as your company will quickly see benefits from their efforts.” “但是这一切终究不会白费--开发人员不应该把业余时间用在磨练他们的技能上,因为你的公司很快就会在他们的努力中看到好处。” An OSPO, Degionni suggested, can help achieve these goals, as well as help prioritize contributions and ensure collaboration. In addition, they can help provide governance that mirrors what companies would have for internally developed applications. Degionni认为,OSPO(开源计划办公室)可以帮助公司实现这些目标,以及帮助确定贡献的优先级并确保合作的进行。除此之外,他们也可以对公司内部开发应用程序方面的治理提供相关帮助。 “Members of the open source team are also in a position to be great internal evangelists for open source technologies, and act as bridges between the organization and the broader community,” he added. “开源团队的成员也可以成为开源技术的伟大内部布道师,并充当组织与更广泛社区之间的桥梁。”他补充道。 In the September survey from The New Stack, Linux Foundation Research and the TODO Group, nearly 53% of organizations with OSPOs said they saw more innovation as a result of having an OSPO, while almost 43% said they saw increased participation in external open source projects. 在 The New Stack、Linux Foundation Research 和 TODO Group 的 9 月调查中,近 53% 的拥有 OSPO的组织表示,由于拥有了OSPO,他们看到了更多创新,而近 43% 的组织表示,他们在外部开源项目的参与度上有所增加。 Part3More OSPO Benefits:A Business Edge Contributing to open source communities doesn’t just help the communities, but the companies that contribute to them, said Tom Hickman, chief innovation officer at ThreatX, a cybersecurity firm. 网络安全公司 ThreatX 的首席创新官 Tom Hickman 表示,为开源社区做出贡献,不仅有助于社区,还有助于为社区做出贡献的公司。 “Growing the community of developers around a project helps the code base, and attracts more developers,” he said. “It can become a virtuous circle.” “围绕一个项目而发展的开发人员社区,有助于代码库的形成,并吸引更多的开发人员参与”,他说,“这可以变成一个良性循环。” Also, companies that contribute to open source projects get twice the productive value from their use of open source than companies that don’t, according to research by Harvard Business School. 此外,根据哈佛商学院的研究,为开源项目作出贡献的公司从使用开源的项目中获得的生产价值,是不参与开源项目公司的两倍。 Many of the biggest companies in the world are contributing to open source, said Chris Aniszczyk, chief technology officer at Cloud Native Computing Foundation. He pointed to the Open Source Contributor Index as a reference for exactly just how much companies are doing. Cloud Native Computing Foundation 的首席技术官 Chris Aniszczyk 说,世界上许多巨头公司都为开源作出了贡献。他还提到,开源贡献者的指数是作为公司是否有所作为的参考。 The tech giants dominate the list: Google, Microsoft, Red Hat, Intel, IBM, Amazon, Facebook, VMware, GitHub and SAP are the top 10 contributors, in that order. But there are also a lot of end users on the top 100 list, said Aniszczyk, including Uber, the BBC, Orange, Netflix, and Square. 科技巨头占据了这份榜单的主导地位:谷歌、微软、红帽、英特尔、IBM、亚马逊、Facebook、VMware、GitHub 和 SAP 依次是排名前 10 的贡献者。但Aniszczyk 表示,但也有很多终端用户公司进入前 100 名,包括 Uber、BBC、Orange、Netflix 和 Square。 “We’ve always known working in upstream projects is not just the right thing to do —it’s the best approach to open source software development and the best way to deliver open source benefits to our customers,” he said. “It’s great to see that IT leaders recognize this as well.” “我们一直知道,在上游项目中工作不仅仅是关正确与否----它是开源软件开发的最佳方法,也是向客户提供开源福利的最佳方式“他说,“很高兴看到IT领导者们也认识到了这一点。” To contribute alongside these giants, companies need to have their own open source strategies, and having an open source program office can help. 为了和这些公司一起作出贡献,公司也需要有自己的开源策略,而拥有一个开源项目办公室则可以为其提供帮助。 “OSPOs provide a critical center of competency in a company when it comes to utilizing open source software,” he said. “在使用开源软件方面,OPSO为公司提供了一个至关重要的能力中心”他说。 It’s similar to the way that companies have security operations centers, he said. 这与公司拥有安全运营中心的方式类似,他说。 “Growing the community of developers around a project helps the code base, and attracts more developers. It can become a virtuous circle.” —Tom Hickman, chief innovation officer, ThreatX “围绕一个项目而发展的开发人员社区,有助于代码库的形成,并吸引更多的开发人员参与,这可以变成一个良性循环。” ——Tom Hickman,ThreatX 首席创新官 “If you don’t make the investment in a security team, you generally don’t expect your software to be secure or be able to respond to security incidents in a timely fashion,” he said. “如果你没有对安全团队进行相应投资,你通常是不会期望你的软件是安全的,也无法及时响应安全事件。”他说。 “The same logic applies to OSPOs and is why you see many leading companies out there such as Apple, Meta, Twitter, Goldman Sachs, Bloomberg, and Google all have OSPOs. They are ahead of the curve.” “同样的逻辑也适用于 OSPO,这就是为什么你会看到许多领先的公司,例如 Apple、Meta、Twitter、Goldman Sachs、Bloomberg 和 Google 都拥有 OSPO。他们走在了趋势的前面。” Support for open source activity within your organization can become a differentiator and marketing opportunity for software vendors. 而对组织内的开源活动的支持态度亦可成为软件供应商们的差异化原因与营销的机会。 According to a Red Hat survey released in February, 82% of IT leaders are more likely to select a vendor who contributes to the open source community. 根据Red Hat2月分发布的一项调查,82%的IT领导者更倾向于选择为开源社区作出贡献的软件供应商。 Respondents said that when vendors support open source communities they are more familiar with open source processes and are more effective if customers have technical challenges. 受访者表示,当供应商支持开源社区时,就表示着他们更熟悉开源的流程并且在客户遇到技术难题时会更加有效。 But it’s not just software vendors who benefit. 但收益的不仅仅是软件供应商们。 According to September’s survey by The New Stack, Linux Foundation Research, and the TODO Group, 57% of organizations with OSPOs use them to further strategic relationships and build partnerships. 根据 The New Stack、Linux Foundation Research 和 TODO Group 9 月份的调查,57% 拥有 OSPO 的组织将使用它们来进一步发展战略关系和建立合作伙伴关系。 Mark Hinkle started an open source program office back when he worked at Citrix a decade ago. He pointed out how having an OSPO in-house benefited the company. 十年前,Mark Hinkle 在 Citrix 工作时创办了一个开源计划办公室。他指出了在内部拥有一个 OSPO将如何使公司受益。 “For us the biggest job was to educate our employees who weren’t familiar with open source to get involved and be good community members,” he said. “We also provided guidance on how to make sure our IP didn’t enter projects without proper understanding and we made sure we didn’t incorporate open source that conflicted with our enterprise software licensing.” “对于我们来说,最大的工作是让不熟悉开源的员工学会并参与其中,成为优秀的社区成员”,他说,“我们还就如何确保我们的IP不会在没有正确理解的情况下进入项目的情况提供了指导,并确保我们没有与我们企业软件许可相冲突的开源项目合作。” The OSPO also helped Citrix identify strategic opportunities for the company to participate in open source projects and trade organizations like The Linux Foundation, he said. 他说,OSPO还帮助Citrix确定了公司参与开源项目和Linux基金会等贸易组织的战略机会。 Today, he’s the CEO and co-founder of TriggerMesh, a cloud native, open source integration platform. 如今,他是云原生开源集成平台 TriggerMesh 的首席执行官兼联合创始人。 There are some significant economic benefits to participating in the open source ecosystem, he said. 他说,参与开源系统对公司来说有着重大的经济效益。 “We participate in Knative to share the development of our underlying platform but we develop value-added services as part of our business,” he said. “By sharing the R and D for the platform, it gives us more resources to develop our own differentiated technology.” “我们参与Knative是为了分享我们基础底层平台的开发,但作为业务的一部分,我们也拥有相关的增值服务。”他说,“通过共享该平台的研发,这为我们提供了更多的资源来改进我们自己的差异化技术。” Part4How to Get Started in Open Source Sixty-three percent of companies in the September survey from The New Stack, Linux Foundation Research and the TODO Group said that having an OSPO was very or extremely critical to the success of their engineering or product teams, up from 54% in the previous annual study. 在 The New Stack、Linux Foundation Research 和 TODO Group 的 9 月份调查中,有 63% 的公司表示,拥有OSPO 对其工程或产品团队的成功至关重要,高于上一年度该项研究数据的 54%。 In particular, 77% said that their open source program had a positive impact on their software practices, such as improved code quality. 其中77% 的人表示他们的开源程序对他们的软件实践产生了积极影响,例如提高了代码质量。 But companies can’t always contribute to every single open source project that they use. 但公司也不可能总是为他们使用的每一个开源项目而花费精力。 “First, thin the herd a little bit,” advised VMware’s Ambiel. “首先,节流一下”,VMware 的 Ambiel 建议道。 Companies should look at the projects that make the most sense for their use cases. This is an area where an OSPO can help set priorities and ensure technical and strategic alignment. 公司应该关注投入使用中最有意义的项目。而这也是OSPO可以帮助确定优先事项并确保技术与战略一致性的领域。 Then, developers should go and check out the projects themselves. Projects typically offer online documentation, often with contributor guides, governance documents, and lists of open issues. 之后,开发人员应该自己去了解一下。项目通常提供相关在线文档,一般包含贡献着指南、治理文档和未解决问题列表。 “For the projects that rise to the top of your strategic list, introduce yourself — say hello,” she said. “Go to the Slack channel or the distribution list and ask where they need help. Maybe they don’t need help and everything is good. Or maybe they can use a new person to review code.” “对于那些上升到你的战略清单顶端的项目,你可以介绍一下自己----打个招呼”,她说。“然后转到Slack频道或者分发列表,询问他们需要帮助的地方。也许他们不需要帮助,一切完好;又或者他们也有可能使用新人来审查核验代码。” An open source program office can not only help make a business case for contributing to the open source community, Ambiel said, but can help companies do it in a way that’s safe, secure and sound. Ambiel 说,开源项目办公室不仅可以帮助制定为开源社区做出贡献的商业案例,还可以帮助公司以安全、可靠和健全的方式来做这件事。 “If I work for a company and want to contribute to open source, I don’t want to accidentally disclose, divulge or undermine any patents,” she said. “An OSPO helps you make smart choices.” “如果我为一家公司工作,并想为开源做出贡献,我不想意外披露、泄露或破坏任何专利,”她说。“而OSPO可以帮助您做出明智的选择。” An OSPO can also help provide leadership and the guiding philosophy about supporting open source, she said. “It can provide guidance, mentorship, coaching and best practices.” 她说,OSPO还可以在开源方面提供领导力和指导理念的支持。“它可以提供引领、指导、辅导和最佳实践的作用。” Commitment to support open source has to start at the top, said Anaïs Urlichs, developer advocate at Aqua Security. Aqua Security的开发人员倡导者Anaïs Urlichs则认为,支持开源的承诺必须从高层开始。 “Too often,” she said, “companies do not value investment into open source, so employees are not encouraged to contribute to it.” 她说,“公司在多数时候往往不重视对开源的投资,所以员工自然而然不被鼓励对此作出贡献。” In those cases, employees with a passion for open source end up contributing during their free time, which is not sustainable. 在这些情况下,员工对于开源的热情也会在空闲时间里对开源的建设而消散殆尽,这对于开源的发展来说是不可持续的。 “If companies rely on open source projects, it is important to make open source contributions part of an engineer’s work schedule,” she said. “Some companies define a time percentage that employees can contribute to open source as part of their normal workday.” “如果公司对开源项目依赖度高,那么将开源贡献纳入工程师的日程安排是很重要的,”她说。“一些公司定义了员工可以为开源建设的时间百分比,将其作为他们正常工作日的一部分。” The New Stack is a wholly owned subsidiary of Insight Partners, an investor in the following companies mentioned in this article: Sysdig, Aqua Security. The New Stack 是 Insight Partners 的全资子公司,Insight Partners 是本文提到的以下公司的投资者:Sysdig、Aqua Security。 相关阅读 | Related Reading 《开源合规指南(企业篇)》正式发布,为推动我国开源合规建设提供参考 “目标->用户->指标”——企业开源运营之道|瞰道@谭中意 开源之夏邀请函——仅限高校学子开启 开源社简介 开源社成立于 2014 年,是由志愿贡献于开源事业的个人成员,依 “贡献、共识、共治” 原则所组成,始终维持厂商中立、公益、非营利的特点,是最早以 “开源治理、国际接轨、社区发展、开源项目” 为使命的开源社区联合体。开源社积极与支持开源的社区、企业以及政府相关单位紧密合作,以 “立足中国、贡献全球” 为愿景,旨在共创健康可持续发展的开源生态,推动中国开源社区成为全球开源体系的积极参与及贡献者。 2017 年,开源社转型为完全由个人成员组成,参照 ASF 等国际顶级开源基金会的治理模式运作。近八年来,链接了数万名开源人,集聚了上千名社区成员及志愿者、海内外数百位讲师,合作了近百家赞助、媒体、社区伙伴。 本篇文章为转载内容。原文链接:https://blog.csdn.net/kaiyuanshe/article/details/124976824。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2023-05-03 09:19:23
273
转载
Javascript
... function UserList({ users }) { return ( {users.map(user => ( {user.name} {user.active ? Active : Inactive} ))} ); } export default UserList; 在这个例子中,我们通过模板字面量动态生成了每个用户的详细信息,包括头像、用户名和状态信息。这种做法不仅使代码更加简洁,也提高了可维护性。 此外,随着TypeScript的普及,模板字面量类型也成为了一种强大的工具。通过定义特定格式的字符串类型,我们可以确保字符串的格式符合预期,从而减少运行时错误。例如: typescript type Greeting = Hello, ${string}!; const greeting: Greeting = 'Hello, Alice!'; console.log(greeting); // 正确 const wrongGreeting: Greeting = 'Goodbye, Alice!'; // 编译错误 这段代码定义了一个名为Greeting的类型,它表示一个以Hello, 开头并以!结尾的字符串。通过这种方式,我们可以确保所有使用该类型的变量都符合特定的格式,从而提高代码的健壮性。 总之,模板字面量作为一种强大的语言特性,在现代Web开发中扮演着越来越重要的角色。无论是在React或Vue.js这样的框架中,还是在TypeScript这样的类型系统中,模板字面量都能帮助开发者写出更简洁、更安全的代码。
2024-12-10 15:48:06
97
秋水共长天一色
JSON
...象赋值给组件的状态(state),实现视图的自动更新;React通过setState方法更新状态,并结合JSX语法实现JSON数据到UI的渲染;Angular则凭借其强大的模板表达式和变更检测系统,让JSON数据操作变得直观高效。 此外,在Node.js后端环境中,诸如Express框架支持直接将JSON传递给路由处理器,并内建了中间件来解析JSON请求体。同时,使用诸如axios或fetch这类现代HTTP客户端库,可以更加优雅地发起异步请求并处理返回的JSON数据。 近期,ECMAScript标准也在JSON支持上进行了优化,如引入JSON.stringify()的第三个参数用于定制化序列化过程,以及JSON.parse()可选的reviver函数对反序列化结果进行深度处理。这些新特性的运用能够帮助开发者更精细地控制JSON数据在程序中的流转和表现形式。 总的来说,理解并熟练掌握JSON数据处理已经成为现代全栈开发者的必备技能,持续关注相关技术和最佳实践的发展,能更好地适应快速变化的Web开发环境,提升开发效率和代码质量。
2023-07-24 23:16:09
441
逻辑鬼才
MyBatis
...yBatis框架中StatementParameterIndexOutOfRange异常的深度解析与解决方案 1. 引言 --- 当我们深入使用MyBatis这一强大的持久层框架时,有时可能会遇到一个让人挠头的问题——StatementParameterIndexOutOfRange异常。这个异常啊,它常常会在我们给SQL预编译语句塞参数的时候蹦出来,就是当你给索引的位置安排得太多,超出了实际参数的个数,就像是你手里只有三个苹果,却偏偏要按四个位置来放,这不就出问题了吗?这篇东西,咱们会手把手通过实实在在的代码例子、一步步的问题剖析,还有应对招数,一起把这个难题掰扯清楚,同时还会琢磨出怎么才能巧妙地躲开这个问题的小窍门儿。 2. 问题现象与背景理解 --- 想象一下,你正在编写一个使用MyBatis进行数据库操作的服务方法,例如下面这段简单的示例代码: java @Mapper public interface UserMapper { @Update("UPDATE user SET username={username} WHERE id={userId}") int updateUsername(@Param("userId") Integer userId, @Param("username") String username); } @Service public class UserService { private final UserMapper userMapper; public UserService(UserMapper userMapper) { this.userMapper = userMapper; } public void updateUser(Integer userId, String username) { // 假设此处由于疏忽,只传入了一个参数 userMapper.updateUsername(userId); // 此处应该传入两个参数,但实际只传了userId } } 在上述场景中,我们意图更新用户信息,但不幸的是,在调用updateUsername方法时,仅传入了userId参数,而忽略了username参数。运行此段代码,MyBatis将会抛出StatementParameterIndexOutOfRange异常,提示“Prepared statement parameter index is out of range”。 3. 异常原因剖析 --- 该异常的本质是我们在执行SQL预编译语句时,为占位符(如:{username}和{userId})提供的参数数量与占位符的数量不匹配导致的。在MyBatis的工作原理里,它会根据SQL语句里那些小问号(参数占位符)的数量,亲手打造一个PreparedStatement对象。然后呢,就像我们玩拼图一样,按照顺序把每个参数塞到对应的位置上。当尝试访问不存在的参数时,自然就会引发这样的错误。 4. 解决方案及预防措施 --- 面对StatementParameterIndexOutOfRange异常,解决的关键在于确保传递给映射方法的参数数量与SQL语句中的参数占位符数量相匹配。回到上面的示例代码,正确的做法应该是: java public void updateUser(Integer userId, String username) { userMapper.updateUsername(userId, username); // 正确地传入两个参数 } 同时,为了预防此类问题的发生,我们可以采取以下几种策略: - 代码审查:在团队协作开发过程中,对于涉及SQL语句的方法调用,应仔细检查参数是否齐全。 - 单元测试:编写完善的单元测试用例,覆盖所有可能的参数组合情况,确保SQL语句在各种情况下都能正确执行。 - IDE辅助:利用IDE(如IntelliJ IDEA)的代码提示功能,当方法需要的参数缺失时,IDE通常会在编辑器中给出警告提示。 5. 总结与思考 --- 尽管StatementParameterIndexOutOfRange异常看似简单,但它提醒我们在使用MyBatis等ORM框架时,务必细心对待SQL语句中的参数传递。每个程序员在高强度的编程赶工中,都免不了会犯些小马虎。重点在于,得学会怎样火眼金睛般快速揪出问题所在,同时呢,也得通过一些实实在在的预防招数,让这类小错误尽量少地冒泡儿。因此,养成良好的编程习惯,提高代码质量,是我们每一位开发者在追求技术进步道路上的重要一课。
2024-01-24 12:47:10
114
烟雨江南
ZooKeeper
...。 java Stat stat = zk.exists("/path/to/node", false); if (stat == null) { // Node does not exist } else if (!zk.hasAdminAccess("/path/to/node")) { // User does not have admin access to the node System.out.println("Failed to modify node, insufficient permissions"); } 2. 磁盘空间不足 如果ZooKeeper服务所在的服务器的磁盘空间不足,那么写入新的数据就可能会失败。这是因为每当ZooKeeper进行一次写操作时,它都会像咱们给文件命名个新版本号一样,创建一个新的版本标识。想象一下,如果我们的磁盘空间快见底了,那自然也就没地方再放这些不断更新、不断增加的版本号啦。 3. 数据冲突 ZooKeeper的数据是有序的,这意味着如果有多个客户端同时尝试更新同一个节点的数据,那么ZooKeeper会选择其中的一个进行写入,其他的所有写操作都会被忽略。但是,如果这些客户端之间存在数据冲突,那么写入操作就可能会失败。 三、解决数据写入失败的方法 1. 检查权限 首先,你需要确保你有足够的权限来进行写操作。你可以使用hasAdminAccess()方法来检查你的权限。 java Stat stat = zk.exists("/path/to/node", false); if (stat == null) { // Node does not exist } else if (!zk.hasAdminAccess("/path/to/node")) { // User does not have admin access to the node System.out.println("Failed to modify node, insufficient permissions"); } 2. 增加磁盘空间 其次,你需要确保ZooKeeper服务所在的服务器有足够的磁盘空间。你可以通过增加硬盘容量或者清理不必要的文件来增加磁盘空间。 3. 解决数据冲突 最后,你需要解决数据冲突的问题。你可以通过调整并发度或者使用更复杂的锁机制来避免数据冲突。比如,你能够像用一把保险锁(就像互斥锁那样)来确保同一时间只有一个客户端能对节点数据进行修改,这样就实现了安全更新。 四、结论 总的来说,数据写入失败可能是由于权限问题、磁盘空间不足或数据冲突等原因造成的。对于这些问题,我们需要分别采取相应的措施来解决。记住了啊,真正搞明白这些问题,并妥善处理它们,就能让我们更溜地驾驭ZooKeeper这个超级强大的工具,让它发挥出更大的作用。
2023-09-18 15:29:07
121
飞鸟与鱼-t
DorisDB
...LECT FROM user WHERE age > 18; 如果age字段没有索引,那么查询将会进行全表扫描。为了提高查询效率,我们应该为age字段创建索引。 四、如何提高查询效率? 1. 分区设计 分区设计可以显著提高查询效率。在DorisDB这个数据库里,我们可以灵活运用PARTITION BY命令,就像给表分门别类一样进行分区操作,让数据管理更加井井有条。例如: sql CREATE TABLE table_name ( id INT, name STRING, ... ) PARTITIONED BY (id); 这个语句会根据id字段对table_name表进行分区。 2. 查询优化器 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
...$ psql -U username 这里的username是你在PostgreSQL中的用户名。 2. 在PostgreSQL的提示符下,输入\c database_name命令,进入你需要操作的数据库。 3. 然后,你可以通过SELECT pg_backend_pid();命令查看当前正在运行的后台进程的ID。 4. 接下来,我们可以使用ALTER USER命令来修改用户的密码。例如,如果你想将用户名为user1的用户密码改为new_password,可以使用以下命令: sql ALTER USER user1 WITH PASSWORD 'new_password'; 5. 最后,记得退出PostgreSQL环境 bash \q 三、安全性的重要性 当我们面对警告时,往往会感到紧张和不安。这是因为我们的信息安全可能会受到影响。而在PostgreSQL中,用户的密码就是我们最重要的信息资产之一。 因此,我们不能忽视任何有关密码安全的警告。我们必须定期更改我们的密码,并确保它们足够强大,以防止被破解。此外,咱们也得记住,可别在公共网络这种地方,泄露那些敏感信息,像是银行卡账号、社交媒体账号啥的,这些都得捂严实了,别让人给瞧见了。 四、总结 在PostgreSQL中,如果我们收到了“WARNING: your password has expired, please change it before continuing”的警告,我们不需要惊慌。只要按照上述步骤,就可以轻松地更改我们的密码。 在这个过程中,我们也可以更好地认识到密码安全的重要性。我们得时刻打起十二分精神,把咱们的信息宝藏看牢了,别让那些不必要的损失找上门来。 所以,记住,当遇到警告时,首先要冷静分析,然后根据提示进行相应的操作。这样我们才能真正做到随机应变,无论啥状况冒出来都能稳稳接住,确保我们的信息安全无虞。
2023-04-17 13:39:52
113
追梦人-t
ElasticSearch
...,我们需要创建一个 user_comment 文档类型,包含用户 id、评论内容和评论时间等字段。然后,我们可以编写如下的代码来获取最新的用户评论: python from datetime import datetime import requests 设置 Elasticsearch 的地址和端口 es_url = "http://localhost:9200" 创建 Elasticsearch 集群 es = Elasticsearch([es_url]) 获取最新的用户评论 def get_latest_user_comments(): 设置查询参数 params = { "index": "user_comment", "body": { "query": { "match_all": {} }, "sort": [ { "created_at": { "order": "desc" } } ], "size": 1, "search_after": [] } } 获取第一条记录 response = es.search(params) if not response["hits"]["hits"]: return [] 记录最后一条记录的排序字段值 last_record = response["hits"]["hits"][0] search_after = [last_record["_source"]["id"], last_record["_source"]["created_at"]] 获取下一条记录 while True: params["body"]["size"] += 1 params["body"]["search_after"] = search_after response = es.search(params) 如果没有更多记录,则返回所有记录 if not response["hits"]["hits"]: return [hit["_source"] for hit in response["hits"]["hits"]] else: last_record = response["hits"]["hits"][0] search_after = [last_record["_source"]["id"], last_record["_source"]["created_at"]] 在这段代码中,我们首先设置了一个空的 search_after 列表,然后执行了一次查询,获取了第一条记录,并将其存储在 last_record 变量中。接着,我们将 last_record 中的 id 和 created_at 字段的值添加到 search_after 列表中,再次执行查询,获取下一条记录。如此反复,直到获取到我们需要的所有记录为止。 五、总结 search_after 参数是 Elasticsearch 5.0 版本引入的一个新的分页方式,它可以让我们在每一页查询结束时,记录下最后一条记录的排序字段值,并将这个值作为下一页查询的开始点,以此类推广多获取我们需要的分页数量为止。这种方法不仅可以减少内存和 CPU 的消耗,而且还能够提高查询的效率,是一个非常值得使用的分页方式。
2023-03-26 18:17:46
576
人生如戏-t
PostgreSQL
...ers 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
...00/_nodes/stats/indices,query_cache?human&pretty' 通过观察查询缓存命中率、分片分配状态以及CPU、内存使用情况,可以帮助我们判断是否因ES集群性能瓶颈导致Discover加载慢。 4. 解决策略与实践 策略1:优化查询条件与DSL 确保在Discover页面使用的查询语句高效且有针对性。例如,使用range查询限定时间范围,使用term或match精确匹配特定字段,或利用bool查询进行复杂的组合条件过滤。 策略2:调整Elasticsearch集群配置 - 增加硬件资源,如提升CPU核数、增加内存大小。 - 调整索引设置,如合理设置分片数量和副本数量,优化refresh interval以平衡写入性能与实时性需求。 - 启用并适当调整查询缓存大小。 策略3:优化Kibana配置 在Kibana.yml配置文件中,可以对discover页面的默认查询参数进行调整,如设置默认时间范围、最大返回文档数等,以降低一次性加载数据量。 5. 结论与探讨 解决Kibana Discover页面加载数据慢或空白的问题,需要结合实际情况,从查询语句优化、Elasticsearch集群调优以及Kibana自身配置多方面着手。在实际操作的过程中,我们得像个福尔摩斯那样,一探究竟,把问题的根源挖个底朝天。然后,咱们得冷静分析,理性思考,不断尝试各种可能的优化方案,这样才能够让咱们的数据分析之路走得更加顺风顺水,畅通无阻。记住,每一次的成功优化都是对我们技术理解与应用能力的一次锤炼和提升!
2023-08-21 15:24:10
298
醉卧沙场
DorisDB
...们有个用户信息表叫users,里面有个age栏。咱们经常得根据年龄段来捞人,就是找特定年纪的用户。为了提高查询效率,我们可以创建一个针对age列的索引: sql CREATE INDEX idx_users_age ON users (age); 这样,在执行查询时,DorisDB可以直接通过索引来定位需要的数据,而无需扫描整个表,从而减少了网络传输的数据量。 3.4 使用分区表 分区表可以将大数据集分成多个较小的部分,从而提高查询效率。想象一下,我们有个表格叫sales,里面记录了所有的销售情况,还有一个日期栏叫date。每次我们需要查某个时间段内的销售记录时,就得用上这个表格了。为了提高查询效率,我们可以创建一个基于date列的分区表: sql CREATE TABLE sales ( id INT, date DATE, amount DECIMAL(10, 2) ) PARTITION BY RANGE (date) ( PARTITION p2023 VALUES LESS THAN ('2024-01-01'), PARTITION p2024 VALUES LESS THAN ('2025-01-01') ); 这样,在执行查询时,DorisDB只需要扫描相关的分区,而无需扫描整个表,从而减少了网络传输的数据量。 4. 实践经验分享 在实际工作中,我发现以下几点可以帮助我们更好地优化DorisDB的网络带宽使用: - 监控网络流量:定期检查网络流量情况,找出瓶颈所在。可以使用工具如iftop或nethogs来监控网络流量。 - 分析查询日志:通过分析查询日志,找出频繁执行且消耗资源较多的查询,对其进行优化。 - 合理规划集群:合理规划集群的规模和节点分布,避免因节点过多而导致网络带宽竞争激烈。 - 持续学习和实践:DorisDB的技术不断更新迭代,我们需要持续学习新的技术和最佳实践,不断优化我们的系统。 5. 结语 优化DorisDB的网络带宽使用是一项系统工程,需要我们从多方面入手,综合考虑各种因素。用上面说的那些招儿,咱们能让系统跑得飞快又稳当,让用户用起来更爽!希望这篇文章能对你有所帮助,让我们一起努力,让数据流动得更顺畅!
2025-01-14 16:16:03
86
红尘漫步
Greenplum
...据。 sql pg_dumpall > backup.sql 这段代码将备份整个数据库到backup.sql文件中。我们可以使用这个文件来恢复数据。 3.2 系统监控 通过系统监控,我们可以及时发现并解决问题。比如,假如我们瞅见某个家伙的CPU占用率爆表了,那咱就得琢磨琢磨,是不是这家伙的硬件出啥幺蛾子了。 sql SELECT datname, pg_stat_activity.pid, state, query FROM pg_stat_activity WHERE datname = ''; 这段代码将显示当前正在运行的所有查询及其状态。我们可以根据这些信息来判断是否存在异常情况。 3.3 用户培训 最后,我们应该对用户进行培训,让他们了解正确的使用方法,避免因为误操作而导致的数据文件完整性检查失败。 sql DO $$ BEGIN RAISE NOTICE 'INSERT INTO my_table VALUES (1, 2)'; EXCEPTION WHEN unique_violation THEN RAISE NOTICE 'Error: INSERT failed'; END$$; 这段代码将在my_table表中插入一条新的记录。我们可以使用这个例子来教给用户如何正确地插入数据。 4. 结论 数据文件完整性检查失败是一个严重的问题,但我们并不需要害怕它。只要我们掌握了正确的知识和技能,就能够有效地应对这个问题。 通过本文的学习,你应该已经知道了一些可能导致数据文件完整性检查失败的原因,以及一些解决方案。希望这篇文章能够帮助你在遇到问题时找到正确的方向。
2023-12-13 10:06:36
529
风中飘零-t
Kibana
...e1:9200"] username: "your_user" password: "your_password" 同理,添加第二个、第三个...集群配置 cluster_2: seeds: ["http://cluster2-node1:9200"] ssl: true ssl_certificate_authorities: ["/path/to/ca.pem"] 步骤二:重启Kibana服务 应用上述配置后,记得重启Kibana服务,让新的设置生效。 步骤三:验证集群连接 在Kibana控制台,检查Stack Management > Advanced Settings > xpack.search.remote.clusters,应能看到你刚配置的集群信息,表示已经成功连接。 4. 使用跨集群搜索功能 现在,你可以在Discover页面创建索引模式时选择任意一个远程集群的索引了。例如: json POST .kibana/_index_template/my_cross_cluster_search_template { "index_patterns": ["cluster_1:index_name", "cluster_2:another_index"], "template": { "settings": {}, "mappings": {} }, "composed_of": [] } 这样,在Discover面板搜索时,就可以同时查询到"cluster_1:index_name"和"cluster_2:another_index"两个不同集群的数据了。 5. 深入思考与探讨 跨集群搜索的功能对于那些拥有大量分布式数据源的企业来说,无疑是一个福音。然而,这并不意味着我们可以无限制地增加集群数量。当我们的集群规模逐渐扩大时,性能消耗和复杂程度也会像体重秤上的数字一样蹭蹭上涨。所以在实际操作中,咱们就得像个精打细算的家庭主妇,根据自家业务的具体需求和资源现状,好好掂量一下,做出最划算、最明智的选择。 此外,虽然Kibana跨集群搜索带来了极大的便利性,但在处理跨集群数据权限、数据同步延迟等问题上仍需谨慎对待。在尽情享受技术带来的种种便利和高效服务时,咱们也别忘了时刻关注并确保数据的安全性以及实时更新的重要性。 总结起来,配置Kibana跨集群搜索不仅是一项技术实践,更是对我们如何在复杂数据环境中优化工作流程,提升数据价值的一次有益探索。每一次尝试和挑战都是我们在数据分析道路上不断进步的动力源泉。
2023-02-02 11:29:07
334
风轻云淡
转载文章
...决 两个函数的区别 pg_cancel_backend() pg_terminate_backend() 后记 查询被锁住的表和进程 杀掉指定表指定锁的进程 问题发生并解决后,有一段时间了,所以问题和解决过程只记住了个大概… 问题表现 pgsql,删除某张表,无论是用第三方工具,还是命令,都无法删除成功。因为时间有点长了,所以报的啥错我也记不清了… 无法删除、无法访问、select 什么的都不成功。其他同事对这张表的操作一样。 百度之后,显示最多的结果是,有依赖,解决办法也很简单: DROP TABLE [table] CASCADE; 但是执行后,仍然解决不了问题。 问题分析 既然和依赖没关系,那就想其他办法。 经过百度和分析,大概率是有一个查询的sql,因为某些原因卡住了,然后一直占住这张表了,其他的操作都无法使用这张表。 问题解决 百度之后有如下办法: select from pg_class where relname='t_test' select oid from pg_class where relname='t_test' -- 将查出来的oid 填入下面select from pg_locks where relation='33635' -- 再将查出来的pid,调用下面的方法select pg_terminate_backend (17789) 因为时间过长,所以我也不确定下面的sql是干嘛的了… select ,pid,backend_start,application_name,query_start,waiting,state ,query from pg_stat_activitywhere pid = 17789order by query_start asc;SELECT FROM pg_stat_activity WHERE datname='t_test' 两个函数的区别 除了pg_terminate_backend()外,还有pg_cancel_backend()。 这里和oracle类似kill session的操作是 pg_terminate_backend() pg_cancel_backend() 只能关闭当前用户下的后台进程 向后台发送SIGINT信号,用于关闭事务,此时session还在,并且事务回滚 取消后台操作,回滚未提交事物 pg_terminate_backend() 需要superuser权限,可以关闭所有的后台进程 向后台发送SIGTERM信号,用于关闭事务、关闭Process,此时session也会被关闭,并且事务回滚 中断session,回滚未提交事物 后记 后来查了以下,出现那种删不掉,DROP TABLE [table] CASCADE也没用的情况,是因为表被锁住了。 查询被锁住的表和进程 select from pg_locks ajoin pg_class b on a.relation = b.oidjoin pg_stat_activity c on a.pid = c.pidwhere a.mode like '%ExclusiveLock%'; 这里查的是排它锁,也可以精确到行排它锁或者共享锁之类的。这里有几个重要的column:a.pid是进程id,b.relname是表名、约束名或者索引名,a.mode是锁类型。 杀掉指定表指定锁的进程 select pg_cancel_backend(a.pid) from pg_locks ajoin pg_class b on a.relation = b.oidjoin pg_stat_activity c on a.pid = c.pidwhere b.relname ilike '表名' and a.mode like '%ExclusiveLock%';--或者使用更加霸道的pg_terminate_backend():select pg_terminate_backend(a.pid) from pg_locks ajoin pg_class b on a.relation = b.oidjoin pg_stat_activity c on a.pid = c.pidwhere b.relname ilike '表名' and a.mode like '%ExclusiveLock%'; 另外需要注意的是,pg_terminate_backend()会把session也关闭,此时sessionId会失效,可能会导致系统账号退出登录,需要清除掉浏览器的缓存cookie(至少我们系统遇到的情况是这样的)。 本篇文章为转载内容。原文链接:https://blog.csdn.net/weixin_42845682/article/details/116980793。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2023-09-22 09:08:45
126
转载
站内搜索
用于搜索本网站内部文章,支持栏目切换。
知识学习
实践的时候请根据实际情况谨慎操作。
随机学习一条linux命令:
env
- 列出当前环境变量及其值。
推荐内容
推荐本栏目内的其它文章,看看还有哪些文章让你感兴趣。
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
历史内容
快速导航到对应月份的历史文章列表。
随便看看
拉到页底了吧,随便看看还有哪些文章你可能感兴趣。
时光飞逝
"流光容易把人抛,红了樱桃,绿了芭蕉。"