一.部署说明

1.1 实施环境

本文档实验环境如下:

PGSQL主机: 192.168.1.45

PGSQL备机: 192.168.1.50

软件和系统版本

Pgsql 版本: pgsql 9.2.4

Linux 版本: Redhat 5.8

pgpool版本:pgpool-II version 3.3.4 (tokakiboshi)

1.2 文档说明  

  在postgresql 的stream replication配置一文我们实现了postgresql的stream replication,实现了postgresql的热备。而实际生产中集群的目的之一就是负载均衡。那我们系统为例,刚开始java程序需要修改数据源,将查询的压力分担给从机,对数据的修改设置为主机。但是这种方式不灵活,负载不能均衡,并且比较麻烦。所以如果此时有一个路由控制器多好,可以根据请求将请求分发给不同的数据库。刚好,pgpoool就是这么一个中间件,负责与数据库集群交互,对外提供统一的访问接口,使得程序对数据库的访问变得简单,提高整个系统的性能。本文主要配置pgpool的负载均衡,是在上篇博文:PostgreSQL的HA解决方案-1主从和备份(master/slave and backup) 的基础之上配置的。

  为了试验减少不必要的麻烦,本系列试验中,各个主机之间的通信,都是设置为无密码访问,且关闭主从的防火墙,但对于实际生产,需要根据实际需要,配置密码,增强集群的安全性。

二.配置步骤

  1.1 源码安装pgpool。参考中文手册:http://pgpool.projects.pgfoundry.org/pgpool-II/doc/pgpool-zh_cn.html#install

  1.2 安装pgpool中提供的工具。安装 pgpool_regclass。注意 pgpool_regclass是在你解压pgpool后的目录中的sql目录下,而不是你的安装目录。

    pgpool_regclass主要作用是,方便在数据库查询中,查询关于pgpool的的配置参数,监控信息等,请仔细阅读中文手册。应在在每台通过 pgpool-II 访问的数据库中执行 pgpool-regclass.sql。你不需要在你执行“psql -f pgpool-regclass.sql template1”后建立的数据库中这么做,因为这个模板数据库将被克隆成新建的数据库。

  1. cd pgpool-II-x.x.x/sql/pgpool-regclass
  2. make
  3. make install
  4. psql -f pgpool-regclass.sql template1

    安装之后,再在/usr/local/pgsql/share/extension/目录下多出如下文件:

  1. -rw-r--r-- root root Sep : pgpool_regclass.control
  2. -rw-r--r-- root root Sep : pgpool_regclass--1.0.sql
  3. -rw-r--r-- root root Sep : pgpool-regclass.sql

  1.3 配置pgpool的配置文件。

  主要配置:

  1. listen_addresses="*"
  2. port=
  3. backend_hostname0="localhost"
  4. backend_port0=""
  5. backend_weight0=
  6. backend_hostname1="192.168.57.175"
  7. backend_port1=""
  8. backend_weight1=
  9. replication_mode=off
  10. load_balance_mode=on
  11. master_slave_mode=on
  12. master_save_sub_mode="stream"
  13. parallel_mode=off

