pgpool就是一个架在数据库与应用系统之间的中间层,用于实现cluster或分布式数据库,实现数据库的大规模集成应用,类以于oracle的Tuxedo;不过这个是开源的,功能上也有一些限制,具体应用去它的官网上去看,下面主要分析它的实现原理

对于replication,它和MysqL一样是通过传递sql实现的,对于分布式存储,它是把sql经过parse,rewrite之后,生成经过优化后的sql分别在结点上执行,再把结果汇总。

对postgresql的通讯是通过libpq和socket实现的,对于自身多结点的通讯是通过socket实现的,对于一台机器的多个进程间是通过pipe和unix domain socket通信的

pgpool也和postgresql一样是多进程的,主要分为main进程,child进程,pcp进程,main进程主要是health check和消息中转,child进程负责与postgresql通讯,pcp进程负责与其它的pgpool进程通讯和用户名密码的检查,pcp之间的通讯全是用一个字母代表语义,这个通讯协议还需要看看是不是采用的是postgresql中的通讯协议,在pcp目录下面,还保存了一些用户管理pgpool的工具

pgpool的数据库结点分为两类,第一是node db就是普通的数据库结点,第二是system db这个在分布式存储中主要存储分布的规则,在query cache中用来保存cache,这在一个pgpool的缓冲池中只有一个

在结构体中,第一个最重要的是

typedef struct {

char *listen_addresses; /* hostnames/IP addresses to listen on */

int port; /* port # to bind */

int pcp_port; /* PCP port # to bind */

char *socket_dir; /* pgpool socket directory */

char *pcp_socket_dir; /* PCP socket directory */

int pcp_timeout; /* PCP timeout for an idle client */

int num_init_children; /* # of children initially pre-forked */

int child_life_time; /* if idle for this seconds,child exits */

int connection_life_time; /* if idle for this seconds,connection closes */

int child_max_connections; /* if max_connections received,child exits */

int client_idle_limit; /* If client_idle_limit is n (n > 0),the client is forced to be

disconnected after n seconds idle */

int authentication_timeout; /* maximum time in seconds to complete client authentication */

int max_pool; /* max # of connection pool per child */

char *logdir; /* logging directory */

char *pid_file_name; /* pid file name */

char *backend_socket_dir; /* Unix domain socket directory for the Postgresql server */

int replication_mode; /* replication mode */

int log_connections; /* 0:false,1:true - logs incoming connections */

int log_hostname; /* 0:false,1:true - resolve hostname */

int enable_pool_hba; /* 0:false,1:true - enables pool_hba.conf file authentication */

int load_balance_mode; /* load balance mode */

int replication_stop_on_mismatch; /* if there's a data mismatch between master and secondary

* start degenration to stop replication mode

*/

int replicate_select; /* if non 0,replicate SELECT statement when load balancing is disabled. */

char **reset_query_list; /* comma separated list of quries to be issued at the end of session */

int print_timestamp; /* if non 0,print time stamp to each log line */

int master_slave_mode; /* if non 0,operate in master/slave mode */

int connection_cache; /* if non 0,cache connection pool */

int health_check_timeout; /* health check timeout */

int health_check_period; /* health check period */

char *health_check_user; /* Postgresql user name for health check */

char *failover_command; /* execute command when failover happens */

char *failback_command; /* execute command when failback happens */

/*

* If true,trigger fail over when writing to the backend

* communication socket fails. This is the same behavior of

* pgpool-II 2.2.x or earlier. If set to false,pgpool will report

* an error and disconnect the session.

*/

int fail_over_on_backend_error;

char *recovery_user; /* Postgresql user name for online recovery */

char *recovery_password; /* Postgresql user password for online recovery */

char *recovery_1st_stage_command; /* Online recovery command in 1st stage */

char *recovery_2nd_stage_command; /* Online recovery command in 2nd stage */

int recovery_timeout; /* maximum time in seconds to wait for remote start-up */

int client_idle_limit_in_recovery; /* If > 0,the client is forced to be

* disconnected after n seconds idle

* This parameter is only valid while in recovery 2nd statge */

int insert_lock; /* if non 0,automatically lock table with INSERT to keep SERIAL

data consistency */

int ignore_leading_white_space; /* ignore leading white spaces of each query */

int log_statement; /* 0:false,1: true - logs all sql statements */

int log_per_node_statement; /* 0:false,1: true - logs per node detailed sql statements */

int parallel_mode; /* if non 0,run in parallel query mode */

int enable_query_cache; /* if non 0,use query cache. 0 by default */

char *pgpool2_hostname; /* pgpool2 hostname */

char *system_db_hostname; /* system DB hostname */

int system_db_port; /* system DB port number */

char *system_db_dbname; /* system DB name */

char *system_db_schema; /* system DB schema name */

char *system_db_user; /* user name to access system DB */

char *system_db_password; /* password to access system DB */

char *lobj_lock_table; /* table name to lock for rewriting lo_creat */

BackendDesc *backend_desc; /* Postgresql Server description. Placed on shared memory */

LOAD_BALANCE_STATUS load_balance_status[MAX_NUM_BACKENDS]; /* to remember which DB node is selected for load balancing */

/* followings do not exist in the configuration file */

int current_slot; /* current backend slot # */

int replication_enabled; /* replication mode enabled */

int master_slave_enabled; /* master/slave mode enabled */

int num_reset_queries; /* number of queries in reset_query_list */

/* ssl configuration */

int ssl; /* if non 0,activate ssl support (frontend+backend) */

char *ssl_cert; /* path to ssl certificate (frontend only) */

char *ssl_key; /* path to ssl key (frontend only) */

char *ssl_ca_cert; /* path to root (CA) certificate */

char *ssl_ca_cert_dir; /* path to directory containing CA certificates */

} POOL_CONFIG;

