pgpool一共可以管理pool_config->num_init_children * pool_config->max_pool * sizeof(ConnectionInfo);数据库连接
每个pool_config->num_init_children 对应pgpool的一个child进程,也就是对应一台postgresql数据库,这个进程最多可以管理pool_config->max_pool个对数据库的连接
/*
* Connection pool information. Placed on shared memory area.
*/
typedef struct {
char database[SM_DATABASE]; /* Database name */
char user[SM_USER]; /* User name */
int major; /* protocol major version */
int minor; /* protocol minor version */
int pid; /* backend process id */
int key; /* cancel key */
int counter; /* used counter */
time_t create_time; /* connection creation time */
int load_balancing_node; /* load balancing node */
} ConnectionInfo;
每个child进程保存在共享内存中的信息
/*
* process information
* This object put on shared memory.
*/
typedef struct {
pid_t pid; /* OS's process id */
time_t start_time; /* fork() time */
ConnectionInfo *connection_info; /* head of the connection info for this process,指向共享内存中的 i * pool_config->max_pool处, */
} ProcessInfo;
以上两个结构是在main进程中初始化,放入共享内存的,对于每一个child进行的连接池
pool_connection_pool = (POOL_CONNECTION_POOL *)malloc(sizeof(POOL_CONNECTION_POOL)*pool_config->max_pool);
typedef struct {
ConnectionInfo *info; /* connection info on shmem ,指向ProcessInfo->connection_info,从那开始的max_pool个*/
POOL_CONNECTION_POOL_SLOT *slots[MAX_NUM_BACKENDS];
} POOL_CONNECTION_POOL;
typedef struct {
StartupPacket *sp; /* startup packet info 估计是postgresql的通训协议中要用到的*/
int pid; /* backend pid */
int key; /* cancel key */
POOL_CONNECTION *con;
time_t closetime; /* absolute time in second when the connection closed
* if 0,that means the connection is under use.
*/
} POOL_CONNECTION_POOL_SLOT;
/*
* stream connection structure
*/
typedef struct {
int fd; /* fd for connection 直正连接socket,可以是unix domain socket或是inet domain socket */
char *wbuf; /* write buffer for the connection */
int wbufsz; /* write buffer size */
int wbufpo; /* buffer offset */
#ifdef USE_SSL
SSL_CTX *ssl_ctx; /* SSL connection context */
SSL *ssl; /* SSL connection */
#endif
int ssl_active; /* SSL is Failed if < 0,off if 0,on if > 0 */
char *hp; /* pending data buffer head address */
int po; /* pending data offset */
int bufsz; /* pending data buffer size */
int len; /* pending data length */
char *sbuf; /* buffer for pool_read_string */
int sbufsz; /* its size in bytes */
char *buf2; /* buffer for pool_read2 */
int bufsz2; /* its size in bytes */
int isbackend; /* this connection is for backend if non 0 */
int db_node_id; /* DB node id for this connection */
char tstate; /* transaction state (V3 only) */
/*
* following are used to remember when re-use the authenticated connection
*/
int auth_kind; /* 3: clear text password,4: crypt password,5: md5 password */
int pwd_size; /* password (sent back from frontend) size in host order */
char password[MAX_PASSWORD_SIZE]; /* password (sent back from frontend) */
char salt[4]; /* password salt */
/*
* following are used to remember current session paramter status.
* re-used connection will need them (V3 only)
*/
ParamStatus params;
int no_forward; /* if non 0,do not write to frontend */
char kind; /* kind cache */
/*
* frontend info needed for hba
*/
int protoVersion;
SockAddr raddr;
UserAuth auth_method;
char *auth_arg;
char *database;
char *username;
} POOL_CONNECTION;
POOL_CONNECTION主要是在socket连接之间缓存的作用,socket写入时先写入wbuf,读入也是先读进rbuf中,之后需要的时候再解析
原文链接:https://www.f2er.com/postgresql/197103.html