详细配置:

  1. # ----------------------------
  2. # pgPool-II configuration file
  3. # ----------------------------
  4. #
  5. # This file consists of lines of the form:
  6. #
  7. # name = value
  8. #
  9. # Whitespace may be used. Comments are introduced with "#" anywhere on a line.
  10. # The complete list of parameter names and allowed values can be found in the
  11. # pgPool-II documentation.
  12. #
  13. # This file is read on server startup and when the server receives a SIGHUP
  14. # signal. If you edit the file on a running system, you have to SIGHUP the
  15. # server for the changes to take effect, or use "pgpool reload". Some
  16. # parameters, which are marked below, require a server shutdown and restart to
  17. # take effect.
  18. #
  19.  
  20. #------------------------------------------------------------------------------
  21. # CONNECTIONS
  22. #------------------------------------------------------------------------------
  23.  
  24. # - pgpool Connection Settings -
  25.  
  26. #listen_addresses = 'localhost'
  27. listen_addresses = '*'
  28. # Host name or IP address to listen on:
  29. # '*' for all, '' for no TCP/IP connections
  30. # (change requires restart)
  31. port =
  32. # Port number
  33. # (change requires restart)
  34. socket_dir = '/tmp'
  35. # Unix domain socket path
  36. # The Debian package defaults to
  37. # /var/run/postgresql
  38. # (change requires restart)
  39.  
  40. # - pgpool Communication Manager Connection Settings -
  41.  
  42. pcp_port =
  43. # Port number for pcp
  44. # (change requires restart)
  45. pcp_socket_dir = '/tmp'
  46. # Unix domain socket path for pcp
  47. # The Debian package defaults to
  48. # /var/run/postgresql
  49. # (change requires restart)
  50.  
  51. # - Backend Connection Settings -
  52.  
  53. #backend_hostname0 = 'host1'
  54. backend_hostname0 = '192.168.1.45'
  55. # Host name or IP address to connect to for backend
  56. backend_port0 =
  57. # Port number for backend
  58. backend_weight0 =
  59. # Weight for backend (only in load balancing mode)
  60. #backend_data_directory0 = '/data'
  61. # Data directory for backend
  62. backend_flag0 = 'ALLOW_TO_FAILOVER'
  63. # Controls various backend behavior
  64. # ALLOW_TO_FAILOVER or DISALLOW_TO_FAILOVER
  65. backend_hostname1 = '192.168.1.50'
  66. backend_port1 =
  67. backend_weight1 =
  68. #backend_data_directory1 = '/data1'
  69. backend_flag1 = 'ALLOW_TO_FAILOVER'
  70.  
  71. # - Authentication -
  72.  
  73. enable_pool_hba = on
  74. # Use pool_hba.conf for client authentication
  75. pool_passwd = 'pool_passwd'
  76. # File name of pool_passwd for md5 authentication.
  77. # "" disables pool_passwd.
  78. # (change requires restart)
  79. authentication_timeout =
  80. # Delay in seconds to complete client authentication
  81. # means no timeout.
  82.  
  83. # - SSL Connections -
  84.  
  85. ssl = off
  86. # Enable SSL support
  87. # (change requires restart)
  88. #ssl_key = './server.key'
  89. # Path to the SSL private key file
  90. # (change requires restart)
  91. #ssl_cert = './server.cert'
  92. # Path to the SSL public certificate file
  93. # (change requires restart)
  94. #ssl_ca_cert = ''
  95. # Path to a single PEM format file
  96. # containing CA root certificate(s)
  97. # (change requires restart)
  98. #ssl_ca_cert_dir = ''
  99. # Directory containing CA root certificate(s)
  100. # (change requires restart)
  101.  
  102. #------------------------------------------------------------------------------
  103. # POOLS
  104. #------------------------------------------------------------------------------
  105.  
  106. # - Pool size -
  107.  
  108. num_init_children =
  109. # Number of pools
  110. # (change requires restart)
  111. max_pool =
  112. # Number of connections per pool
  113. # (change requires restart)
  114.  
  115. # - Life time -
  116.  
  117. child_life_time =
  118. # Pool exits after being idle for this many seconds
  119. child_max_connections =
  120. # Pool exits after receiving that many connections
  121. # means no exit
  122. connection_life_time =
  123. # Connection to backend closes after being idle for this many seconds
  124. # means no close
  125. client_idle_limit =
  126. # Client is disconnected after being idle for that many seconds
  127. # (even inside an explicit transactions!)
  128. # means no disconnection
  129.  
  130. #------------------------------------------------------------------------------
  131. # LOGS
  132. #------------------------------------------------------------------------------
  133.  
  134. # - Where to log -
  135.  
  136. log_destination = 'stderr'
  137. # Where to log
  138. # Valid values are combinations of stderr,
  139. # and syslog. Default to stderr.
  140.  
  141. # - What to log -
  142.  
  143. print_timestamp = on
  144. # Print timestamp on each line
  145. # (change requires restart)
  146.  
  147. log_connections = on
  148. # Log connections
  149. log_hostname = on
  150. # Hostname will be shown in ps status
  151. # and in logs if connections are logged
  152. log_statement = on
  153. # Log all statements
  154. log_per_node_statement = off
  155. # Log all statements
  156. # with node and backend informations
  157. log_standby_delay = 'none'
  158. # Log standby delay
  159. # Valid values are combinations of always,
  160. # if_over_threshold, none
  161.  
  162. # - Syslog specific -
  163.  
  164. syslog_facility = 'LOCAL0'
  165. # Syslog local facility. Default to LOCAL0
  166. syslog_ident = 'pgpool'
  167. # Syslog program identification string
  168. # Default to 'pgpool'
  169.  
  170. # - Debug -
  171.  
  172. debug_level =
  173. # Debug message verbosity level
  174. # means no message, or more mean verbose
  175.  
  176. #------------------------------------------------------------------------------
  177. # FILE LOCATIONS
  178. #------------------------------------------------------------------------------
  179.  
  180. pid_file_name = '/var/run/pgpool/pgpool.pid'
  181. # PID file name
  182. # (change requires restart)
  183. logdir = '/tmp'
  184. # Directory of pgPool status file
  185. # (change requires restart)
  186.  
  187. #------------------------------------------------------------------------------
  188. # CONNECTION POOLING
  189. #------------------------------------------------------------------------------
  190.  
  191. connection_cache = on
  192. # Activate connection pools
  193. # (change requires restart)
  194.  
  195. # Semicolon separated list of queries
  196. # to be issued at the end of a session
  197. # The default is for 8.3 and later
  198. reset_query_list = 'ABORT; DISCARD ALL'
  199. # The following one is for 8.2 and before
  200. #reset_query_list = 'ABORT; RESET ALL; SET SESSION AUTHORIZATION DEFAULT'
  201.  
  202. #------------------------------------------------------------------------------
  203. # REPLICATION MODE
  204. #------------------------------------------------------------------------------
  205.  
  206. replication_mode = off
  207. # Activate replication mode
  208. # (change requires restart)
  209. replicate_select = off
  210. # Replicate SELECT statements
  211. # when in replication or parallel mode
  212. # replicate_select is higher priority than
  213. # load_balance_mode.
  214.  
  215. insert_lock = on
  216. # Automatically locks a dummy row or a table
  217. # with INSERT statements to keep SERIAL data
  218. # consistency
  219. # Without SERIAL, no lock will be issued
  220. lobj_lock_table = ''
  221. # When rewriting lo_creat command in
  222. # replication mode, specify table name to
  223. # lock
  224.  
  225. # - Degenerate handling -
  226.  
  227. replication_stop_on_mismatch = off
  228. # On disagreement with the packet kind
  229. # sent from backend, degenerate the node
  230. # which is most likely "minority"
  231. # If off, just force to exit this session
  232.  
  233. failover_if_affected_tuples_mismatch = off
  234. # On disagreement with the number of affected
  235. # tuples in UPDATE/DELETE queries, then
  236. # degenerate the node which is most likely
  237. # "minority".
  238. # If off, just abort the transaction to
  239. # keep the consistency
  240.  
  241. #------------------------------------------------------------------------------
  242. # LOAD BALANCING MODE
  243. #------------------------------------------------------------------------------
  244.  
  245. load_balance_mode = on
  246. # Activate load balancing mode
  247. # (change requires restart)
  248. ignore_leading_white_space = on
  249. # Ignore leading white spaces of each query
  250. white_function_list = ''
  251. # Comma separated list of function names
  252. # that don't write to database
  253. # Regexp are accepted
  254. black_function_list = 'nextval,setval'
  255. # Comma separated list of function names
  256. # that write to database
  257. # Regexp are accepted
  258.  
  259. #------------------------------------------------------------------------------
  260. # MASTER/SLAVE MODE
  261. #------------------------------------------------------------------------------
  262.  
  263. master_slave_mode = on
  264. # Activate master/slave mode
  265. # (change requires restart)
  266. master_slave_sub_mode = 'stream'
  267. # Master/slave sub mode
  268. # Valid values are combinations slony or
  269. # stream. Default is slony.
  270. # (change requires restart)
  271.  
  272. # - Streaming -
  273.  
  274. #sr_check_period =
  275. sr_check_period =
  276. # Streaming replication check period
  277. # Disabled () by default
  278. sr_check_user = 'postgres'
  279. # Streaming replication check user
  280. # This is necessary even if you disable
  281. # streaming replication delay check with
  282. # sr_check_period =
  283. sr_check_password = 'postgres123'
  284. # Password for streaming replication check user
  285. delay_threshold =
  286. # Threshold before not dispatching query to standby node
  287. # Unit is in bytes
  288. # Disabled () by default
  289.  
  290. # - Special commands -
  291.  
  292. follow_master_command = ''
  293. # Executes this command after master failover
  294. # Special values:
  295. # %d = node id
  296. # %h = host name
  297. # %p = port number
  298. # %D = database cluster path
  299. # %m = new master node id
  300. # %H = hostname of the new master node
  301. # %M = old master node id
  302. # %P = old primary node id
  303. # %r = new master port number
  304. # %R = new master database cluster path
  305. # %% = '%' character
  306.  
  307. #------------------------------------------------------------------------------
  308. # PARALLEL MODE
  309. #------------------------------------------------------------------------------
  310.  
  311. parallel_mode = off
  312. # Activates parallel query mode
  313. # (change requires restart)
  314. pgpool2_hostname = ''
  315. # Set pgpool2 hostname
  316. # (change requires restart)
  317.  
  318. # - System DB info -
  319.  
  320. system_db_hostname = 'localhost'
  321. # (change requires restart)
  322. system_db_port =
  323. # (change requires restart)
  324. system_db_dbname = 'pgpool'
  325. # (change requires restart)
  326. system_db_schema = 'pgpool_catalog'
  327. # (change requires restart)
  328. system_db_user = 'pgpool'
  329. # (change requires restart)
  330. system_db_password = ''
  331. # (change requires restart)
  332.  
  333. #------------------------------------------------------------------------------
  334. # HEALTH CHECK
  335. #------------------------------------------------------------------------------
  336.  
  337. #health_check_period =
  338. health_check_period =
  339. # Health check period
  340. # Disabled () by default
  341. health_check_timeout =
  342. # Health check timeout
  343. # means no timeout
  344. health_check_user = 'postgres'
  345. # Health check user
  346. health_check_password = 'postgres123'
  347. # Password for health check user
  348. health_check_max_retries =
  349. # Maximum number of times to retry a failed health check before giving up.
  350. health_check_retry_delay =
  351. # Amount of time to wait (in seconds) between retries.
  352.  
  353. #------------------------------------------------------------------------------
  354. # FAILOVER AND FAILBACK
  355. #------------------------------------------------------------------------------
  356.  
  357. failover_command = '/home/postgres/scripts/failover_stream.sh %d %H /usr/local/pgsql/data/postgresql.trigger.5432'
  358. # Executes this command at failover
  359. # Special values:
  360. # %d = node id
  361. # %h = host name
  362. # %p = port number
  363. # %D = database cluster path
  364. # %m = new master node id
  365. # %H = hostname of the new master node
  366. # %M = old master node id
  367. # %P = old primary node id
  368. # %r = new master port number
  369. # %R = new master database cluster path
  370. # %% = '%' character
  371. failback_command = ''
  372. # Executes this command at failback.
  373. # Special values:
  374. # %d = node id
  375. # %h = host name
  376. # %p = port number
  377. # %D = database cluster path
  378. # %m = new master node id
  379. # %H = hostname of the new master node
  380. # %M = old master node id
  381. # %P = old primary node id
  382. # %r = new master port number
  383. # %R = new master database cluster path
  384. # %% = '%' character
  385.  
  386. fail_over_on_backend_error = on
  387. # Initiates failover when reading/writing to the
  388. # backend communication socket fails
  389. # If set to off, pgpool will report an
  390. # error and disconnect the session.
  391.  
  392. search_primary_node_timeout =
  393. # Timeout in seconds to search for the
  394. # primary node when a failover occurs.
  395. # means no timeout, keep searching
  396. # for a primary node forever.
  397.  
  398. #------------------------------------------------------------------------------
  399. # ONLINE RECOVERY
  400. #------------------------------------------------------------------------------
  401.  
  402. recovery_user = 'postgres'
  403. # Online recovery user
  404. recovery_password = 'postgres123'
  405. # Online recovery password
  406. recovery_1st_stage_command = ''
  407. # Executes a command in first stage
  408. recovery_2nd_stage_command = ''
  409. # Executes a command in second stage
  410. recovery_timeout =
  411. # Timeout in seconds to wait for the
  412. # recovering node's postmaster to start up
  413. # means no wait
  414. client_idle_limit_in_recovery =
  415. # Client is disconnected after being idle
  416. # for that many seconds in the second stage
  417. # of online recovery
  418. # means no disconnection
  419. # - means immediate disconnection
  420.  
  421. #------------------------------------------------------------------------------
  422. # WATCHDOG
  423. #------------------------------------------------------------------------------
  424.  
  425. # - Enabling -
  426.  
  427. use_watchdog = off
  428. # Activates watchdog
  429. # (change requires restart)
  430.  
  431. # -Connection to up stream servers -
  432.  
  433. trusted_servers = ''
  434. # trusted server list which are used
  435. # to confirm network connection
  436. # (hostA,hostB,hostC,...)
  437. # (change requires restart)
  438. ping_path = '/bin'
  439. # ping command path
  440. # (change requires restart)
  441.  
  442. # - Watchdog communication Settings -
  443.  
  444. wd_hostname = ''
  445. # Host name or IP address of this watchdog
  446. # (change requires restart)
  447. wd_port =
  448. # port number for watchdog service
  449. # (change requires restart)
  450. wd_authkey = ''
  451. # Authentication key for watchdog communication
  452. # (change requires restart)
  453.  
  454. # - Virtual IP control Setting -
  455.  
  456. delegate_IP = ''
  457. # delegate IP address
  458. # If this is empty, virtual IP never bring up.
  459. # (change requires restart)
  460. ifconfig_path = '/sbin'
  461. # ifconfig command path
  462. # (change requires restart)
  463. if_up_cmd = 'ifconfig eth0:0 inet $_IP_$ netmask 255.255.255.0'
  464. # startup delegate IP command
  465. # (change requires restart)
  466. if_down_cmd = 'ifconfig eth0:0 down'
  467. # shutdown delegate IP command
  468. # (change requires restart)
  469.  
  470. arping_path = '/usr/sbin' # arping command path
  471. # (change requires restart)
  472.  
  473. arping_cmd = 'arping -U $_IP_$ -w 1'
  474. # arping command
  475. # (change requires restart)
  476.  
  477. # - Behaivor on escalation Setting -
  478.  
  479. clear_memqcache_on_escalation = on
  480. # Clear all the query cache on shared memory
  481. # when standby pgpool escalate to active pgpool
  482. # (= virtual IP holder).
  483. # This should be off if client connects to pgpool
  484. # not using virtual IP.
  485. # (change requires restart)
  486. wd_escalation_command = ''
  487. # Executes this command at escalation on new active pgpool.
  488. # (change requires restart)
  489.  
  490. # - Lifecheck Setting -
  491.  
  492. # -- common --
  493.  
  494. wd_lifecheck_method = 'heartbeat'
  495. # Method of watchdog lifecheck ('heartbeat' or 'query')
  496. # (change requires restart)
  497. wd_interval =
  498. # lifecheck interval (sec) >
  499. # (change requires restart)
  500.  
  501. # -- heartbeat mode --
  502.  
  503. wd_heartbeat_port =
  504. # Port number for receiving heartbeat signal
  505. # (change requires restart)
  506. wd_heartbeat_keepalive =
  507. # Interval time of sending heartbeat signal (sec)
  508. # (change requires restart)
  509. wd_heartbeat_deadtime =
  510. # Deadtime interval for heartbeat signal (sec)
  511. # (change requires restart)
  512. heartbeat_destination0 = 'db2'
  513. # Host name or IP address of destination
  514. # for sending heartbeat signal.
  515. # (change requires restart)
  516. heartbeat_destination_port0 =
  517. # Port number of destination for sending
  518. # heartbeat signal. Usually this is the
  519. # same as wd_heartbeat_port.
  520. # (change requires restart)
  521. heartbeat_device0 = ''
  522. # Name of NIC device (such like 'eth0')
  523. # used for sending/receiving heartbeat
  524. # signal to/from destination .
  525. # This works only when this is not empty
  526. # and pgpool has root privilege.
  527. # (change requires restart)
  528.  
  529. #heartbeat_destination1 = 'host0_ip2'
  530. #heartbeat_destination_port1 =
  531. #heartbeat_device1 = ''
  532.  
  533. # -- query mode --
  534.  
  535. wd_life_point =
  536. # lifecheck retry times
  537. # (change requires restart)
  538. wd_lifecheck_query = 'SELECT 1'
  539. # lifecheck query to pgpool from watchdog
  540. # (change requires restart)
  541. wd_lifecheck_dbname = 'template1'
  542. # Database name connected for lifecheck
  543. # (change requires restart)
  544. wd_lifecheck_user = 'nobody'
  545. # watchdog user monitoring pgpools in lifecheck
  546. # (change requires restart)
  547. wd_lifecheck_password = ''
  548. # Password for watchdog user in lifecheck
  549. # (change requires restart)
  550.  
  551. # - Other pgpool Connection Settings -
  552.  
  553. #other_pgpool_hostname0 = 'host0'
  554. # Host name or IP address to connect to for other pgpool
  555. # (change requires restart)
  556. #other_pgpool_port0 =
  557. # Port number for othet pgpool
  558. # (change requires restart)
  559. #other_wd_port0 =
  560. # Port number for othet watchdog
  561. # (change requires restart)
  562. #other_pgpool_hostname1 = 'host1'
  563. #other_pgpool_port1 =
  564. #other_wd_port1 =
  565.  
  566. #------------------------------------------------------------------------------
  567. # OTHERS
  568. #------------------------------------------------------------------------------
  569. relcache_expire =
  570. # Life time of relation cache in seconds.
  571. # means no cache expiration(the default).
  572. # The relation cache is used for cache the
  573. # query result against PostgreSQL system
  574. # catalog to obtain various information
  575. # including table structures or if it's a
  576. # temporary table or not. The cache is
  577. # maintained in a pgpool child local memory
  578. # and being kept as long as it survives.
  579. # If someone modify the table by using
  580. # ALTER TABLE or some such, the relcache is
  581. # not consistent anymore.
  582. # For this purpose, cache_expiration
  583. # controls the life time of the cache.
  584.  
  585. relcache_size =
  586. # Number of relation cache
  587. # entry. If you see frequently:
  588. # "pool_search_relcache: cache replacement happend"
  589. # in the pgpool log, you might want to increate this number.
  590.  
  591. check_temp_table = on
  592. # If on, enable temporary table check in SELECT statements.
  593. # This initiates queries against system catalog of primary/master
  594. # thus increases load of master.
  595. # If you are absolutely sure that your system never uses temporary tables
  596. # and you want to save access to primary/master, you could turn this off.
  597. # Default is on.
  598.  
  599. #------------------------------------------------------------------------------
  600. # ON MEMORY QUERY MEMORY CACHE
  601. #------------------------------------------------------------------------------
  602. memory_cache_enabled = off
  603. # If on, use the memory cache functionality, off by default
  604. memqcache_method = 'shmem'
  605. # Cache storage method. either 'shmem'(shared memory) or
  606. # 'memcached'. 'shmem' by default
  607. # (change requires restart)
  608. memqcache_memcached_host = 'localhost'
  609. # Memcached host name or IP address. Mandatory if
  610. # memqcache_method = 'memcached'.
  611. # Defaults to localhost.
  612. # (change requires restart)
  613. memqcache_memcached_port =
  614. # Memcached port number. Mondatory if memqcache_method = 'memcached'.
  615. # Defaults to .
  616. # (change requires restart)
  617. memqcache_total_size =
  618. # Total memory size in bytes for storing memory cache.
  619. # Mandatory if memqcache_method = 'shmem'.
  620. # Defaults to 64MB.
  621. # (change requires restart)
  622. memqcache_max_num_cache =
  623. # Total number of cache entries. Mandatory
  624. # if memqcache_method = 'shmem'.
  625. # Each cache entry consumes bytes on shared memory.
  626. # Defaults to ,,(.8MB).
  627. # (change requires restart)
  628. memqcache_expire =
  629. # Memory cache entry life time specified in seconds.
  630. # means infinite life time. by default.
  631. # (change requires restart)
  632. memqcache_auto_cache_invalidation = on
  633. # If on, invalidation of query cache is triggered by corresponding
  634. # DDL/DML/DCL(and memqcache_expire). If off, it is only triggered
  635. # by memqcache_expire. on by default.
  636. # (change requires restart)
  637. memqcache_maxcache =
  638. # Maximum SELECT result size in bytes.
  639. # Must be smaller than memqcache_cache_block_size. Defaults to 400KB.
  640. # (change requires restart)
  641. memqcache_cache_block_size =
  642. # Cache block size in bytes. Mandatory if memqcache_method = 'shmem'.
  643. # Defaults to 1MB.
  644. # (change requires restart)
  645. memqcache_oiddir = '/var/log/pgpool/oiddir'
  646. # Temporary work directory to record table oids
  647. # (change requires restart)
  648. white_memqcache_table_list = ''
  649. # Comma separated list of table names to memcache
  650. # that don't write to database
  651. # Regexp are accepted
  652. black_memqcache_table_list = ''
  653. # Comma separated list of table names not to memcache
  654. # that don't write to database
  655. # Regexp are accepted

  1.4 启动pgpool:pgpool -dn 以非守护进程,调试模式运行pgpool,因为如果默认是守护进程,待会想停止就麻烦了。其他参数--help.

