pgpool如何对数据库节点进行状态检查及相关数据结构描述
/*
* configuration parameters
*/
typedef struct {
char *listen_addresses; /* hostnames/IP addresses to listen on */
int port; /* port # to bind */
char *pcp_listen_addresses; /* PCP listen address to listen on */
int pcp_port; /* PCP port # to bind */
char *socket_dir; /* pgpool socket directory */
char *wd_ipc_socket_dir; /* watchdog command IPC socket directory */
char *pcp_socket_dir; /* PCP socket directory */
int num_init_children; /* # of children initially pre-forked */
int listen_backlog_multiplier; /* determines the size of the connection queue */
bool serialize_accept; /* if non 0, serialize call to accept() to avoid thundering herd problem */
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 *log_destination; /* log destination: stderr or syslog */
int syslog_facility; /* syslog facility: LOCAL0, LOCAL1, ... */
char *syslog_ident; /* syslog ident string: pgpool */
char *pid_file_name; /* pid file name */
bool replication_mode; /* replication mode */
bool log_connections; /* logs incoming connections */
bool log_hostname; /* resolve hostname */
bool enable_pool_hba; /* enables pool_hba.conf file authentication */
char *pool_passwd; /* pool_passwd file name. "" disables pool_passwd */
bool load_balance_mode; /* load balance mode */
bool replication_stop_on_mismatch; /* if there's a data mismatch between master and secondary
* start degeneration to stop replication mode
*/
bool failover_if_affected_tuples_mismatch; /* If there's a disagreement with the number of affected tuples in
* UPDATE/DELETE, then degenerate the node which is most likely
* "minority". # If false, just abort the transaction to keep the
* consistency.
*/
bool replicate_select; /* replicate SELECT statement when load balancing is disabled. */
char **reset_query_list; /* comma separated list of queries to be issued at the end of session */
char **white_function_list; /* list of functions with no side effects */
char **black_function_list; /* list of functions with side effects */
char *log_line_prefix; /* printf-style string to output at beginning of each log line */
int log_error_verbosity; /* controls how much detail about error should be emitted */
int client_min_messages; /* controls which message should be sent to client */
int log_min_messages; /* controls which message should be emitted to server log */
bool master_slave_mode; /* operate in master/slave mode */
MasterSlaveSubModes master_slave_sub_mode; /* either "slony" or "stream" */
int64 delay_threshold; /* If the standby server delays more than delay_threshold,
* any query goes to the primary only. The unit is in bytes.
* 0 disables the check. Default is 0.
* Note that health_check_period required to be greater than 0
* to enable the functionality.
*/
LogStandbyDelayModes log_standby_delay; /* how to log standby lag */
bool connection_cache; /* 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 *health_check_password; /* password for health check username */
char *health_check_database; /* database name for health check username */
int health_check_max_retries; /* health check max retries */
int health_check_retry_delay; /* amount of time to wait between retries */
int connect_timeout; /* timeout value before giving up connecting to backend */
int sr_check_period; /* streaming replication check period */
char *sr_check_user; /* PostgreSQL user name for streaming replication check */
char *sr_check_password; /* password for sr_check_user */
char *sr_check_database; /* PostgreSQL database name for streaming replication check */
char *failover_command; /* execute command when failover happens */
char *follow_master_command; /* execute command when failover is ended */
char *failback_command; /* execute command when failback happens */
bool fail_over_on_backend_error; /* 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.
*/
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 search_primary_node_timeout; /* maximum time in seconds to search for new primary
* node after failover
*/
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 stage
*/
bool insert_lock; /* automatically locking of table with INSERT to keep SERIAL data consistency?
*/
bool ignore_leading_white_space; /* ignore leading white spaces of each query */
bool log_statement; /* logs all SQL statements */
bool log_per_node_statement; /* logs per node detailed SQL statements */
char *lobj_lock_table; /* table name to lock for rewriting lo_creat */
int debug_level; /* debug message verbosity level.
* 0: no message, 1 <= : more verbose
*/
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 till syslog, does not exist in the configuration file */
int num_reset_queries; /* number of queries in reset_query_list */
int num_white_function_list; /* number of functions in white_function_list */
int num_black_function_list; /* number of functions in black_function_list */
int num_white_memqcache_table_list; /* number of functions in white_memqcache_table_list */
int num_black_memqcache_table_list; /* number of functions in black_memqcache_table_list */
int num_wd_monitoring_interfaces_list; /* number of items in wd_monitoring_interfaces_list */
int logsyslog; /* flag used to start logging to syslog */
/* ssl configuration */
bool 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 */
int64 relcache_expire; /* relation cache life time in seconds */
int relcache_size; /* number of relation cache life entry */
bool check_temp_table; /* enable temporary table check */
bool check_unlogged_table; /* enable unlogged table check */
/* followings are for regex support and do not exist in the configuration file */
RegPattern *lists_patterns; /* Precompiled regex patterns for black/white lists */
int pattc; /* number of regexp pattern */
int current_pattern_size; /* size of the regex pattern array */
bool memory_cache_enabled; /* if true, use the memory cache functionality, false by default */
MemCacheMethod memqcache_method; /* Cache store method. Either 'shmem'(shared memory) or 'memcached'. 'shmem' by default */
char *memqcache_memcached_host; /* Memcached host name. Mandatory if memqcache_method=memcached. */
int memqcache_memcached_port; /* Memcached port number. Mandatory if memqcache_method=memcached. */
int64 memqcache_total_size; /* Total memory size in bytes for storing memory cache. Mandatory if memqcache_method=shmem. */
int memqcache_max_num_cache; /* Total number of cache entries. Mandatory if memqcache_method=shmem. */
int memqcache_expire; /* Memory cache entry life time specified in seconds. 60 by default. */
bool memqcache_auto_cache_invalidation; /* If true, invalidation of query cache is triggered by corresponding */
/* DDL/DML/DCL(and memqcache_expire). If false, it is only triggered */
/* by memqcache_expire. True by default. */
int memqcache_maxcache; /* Maximum SELECT result size in bytes. */
int memqcache_cache_block_size; /* Cache block size in bytes. 8192 by default */
char *memqcache_oiddir; /* Temporary work directory to record table oids */
char **white_memqcache_table_list; /* list of tables to memqcache */
char **black_memqcache_table_list; /* list of tables not to memqcache */
RegPattern *lists_memqcache_table_patterns; /* Precompiled regex patterns for black/white lists */
int memqcache_table_pattc; /* number of regexp pattern */
int current_memqcache_table_pattern_size; /* size of the regex pattern array */
/*
* database_redirect_preference_list = 'postgres:primary,mydb[0-4]:1,mydb[5-9]:2'
*/
char *database_redirect_preference_list; /* raw string in pgpool.conf */
RegArray *redirect_dbnames; /* Precompiled regex patterns for db prefrence list */
Left_right_tokens *db_redirect_tokens; /* db redirect for dbname and node string */
/*
* app_name_redirect_preference_list = 'psql:primary,myapp[0-4]:1,myapp[5-9]:standby'
*/
char *app_name_redirect_preference_list; /* raw string in pgpool.conf */
RegArray *redirect_app_names; /* Precompiled regex patterns for app name prefrence list */
Left_right_tokens *app_name_redirect_tokens;/* app name redirect for app_name and node string */
bool allow_sql_comments; /* if on, ignore SQL comments when judging if load balance or query cache
* is possible. If off, SQL comments effectively prevent the judgment
* (pre 3.4 behavior). For backward compatibilty sake, default is off.
*/
/*
* add for watchdog
*/
bool use_watchdog; /* Enables watchdog */
WdLifeCheckMethod wd_lifecheck_method; /* method of lifecheck. 'heartbeat' or 'query' */
bool clear_memqcache_on_escalation; /* Clear query cache on shmem when escalating ?*/
char *wd_escalation_command; /* Executes this command at escalation on new active pgpool.*/
char *wd_de_escalation_command; /* Executes this command when master pgpool goes down.*/
char *wd_hostname; /* watchdog hostname */
int wd_port; /* watchdog port */
int wd_priority; /* watchdog node priority, during leader election*/
WdRemoteNodesConfig wd_remote_nodes; /* watchdog lists */
char * trusted_servers; /* icmp reachable server list (A,B,C) */
char * delegate_IP; /* delegate IP address */
int wd_interval; /* lifecheck interval (sec) */
char *wd_authkey; /* Authentication key for watchdog communication */
char * ping_path; /* path to ping command */
char * if_cmd_path; /* path to interface up/down command */
char * if_up_cmd; /* ifup command */
char * if_down_cmd; /* ifdown command */
char * arping_path; /* path to arping command */
char * arping_cmd; /* arping command */
int wd_life_point; /* life point (retry times at lifecheck) */
char *wd_lifecheck_query; /* lifecheck query */
char *wd_lifecheck_dbname; /* Database name connected for lifecheck */
char *wd_lifecheck_user; /* PostgreSQL user name for watchdog */
char *wd_lifecheck_password; /* password for watchdog user */
int wd_heartbeat_port; /* Port number for heartbeat lifecheck */
int wd_heartbeat_keepalive; /* Interval time of sending heartbeat signal (sec) */
int wd_heartbeat_deadtime; /* Deadtime interval for heartbeat signal (sec) */
WdHbIf hb_if[WD_MAX_IF_NUM]; /* interface devices */
int num_hb_if; /* number of interface devices */
char **wd_monitoring_interfaces_list; /* network interface name list to be monitored by watchdog */
} POOL_CONFIG;
BackendDesc *backend_desc;
typedef struct {
sig_atomic_t num_backends; /* Number of used PostgreSQL backends.
* This needs to be a sig_atomic_t type
* since it is replaced by a local
* variable while reloading pgpool.conf.
*/
BackendInfo backend_info[MAX_NUM_BACKENDS];
} BackendDesc;
/*
* 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];
unsigned short flag; /* various flags */
unsigned long long int standby_delay; /* The replication delay against the primary */
} BackendInfo;
/*
* get node information specified by node_number
*/
BackendInfo *
pool_get_node_info(int node_number)
{
if (node_number < 0 || node_number >= NUM_BACKENDS)
return NULL;
return &BACKEND_INFO(node_number);
}
#define BACKEND_INFO(backend_id) (pool_config->backend_desc->backend_info[(backend_id)])
POOL_CONFIG *pool_config = &_pool_config;
/*
* do_health_check() performs the health check on all backend nodes.
* The inout parameter health_check_node_id is the starting backend
* node number for health check and when the function returns or
* exits with an error health_check_node_id contains the value
* of last backend node number on which health check was performed.
*
* Function returns false if all backend nodes are down and true if all
* backend nodes are in healthy state
*/
static bool
do_health_check(bool use_template_db, volatile int *health_check_node_id)
{
POOL_CONNECTION_POOL_SLOT *slot;
BackendInfo *bkinfo;
static char *dbname;
int i;
bool all_nodes_healthy = false;
/* Do not execute health check during recovery */
if (*InRecovery)
return false;
if (!strcmp(pool_config->health_check_database, ""))
dbname = use_template_db ? "template1" : "postgres";
else
dbname = pool_config->health_check_database;
ereport(DEBUG1,
(errmsg("doing health check against database:%s user:%s",
dbname, pool_config->health_check_user)));
/*
* Start checking the backed nodes starting from the
* previously failed node
*/
for (i=*health_check_node_id;i<pool_config->backend_desc->num_backends;i++)
{
*health_check_node_id = i;
/*
* Make sure that health check timer has not been expired.
* Before called health_check(), health_check_timer_expired is
* set to 0. However it is possible that while processing DB
* nodes health check timer expired.
*/
if (health_check_timer_expired)
{
ereport(ERROR,
(errmsg("health check timer has been already expired before attempting to connect backend node %d", i)));
}
bkinfo = pool_get_node_info(i);
ereport(DEBUG1,
(errmsg("Backend DB node %d status is %d", i, bkinfo->backend_status)));
if (bkinfo->backend_status == CON_UNUSED ||
bkinfo->backend_status == CON_DOWN)
continue;
all_nodes_healthy = true;
ereport(DEBUG1,
(errmsg("Trying to make persistent DB connection to backend node %d having status %d", i, bkinfo->backend_status)));
slot = make_persistent_db_connection(bkinfo->backend_hostname,
bkinfo->backend_port,
dbname,
pool_config->health_check_user,
pool_config->health_check_password, false);
ereport(DEBUG1,
(errmsg("persistent DB connection to backend node %d having status %d is successful", i, bkinfo->backend_status)));
discard_persistent_db_connection(slot);
}
return all_nodes_healthy;
}
pgpool如何对数据库节点进行状态检查及相关数据结构描述的更多相关文章
- oracle dg状态检查及相关命令
oracle dg 状态检查 先检查备库的归档日志同步情况 SELECT NAME,applied FROM v$archived_log; alter database recover manage ...
- linux shell mysql 数据库主从同步状态检查告警
需求: 1.监测数据库主从状态 2.获取数据库主要参数 3.可读取配置文件 4.部署位置自适应. 参考资料: http://blog.csdn.net/yf210yf/article/detail ...
- ES 内存使用和GC指标——主节点每30秒会去检查其他节点的状态,如果任何节点的垃圾回收时间超过30秒(Garbage collection duration),则会导致主节点任务该节点脱离集群。
摘录自:http://blog.csdn.net/yangwenbo214/article/details/74000458 内存使用和GC指标 在运行Elasticsearch时,内存是您要密切监控 ...
- Eureka心跳健康检查机制和Spring boot admin 节点状态一直为DOWN的排查(忽略某一个节点的健康检查)
https://www.jdon.com/springcloud/eureka-health-monitoring.html 运行阶段执行健康检查的目的是为了从Eureka服务器注册表中识别并删除不可 ...
- Nginx负载均衡中后端节点服务器健康检查的操作梳理
正常情况下,nginx做反向代理,如果后端节点服务器宕掉的话,nginx默认是不能把这台realserver踢出upstream负载集群的,所以还会有请求转发到后端的这台realserver上面,这样 ...
- Nginx负载均衡中后端节点服务器健康检查的一种简单方式
摘自:https://cloud.tencent.com/developer/article/1027287 一.利用nginx自带模块ngx_http_proxy_module和ngx_http_u ...
- Memcache 内存分配策略和性能(使用)状态检查【转】
前言: 一直在使用Memcache,但是对其内部的问题,如它内存是怎么样被使用的,使用一段时间后想看看一些状态怎么样?一直都不清楚,查了又忘记,现在整理出该篇文章,方便自己查阅.本文不涉及安装.操作. ...
- Tengine笔记3:Nginx的反向代理和健康状态检查
通常代理服务器只用于处理内部网络对Intenet的请求,客户端必须通过代理服务器把本来要发送到Web服务器上的请求通过代理服务器分发给Web服务器,Web服务器响应时再通过代理服务器把响应发给客户端: ...
- linux系统负载状态检查脚本
为了便于分析问题,编写了一个linux状态检查脚本,脚本可放置任意目录,脚本执行检测后会输出日志记录到当前目录下.直接执行脚本可用于一次检测,可通过日志进行分析.如果需要长时间监测,可执行-x参数,脚 ...
随机推荐
- 杭电 1012 u Calculate e【算阶乘】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1012 解题思路:对阶乘递归求和 反思:前面3个的输出格式需要注意,可以自己单独打印出来,也可以在for ...
- 我的C++笔记(语句基本结构)
#include <iostream> using namespace std; int main() { unsigned char c1=24; int year; bool isLe ...
- gulp打包压缩代码以及图片
1.首先全局安装gulp 全局安装就不做介绍了 初学gulp,终于把常用的配置,api,语法弄明白了! gulp插件地址:http://gulpjs.com/plugins gulp官方网址:http ...
- Java中 对象的创建于调用
Main方法是程序的主入口,想要用某个方法必须在main方法中调用 创建对象: 类名 对象名 = new 类名(); 使用对象访问类中的成员: 对象名.成员变量: 对象名.成员方法(); 成员变量的默 ...
- 远程连接windows出现身份验证错误,提示"由于CredSSP加密Oracle修正"解决方案
本机操作系统(OS版本:10.0.17134) 远程计算机操作系统(OS版本:6.3.9600) 远程连接的时候报错“出现身份验证错误,要求的函数不受支持.远程计算机:xxx 这可能是由于CredSS ...
- 在fedora「27」下,安装mysql 问题总结
有时会出现,没有mysql.sock,不存在的问题, Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. ...
- BZOJ 1266: [AHOI2006]上学路线route Floyd_最小割
十分简单的一道题. 图这么小,跑一边 Floyd 就得到第一问最短路径的答案. 考虑第二问怎么求:我们可以先将最短路径组成的图从原图中抽离出来,构成新图 $G$. 我们发现,只要 $G$ 的起点与终点 ...
- 路飞学城Python-Day171
Evernote Export 线性结构: python的列表操作 列表是如何存储的:顺序存储的,是一块连续的内存,内存是一堆格子,列表是一串连续的编号 32位机器上一个整数占4个字节 数组和列表有2 ...
- 【airtest】报错:requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer')),解决方法如下
1. 环境及设备:mac, xcode , iphonex 2. 最近出现一个让人费解的问题,airtest 没跑多长时间,服务就断掉,而且总是报“requests.exceptions.Connec ...
- 发现被坑了,从来没看到说java的Date一旦实例化时间就不会变了
java中使用Date对象获取系统当前时间,然而我就没看到哪篇教程告诉我说Date创建对象之后其中的时间是不会变的!!! 一开始我写了类似于下边这样的代码,希望每隔一段时间显示一次时间 Date d= ...