POOL_CONFIG里面保存了pgpool的配置信息,是从配置文件中读入的,这里面最重要的是BackendDesc *backend_desc,它里面保存了pgpool和数据库的连接信息,是放在共享内存中,供所有pgpool的child进程共享的。其余的字段看注释就可以了

每一个BackendInfo对应一个数据库连接,其实就是postgresql的一个进程

/*

* Postgresql backend descriptor. Placed on shared memory area.

*/

typedef struct {

char backend_hostname[MAX_DB_HOST_NAMELEN]; /* backend host name */

int backend_port; /* backend port numbers */

BACKEND_STATUS backend_status; /* backend status */

double backend_weight; /* normalized backend load balance ratio */

double unnormalized_weight; /* descripted parameter */

char backend_data_directory[MAX_PATH_LENGTH];

} BackendInfo;

typedef struct {int num_backends; /* number of used Postgresql backends */BackendInfo backend_info[MAX_NUM_BACKENDS];} BackendDesc;

相关文章

总结

以上是编程之家为你收集整理的pgpool分析二全部内容,希望文章能够帮你解决pgpool分析二所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

如您喜欢交流学习经验,点击链接加入交流1群:1065694478(已满)交流2群:163560250

pgpool mysql_pgpool分析二相关推荐

  1. 【Android 事件分发】ItemTouchHelper 源码分析 ( OnItemTouchListener 事件监听器源码分析 二 )

    Android 事件分发 系列文章目录 [Android 事件分发]事件分发源码分析 ( 驱动层通过中断传递事件 | WindowManagerService 向 View 层传递事件 ) [Andr ...

  2. Android4.0图库Gallery2代码分析(二) 数据管理和数据加载

    Android4.0图库Gallery2代码分析(二) 数据管理和数据加载 2012-09-07 11:19 8152人阅读 评论(12) 收藏 举报 代码分析android相册优化工作 Androi ...

  3. 一些有用的javascript实例分析(二)

    一些有用的javascript实例分析(二) 原文:一些有用的javascript实例分析(二) 1 5 求出数组中所有数字的和 2 window.onload = function () 3 { 4 ...

  4. Android 系统(41)---Android7.0 PowerManagerService亮灭屏分析(二)

    Android7.0 PowerManagerService亮灭屏分析(二) 3029 在PowerManagerService中对各种状态进行判断后,将其数值封装进DisplayPowerReque ...

  5. SpringBoot源码分析(二)之自动装配demo

    SpringBoot源码分析(二)之自动装配demo 文章目录 SpringBoot源码分析(二)之自动装配demo 前言 一.创建RedissonTemplate的Maven服务 二.创建测试服务 ...

  6. Linux MMC子系统分析(二)——Host分析

    Linux MMC子系统分析(二)--Host分析 前言 通过前面对mmc子系统的模型分析,我们能够知道host是对应于硬件控制器的具体操作.本文将以sdhci-s3c.c为例对host进行简单的分析 ...

  7. gSOAP 源码分析(二)

    gSOAP 源码分析(二) 2012-5-24 flyfish 一 gSOAP XML介绍 Xml的全称是EXtensible Markup Language.可扩展标记语言.仅仅是一个纯文本.适合用 ...

  8. Android Q 10.1 KeyMaster源码分析(二) - 各家方案的实现

    写在之前 这两篇文章是我2021年3月初看KeyMaster的笔记,本来打算等分析完KeyMaster和KeyStore以后再一起做成一系列贴出来,后来KeyStore的分析中断了,这一系列的文章就变 ...

  9. 威海二职工业机器人专业_工业机器人专业介绍和前景分析二

    原标题:工业机器人专业介绍和前景分析二 人才需求最旺最热门专业-工业机器人技术专业 工业机器人技术专业是经教育部批准成立的热点技术专业,.专业以"国家高职高专精品专业.国家示范高职的重点建设 ...

最新文章

  1. android 飞框动画,AndroidTV中实现飞框选中效果
  2. c语言逆序输出6A8F,【C语言】将二进制数逆序输出。比如6为000...0110,逆序后为0110....
  3. JS实现滚动监听以及滑动到顶部
  4. python怎么发图文_用Python发一封图文并茂的邮件
  5. SCOM2012SP1环境准备和安装
  6. ASP.NET MVC5+EF6+EasyUI 后台管理系统(65)-MVC WebApi 用户验证 (1)
  7. Weblogic之简介
  8. ad17如何删除3d实体_3D打印的过程/流程
  9. Atitit 数据与模板绑定法 目录 1.1. templet - 自定义列模板 1 1.2. 方式三:直接赋值模版字符。事实上,templet 也可以直接是一段 html 内容,如: 1 1.2.
  10. 如何设计企业特色的数字化转型架构?
  11. maya多边形建模怎样做曲面_maya中的曲面模型怎么转换成多边形?
  12. linux firefox 插件开发教程,火狐(firefox)浏览器插件开发简明教程
  13. Deepin 系统下安装VMware并激活.
  14. IEC 60664-1-2020【现行】低压供电系统内设备的绝缘配合第1部分:原则、要求和试验
  15. 常见测试概念-分级测试、灰度测试、AB测试
  16. Excel去除重复项的几种方法
  17. kafka connector使用(单机手动启动版)
  18. 什么是keep-alive?怎么去使用?简述keep-alive
  19. linux操作系统 第11章 linux系统管理
  20. Mac版DBeaver调整编辑窗口字体大小

热门文章

  1. 【Python 每日一技】文本查找和替换
  2. MySQL InnoDB MMCC**Mutil-Version Concurrency Control)
  3. 登录金蝶客户端,提示:无法创建账套检测部件,系统将无法检测你的账套是否完整
  4. Mysql,CASE WHEN 函数使用.
  5. 使用ksoap链接webservice,在3gwap和3gnet不同网络下不同
  6. Linux 管道符、重定向与通配符
  7. lisp 画双线带倒圆角_VisualLisp增加公差、消除重合直线圆弧
  8. iOS 常用代码之 UICollectionView
  9. Java正则表达式草稿程序*2
  10. Python-调试工具:pysnooper模块