注意观察调试信息。如果有错误,请重新查看配置文件。如果没有法相错误,使用命令:psql -p 9999 ,通过pgpool进入数据库。如果可以进入就说明pgpool监听的9999正常,且成功连接数据库。

  此时使用如下命令查看监听的数据库信息:当发现status为3时,使用ping、telnet、psql -h进行测试网络连通性。关闭防火墙。

  1. postgres=# show pool_nodes;
  2. node_id | hostname | port | status | lb_weight | role
  3. ---------+--------------+------+--------+-----------+---------
  4. | 192.168.1.45 | | | 0.500000 | primary
  5. | 192.168.1.50 | | | 0.500000 | standby

  当然,可以启动主从数据库的日志级别为 all。那么对数据的一切操作,都可以查看到。此时可以使用脚本测试一下。就可以查看主从的日志。看看是否都有日志记录。

  1. for i in {..}; do echo $i; psql -p -U postgres -h 192.168.1.45 -d postgres -c "select * from test"; done

  1.5 查看pgpool的状态。参考手册:http://pgpool.projects.pgfoundry.org/pgpool-II/doc/pgpool-zh_cn.html#show-commands

  之前安装的regclass就是通过psql查看pgpool状态的工具。可以运行下列命令查看:

  1. pgpool-II 通过 SHOW 命令提供一些信息。SHOW 是一个真实的 SQL 语句, 但是如果该命令查询 pgpool-II 信息的话,pgpool-II 解释了该命令。可选项如下:
  2.  
  3. pool_status, 获取配置
  4. pool_nodes, 获取节点信息
  5. pool_processes, 获取pgPool-II 进程信息
  6. pool_pools, 获取pgPool-II 所有的连接池信息
  7. pool_version, 获取pgPool_II 版本信息

  比如:pool_processes。查看进程池的情况。可以根据需要修改pgpool中的设置。

  1. postgres=# show pool_processes;
  2. pool_pid | start_time | database | username | create_time | pool_counter
  3. ----------+---------------------+----------+----------+---------------------+--------------
  4. | -- :: | postgres | postgres | -- :: |
  5. | -- :: | | | |
  6. | -- :: | | | |
  7. | -- :: | | | |
  8. | -- :: | | | |
  9. | -- :: | | | |
  10. | -- :: | | | |
  11. | -- :: | | | |
  12. | -- :: | | | |
  13. | -- :: | | | |

