127
122
int key; /* cancel key */
131
* configuration paramters
134
char *listen_addresses; /* hostnames/IP addresses to listen on */
135
int port; /* port # to bind */
136
int pcp_port; /* PCP port # to bind */
137
char *socket_dir; /* pgpool socket directory */
138
char *pcp_socket_dir; /* PCP socket directory */
139
int pcp_timeout; /* PCP timeout for an idle client */
140
int num_init_children; /* # of children initially pre-forked */
141
int child_life_time; /* if idle for this seconds, child exits */
142
int connection_life_time; /* if idle for this seconds, connection closes */
143
int child_max_connections; /* if max_connections received, child exits */
144
int client_idle_limit; /* If client_idle_limit is n (n > 0), the client is forced to be
145
disconnected after n seconds idle */
146
int authentication_timeout; /* maximum time in seconds to complete client authentication */
147
int max_pool; /* max # of connection pool per child */
148
char *logdir; /* logging directory */
149
char *pid_file_name; /* pid file name */
150
char *backend_socket_dir; /* Unix domain socket directory for the PostgreSQL server */
151
int replication_mode; /* replication mode */
153
int log_connections; /* 0:false, 1:true - logs incoming connections */
154
int log_hostname; /* 0:false, 1:true - resolve hostname */
155
int enable_pool_hba; /* 0:false, 1:true - enables pool_hba.conf file authentication */
157
int load_balance_mode; /* load balance mode */
159
int replication_stop_on_mismatch; /* if there's a data mismatch between master and secondary
160
* start degenration to stop replication mode
162
int replicate_select; /* if non 0, replicate SELECT statement when load balancing is disabled. */
163
char **reset_query_list; /* comma separated list of quries to be issued at the end of session */
165
int print_timestamp; /* if non 0, print time stamp to each log line */
166
int master_slave_mode; /* if non 0, operate in master/slave mode */
167
int connection_cache; /* if non 0, cache connection pool */
168
int health_check_timeout; /* health check timeout */
169
int health_check_period; /* health check period */
170
char *health_check_user; /* PostgreSQL user name for health check */
171
char *failover_command; /* execute command when failover happens */
172
char *failback_command; /* execute command when failback happens */
175
* If true, trigger fail over when writing to the backend
176
* communication socket fails. This is the same behavior of
177
* pgpool-II 2.2.x or earlier. If set to false, pgpool will report
178
* an error and disconnect the session.
180
int fail_over_on_backend_error;
182
char *recovery_user; /* PostgreSQL user name for online recovery */
183
char *recovery_password; /* PostgreSQL user password for online recovery */
184
char *recovery_1st_stage_command; /* Online recovery command in 1st stage */
185
char *recovery_2nd_stage_command; /* Online recovery command in 2nd stage */
186
int recovery_timeout; /* maximum time in seconds to wait for remote start-up */
187
int client_idle_limit_in_recovery; /* If > 0, the client is forced to be
188
* disconnected after n seconds idle
189
* This parameter is only valid while in recovery 2nd statge */
190
int insert_lock; /* if non 0, automatically lock table with INSERT to keep SERIAL
192
int ignore_leading_white_space; /* ignore leading white spaces of each query */
193
int log_statement; /* 0:false, 1: true - logs all SQL statements */
194
int log_per_node_statement; /* 0:false, 1: true - logs per node detailed SQL statements */
196
int parallel_mode; /* if non 0, run in parallel query mode */
198
int enable_query_cache; /* if non 0, use query cache. 0 by default */
200
char *pgpool2_hostname; /* pgpool2 hostname */
201
char *system_db_hostname; /* system DB hostname */
202
int system_db_port; /* system DB port number */
203
char *system_db_dbname; /* system DB name */
204
char *system_db_schema; /* system DB schema name */
205
char *system_db_user; /* user name to access system DB */
206
char *system_db_password; /* password to access system DB */
208
char *lobj_lock_table; /* table name to lock for rewriting lo_creat */
210
BackendDesc *backend_desc; /* PostgreSQL Server description. Placed on shared memory */
212
LOAD_BALANCE_STATUS load_balance_status[MAX_NUM_BACKENDS]; /* to remember which DB node is selected for load balancing */
214
/* followings do not exist in the configuration file */
215
int current_slot; /* current backend slot # */
216
int replication_enabled; /* replication mode enabled */
217
int master_slave_enabled; /* master/slave mode enabled */
218
int num_reset_queries; /* number of queries in reset_query_list */
220
/* ssl configuration */
221
int ssl; /* if non 0, activate ssl support (frontend+backend) */
222
char *ssl_cert; /* path to ssl certificate (frontend only) */
223
char *ssl_key; /* path to ssl key (frontend only) */
224
char *ssl_ca_cert; /* path to root (CA) certificate */
225
char *ssl_ca_cert_dir; /* path to directory containing CA certificates */
228
125
#define MAX_PASSWORD_SIZE 1024
347
* Relation cache structure
349
#define MAX_ITEM_LENGTH 1024
351
/* Relation lookup cache structure */
353
typedef void *(*func_ptr) ();
356
char dbname[MAX_ITEM_LENGTH]; /* database name */
357
char relname[MAX_ITEM_LENGTH]; /* table name */
358
void *data; /* user data */
359
int refcnt; /* reference count */
360
int session_id; /* LocalSessionId */
364
int num; /* number of cache items */
365
char sql[MAX_ITEM_LENGTH]; /* Query to relation */
367
* User defined function to be called at data register.
368
* Argument is POOL_SELECT_RESULT *.
369
* This function must return a pointer to be
370
* saved in cache->data.
372
func_ptr register_func;
374
* User defined function to be called at data unregister.
375
* Argument cache->data.
377
func_ptr unregister_func;
378
bool cache_is_session_local; /* True if cache life time is session local */
379
PoolRelCache *cache; /* cache data */
384
#define NUM_BACKENDS (in_load_balance? (selected_slot+1) : \
385
(((!REPLICATION && !PARALLEL_MODE)||master_slave_dml)? Req_info->master_node_id+1: \
386
pool_config->backend_desc->num_backends))
388
/* NUM_BACKENDS now always returns actual number of backends if not in_load_balance */
389
#define NUM_BACKENDS (in_load_balance ? (selected_slot+1) : pool_config->backend_desc->num_backends)
251
/* NUM_BACKENDS now always returns actual number of backends */
252
#define NUM_BACKENDS (pool_config->backend_desc->num_backends)
390
253
#define BACKEND_INFO(backend_id) (pool_config->backend_desc->backend_info[(backend_id)])
391
254
#define LOAD_BALANCE_STATUS(backend_id) (pool_config->load_balance_status[(backend_id)])
392
/* if RAW_MODE, VALID_BACKEND returns the selected node only */
257
* This macro returns true if:
258
* current query is in progress and the DB node is healthy OR
259
* no query is in progress and the DB node is healthy
261
extern bool pool_is_node_to_be_sent_in_current_query(int node_id);
262
extern int pool_virtual_master_db_node_id(void);
393
264
#define VALID_BACKEND(backend_id) \
394
(RAW_MODE ? (backend_id) == MASTER_NODE_ID : \
395
(in_load_balance ? LOAD_BALANCE_STATUS(backend_id) == LOAD_SELECTED : \
396
((BACKEND_INFO(backend_id).backend_status == CON_UP) || \
397
(BACKEND_INFO(backend_id).backend_status == CON_CONNECT_WAIT))))
265
((RAW_MODE && (backend_id) == REAL_MASTER_NODE_ID) || \
266
(pool_is_node_to_be_sent_in_current_query((backend_id)) && \
267
((BACKEND_INFO((backend_id)).backend_status == CON_UP) || \
268
(BACKEND_INFO((backend_id)).backend_status == CON_CONNECT_WAIT))))
398
270
#define CONNECTION_SLOT(p, slot) ((p)->slots[(slot)])
399
271
#define CONNECTION(p, slot) (CONNECTION_SLOT(p, slot)->con)
274
* The first DB ndoe id appears in pgpool.conf or the first "live" DB
277
#define REAL_MASTER_NODE_ID (Req_info->master_node_id)
280
* The primary node id in streaming replication mode. If not in the
281
* mode or there's no primary node, this macro returns
282
* REAL_MASTER_NODE_ID.
284
#define PRIMARY_NODE_ID (Req_info->primary_node_id >=0?\
285
Req_info->primary_node_id:REAL_MASTER_NODE_ID)
288
* Real primary node id. If not in the mode or there's no primary
289
* node, this macro returns -1.
291
#define REAL_PRIMARY_NODE_ID (Req_info->primary_node_id)
294
* "Virtual" master node id. It's same as REAL_MASTER_NODE_ID if not
295
* in load balance mode. If in load balance, it's the first load
298
#define MASTER_NODE_ID (pool_virtual_master_db_node_id())
299
#define IS_MASTER_NODE_ID(node_id) (MASTER_NODE_ID == (node_id))
400
300
#define MASTER_CONNECTION(p) ((p)->slots[MASTER_NODE_ID])
401
#define MASTER_NODE_ID (in_load_balance? selected_slot : Req_info->master_node_id)
402
#define IS_MASTER_NODE_ID(node_id) (MASTER_NODE_ID == (node_id))
403
//#define SECONDARY_CONNECTION(p) ((p)->slots[1])
404
#define REPLICATION (pool_config->replication_enabled)
405
#define MASTER_SLAVE (pool_config->master_slave_enabled)
301
#define MASTER(p) MASTER_CONNECTION(p)->con
303
#define REPLICATION (pool_config->replication_mode)
304
#define MASTER_SLAVE (pool_config->master_slave_mode)
406
305
#define DUAL_MODE (REPLICATION || MASTER_SLAVE)
407
306
#define PARALLEL_MODE (pool_config->parallel_mode)
408
307
#define RAW_MODE (!REPLICATION && !PARALLEL_MODE && !MASTER_SLAVE)
409
#define MASTER(p) MASTER_CONNECTION(p)->con
410
//#define SECONDARY(p) SECONDARY_CONNECTION(p)->con
411
308
#define MAJOR(p) MASTER_CONNECTION(p)->sp->major
412
#define TSTATE(p) MASTER(p)->tstate
309
#define TSTATE(p, i) (CONNECTION(p, i)->tstate)
310
#define INTERNAL_TRANSACTION_STARTED(p, i) (CONNECTION(p, i)->is_internal_transaction_started)
413
311
#define SYSDB_INFO (system_db_info->info)
414
312
#define SYSDB_CONNECTION (system_db_info->connection)
415
313
#define SYSDB_STATUS (*system_db_info->system_db_status)
483
380
* global variables
485
382
extern pid_t mypid; /* parent pid */
486
extern POOL_CONFIG *pool_config; /* configuration values */
383
extern bool run_as_pcp_child;
487
385
extern POOL_CONNECTION_POOL *pool_connection_pool; /* connection pool */
488
386
extern volatile sig_atomic_t backend_timer_expired; /* flag for connection closed timer is expired */
489
387
extern long int weight_master; /* normalized weight of master (0-RAND_MAX range) */
490
388
extern int my_proc_id; /* process table id (!= UNIX's PID) */
491
389
extern POOL_SYSTEMDB_CONNECTION_POOL *system_db_info; /* systemdb */
492
extern ProcessInfo *pids; /* shmem process information table */
390
extern ProcessInfo *process_info; /* shmem process information table */
493
391
extern ConnectionInfo *con_info; /* shmem connection info table */
494
extern int in_load_balance; /* non 0 if in load balance mode */
495
extern int selected_slot; /* selected DB node for load balance */
496
extern int master_slave_dml; /* non 0 if master/slave mode is specified in config file */
497
392
extern POOL_REQUEST_INFO *Req_info;
498
393
extern volatile sig_atomic_t *InRecovery;
499
394
extern char remote_ps_data[]; /* used for set_ps_display */
500
395
extern volatile sig_atomic_t got_sighup;
396
extern volatile sig_atomic_t exit_request;
502
398
#define QUERY_STRING_BUFFER_LEN 1024
503
399
extern char query_string_buffer[]; /* last query string sent to simpleQuery() */
505
extern int LocalSessionId; /* Local session id. incremented when new frontend connected */
508
402
* public functions
531
423
POOL_CONNECTION_POOL *backend,
532
424
int reset_request);
534
extern POOL_CONNECTION *pool_open(int fd);
535
extern void pool_close(POOL_CONNECTION *cp);
536
extern int pool_read(POOL_CONNECTION *cp, void *buf, int len);
537
extern char *pool_read2(POOL_CONNECTION *cp, int len);
538
extern int pool_write(POOL_CONNECTION *cp, void *buf, int len);
539
extern int pool_flush(POOL_CONNECTION *cp);
540
extern int pool_flush_it(POOL_CONNECTION *cp);
541
extern int pool_write_and_flush(POOL_CONNECTION *cp, void *buf, int len);
542
extern char *pool_read_string(POOL_CONNECTION *cp, int *len, int line);
543
extern int pool_unread(POOL_CONNECTION *cp, void *data, int len);
545
426
extern int pool_do_auth(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend);
546
427
extern int pool_do_reauth(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *cp);
548
extern int pool_init_cp(void);
549
extern POOL_CONNECTION_POOL *pool_create_cp(void);
550
extern POOL_CONNECTION_POOL *pool_get_cp(char *user, char *database, int protoMajor, int check_socket);
551
extern void pool_discard_cp(char *user, char *database, int protoMajor);
552
extern void pool_backend_timer(void);
554
429
/* SSL functionality */
555
430
extern void pool_ssl_negotiate_serverclient(POOL_CONNECTION *cp);
556
431
extern void pool_ssl_negotiate_clientserver(POOL_CONNECTION *cp);
557
432
extern void pool_ssl_close(POOL_CONNECTION *cp);
558
433
extern int pool_ssl_read(POOL_CONNECTION *cp, void *buf, int size);
559
434
extern int pool_ssl_write(POOL_CONNECTION *cp, const void *buf, int size);
435
extern bool pool_ssl_pending(POOL_CONNECTION *cp);
561
437
extern POOL_STATUS ErrorResponse(POOL_CONNECTION *frontend,
562
438
POOL_CONNECTION_POOL *backend);
699
570
char *query, int protoMajor, int pid, int key, int no_ready_for_query);
700
571
extern POOL_STATUS do_query(POOL_CONNECTION *backend, char *query, POOL_SELECT_RESULT **result, int major);
701
572
extern void free_select_result(POOL_SELECT_RESULT *result);
703
/* pool_relcache.c */
704
extern POOL_RELCACHE *pool_create_relcache(int cachesize, char *sql,
705
func_ptr register_func, func_ptr unregister_func,
706
bool issessionlocal);
707
extern void pool_discard_relcache(POOL_RELCACHE *relcache);
708
extern void *pool_search_relcache(POOL_RELCACHE *relcache, POOL_CONNECTION_POOL *backend, char *table);
709
extern void *int_register_func(POOL_SELECT_RESULT *res);
710
extern void *int_unregister_func(void *data);
713
extern char *pool_rewrite_lo_creat(char kind, char *packet, int packet_len, POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend, int* len);
573
extern int compare(const void *p1, const void *p2);
574
extern POOL_STATUS do_error_execute_command(POOL_CONNECTION_POOL *backend, int node_id, int major);
575
extern POOL_STATUS pool_discard_packet_contents(POOL_CONNECTION_POOL *cp);
578
extern void pool_random_salt(char *md5Salt);
581
extern void pool_sleep(unsigned int second);
583
/* pool_worker_child.c */
584
extern void do_worker_child(void);
587
extern bool pg_md5_encrypt(const char *passwd, const char *salt, size_t salt_len, char *buf);
589
/* pool_connection_pool.c */
590
extern int pool_init_cp(void);
591
extern POOL_CONNECTION_POOL *pool_create_cp(void);
592
extern POOL_CONNECTION_POOL *pool_get_cp(char *user, char *database, int protoMajor, int check_socket);
593
extern void pool_discard_cp(char *user, char *database, int protoMajor);
594
extern void pool_backend_timer(void);
595
extern void pool_connection_pool_timer(POOL_CONNECTION_POOL *backend);
596
extern RETSIGTYPE pool_backend_timer_handler(int sig);
597
extern int connect_inet_domain_socket(int slot, bool retry);
598
extern int connect_unix_domain_socket(int slot, bool retry);
599
extern int connect_inet_domain_socket_by_port(char *host, int port, bool retry);
600
extern int connect_unix_domain_socket_by_port(int port, char *socket_dir, bool retry);
601
extern int pool_pool_index(void);
715
603
#endif /* POOL_H */