PostgreSQL的HA解决方案-2负载均衡(load balance)的更多相关文章

  1. Oracle RAC 服务器端连接负载均衡(Load Balance)

    Oracle RAC服务器端的负载均衡是根据RAC中各节点的连接负荷数情况,将新的连接请求分配到负荷最小的节点上去.当数据库处于运行时,RAC中各节点的PMON进程每3秒会将各自节点的连接负荷数更新到 ...

  2. Oracle RAC 客户端连接负载均衡(Load Balance)

    实现负载均衡(Load Balance)是Oracle RAC最重要的特性之一,主要是把负载平均分配到集群中的各个节点,以提高系统的整体吞吐能力.通常情况下有两种方式来实现负载均衡,一个是基于客户端连 ...

  3. "高可用方案工具包" high availability toolkit 1.2 公布了。version 1.2 新增了 负载均衡 load balance 的技术实现

    "高可用方案工具包"  high availability toolkit 1.2 公布了. version 1.2 新增了 负载均衡 load balance 的技术实现. 项目 ...

  4. 【高可用HA】Nginx (1) —— Mac下配置Nginx Http负载均衡(Load Balancer)之101实例

    [高可用HA]Nginx (1) -- Mac下配置Nginx Http负载均衡(Load Balancer)之101实例 nginx版本: nginx-1.9.8 参考来源: nginx.org [ ...

  5. 【高可用HA】Apache (4) —— Mac下配置Apache Httpd负载均衡(Load Balancer)之mod_jk

    Mac下配置Apache Httpd负载均衡(Load Balancer)之mod_jk httpd版本: httpd-2.4.17 jk版本: tomcat-connectors-1.2.41 参考 ...

  6. 【高可用HA】Apache (3) —— Mac下配置Apache Httpd负载均衡(Load Balancer)之mod_proxy

    Mac下配置Apache Httpd负载均衡(Load Balancer)之mod_proxy httpd版本: httpd-2.4.17 参考来源: Apache (1) -- Mac下安装Apac ...

  7. 【mq】从零开始实现 mq-07-负载均衡 load balance

    前景回顾 [mq]从零开始实现 mq-01-生产者.消费者启动 [mq]从零开始实现 mq-02-如何实现生产者调用消费者? [mq]从零开始实现 mq-03-引入 broker 中间人 [mq]从零 ...

  8. PostgreSQL的HA解决方案-项目概述

    公司使用的数据库时postgresql,一直运行都很流畅,但是最近java新做的管理平台,由于登录用户较多,并发性比较大.另外新系统可能优化也存在问题,所以pg经常崩溃,所以我就开始研究如何事项pg的 ...

  9. 章文嵩博士和他背后的负载均衡(LOAD BANLANCER)帝国

    案首语: 阿里集团技术大牛,@正明,淘宝基础核心软件研发负责人.LVS创始人.阿里云首席科学家章文嵩博士从阿里离职,去追求技术人生另一段历程,让阿里像我一样的很多热爱技术的工程师都有一丝牵动和感触. ...

随机推荐

  1. Tost元素识别

    在日常使用App过程中,经常会看到App界面有一些弹窗提示(如下图所示)这些提示元素出现后等待3秒左右就会自动消失,那么我们该如何获取这些元素文字内容呢? Toast简介 Android中的Toast ...

  2. 【剑指Offer】 24、二叉树中和为某一值的路径

      题目描述:   输入一颗二叉树的根结点和一个整数,打印出二叉树中结点值的和为输入整数的所有路径.路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径.(注意: 在返回值的list中, ...

  3. npm命令及解释

    npm是Node Package Manager,也就是长说的NPM包管理器. 一般安装node.js就会一起安装. npm install npm install XXX    //表示安装模块, ...

  4. 数组(day07)

    数组名称不可以代表存储区 数组名称可以代表数组里第一个存储区的地址 可以对数组名称进行sizeof计算,结果是 数组里所有存储区的总大小 C99规范里可以使用变长数组 声明变长数组的时候可以用变量表示 ...

  5. [luogu1034] 矩形覆盖 (暴力)

    传送门 Description 给n(n<=50)个点(x,y),要求用k(1<=k<=4)个没有联系的矩形覆盖住求矩形最小面积 Solution 感觉不是很可做,结果看TJ后发现数 ...

  6. 实体服务器安装centos7过程记录

    一次在实体服务器安装centos 7的过程记录 第一次在实体服务器上面安装服务器(centos 7),在此记录安装过程中遇到的一些坑. 系统版本:CentOS Linux release 7.6.18 ...

  7. Java基础学习总结(68)——有关Java线程方面的面试题

    不管你是新程序员还是老手,你一定在面试中遇到过有关线程的问题.Java 语言一个重要的特点就是内置了对并发的支持,让 Java 大受企业和程序员的欢迎.大多数待遇丰厚的 Java 开发职位都要求开发者 ...

  8. poj 3177&&poj 3352加边构双联通(有重边)用tarjan 模板求的

    #include<stdio.h>/* 求边双联通分量和求强连通差不多,先缩点求出叶子节点的个数 */ #include<string.h> #define N 5100 st ...

  9. HDU - 2973 - YAPTCHA

    先上题目: YAPTCHA Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  10. hdu1716(库函数next_permutation)

    题目意思: 现有四张卡片,用这四张卡片能排列出非常多不同的4位数,要求按从小到大的顺序输出这些4位数. 注意首位没有前导0 pid=1716">http://acm.hdu.edu.c ...