安装postgresql

CentOS7安装并配置PostgreSQL

安装pgpool

  1. rpm -ivh http://www.pgpool.net/yum/rpms/3.7/redhat/rhel-7-x86_64/pgpool-II-release-3.7-1.noarch.rpm
  2. yum -y install pgpool-II-pg95
  3. yum -y install pgpool-II-pg95-debuginfo
  4. yum -y install pgpool-II-pg95-devel
  5. yum -y install pgpool-II-pg95-extensions
  6.  
  7. 开机启动
  8. systemctl enable pgpool

 

添加Pgpool-II运行用户

  1. [root@im110 pgpool-II]# useradd pgpool
  2. [root@im110 pgpool-II]# passwd pgpool
  3. Changing password for user pgpool.
  4. New password:
  5. Retype new password:
  6. passwd: all authentication tokens updated successfully.
  7. [root@im110 pgpool-II]# chown -R pgpool.pgpool /etc/pgpool-II
  8. [root@im110 pgpool-II]# mkdir -p /var/run/pgpool/
  9. [root@im110 pgpool-II]# chown pgpool.pgpool /var/run/pgpool/

修改配置文件

先备份所有配置文件

vi pgpool.conf修改后如下

  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 = '*'
  27. # Host name or IP address to listen on:
  28. # '*' for all, '' for no TCP/IP connections
  29. # (change requires restart)
  30. port =
  31. # Port number
  32. # (change requires restart)
  33. socket_dir = '/var/run/postgresql'
  34. # Unix domain socket path
  35. # The Debian package defaults to
  36. # /var/run/postgresql
  37. # (change requires restart)
  38. listen_backlog_multiplier =
  39. # Set the backlog parameter of listen() to
  40. # num_init_children * listen_backlog_multiplier.
  41. # (change requires restart)
  42. serialize_accept = off
  43. # whether to serialize accept() call to avoid thundering herd problem
  44. # (change requires restart)
  45.  
  46. # - pgpool Communication Manager Connection Settings -
  47.  
  48. pcp_listen_addresses = '*'
  49. # Host name or IP address for pcp process to listen on:
  50. # '*' for all, '' for no TCP/IP connections
  51. # (change requires restart)
  52. pcp_port =
  53. # Port number for pcp
  54. # (change requires restart)
  55. pcp_socket_dir = '/var/run/postgresql'
  56. # Unix domain socket path for pcp
  57. # The Debian package defaults to
  58. # /var/run/postgresql
  59. # (change requires restart)
  60.  
  61. # - Backend Connection Settings -
  62.  
  63. backend_hostname0 = '119.29.218.235'
  64. # Host name or IP address to connect to for backend
  65. backend_port0 =
  66. # Port number for backend
  67. backend_weight0 =
  68. # Weight for backend (only in load balancing mode)
  69. backend_data_directory0 = '/var/lib/pgsql/data'
  70. # Data directory for backend
  71. backend_flag0 = 'ALLOW_TO_FAILOVER'
  72. # Controls various backend behavior
  73. # ALLOW_TO_FAILOVER, DISALLOW_TO_FAILOVER
  74. # or ALWAYS_MASTER
  75. backend_hostname1 = '111.231.195.197'
  76. backend_port1 =
  77. backend_weight1 =
  78. backend_data_directory1 = '/var/lib/pgsql/data'
  79. backend_flag1 = 'ALLOW_TO_FAILOVER'
  80.  
  81. # - Authentication -
  82.  
  83. enable_pool_hba = on
  84. # Use pool_hba.conf for client authentication
  85. pool_passwd = 'pool_passwd'
  86. # File name of pool_passwd for md5 authentication.
  87. # "" disables pool_passwd.
  88. # (change requires restart)
  89. authentication_timeout =
  90. # Delay in seconds to complete client authentication
  91. # means no timeout.
  92.  
  93. # - SSL Connections -
  94.  
  95. ssl = off
  96. # Enable SSL support
  97. # (change requires restart)
  98. #ssl_key = './server.key'
  99. # Path to the SSL private key file
  100. # (change requires restart)
  101. #ssl_cert = './server.cert'
  102. # Path to the SSL public certificate file
  103. # (change requires restart)
  104. #ssl_ca_cert = ''
  105. # Path to a single PEM format file
  106. # containing CA root certificate(s)
  107. # (change requires restart)
  108. #ssl_ca_cert_dir = ''
  109. # Directory containing CA root certificate(s)
  110. # (change requires restart)
  111.  
  112. #------------------------------------------------------------------------------
  113. # POOLS
  114. #------------------------------------------------------------------------------
  115.  
  116. # - Concurrent session and pool size -
  117.  
  118. num_init_children =
  119. # Number of concurrent sessions allowed
  120. # (change requires restart)
  121. max_pool =
  122. # Number of connection pool caches per connection
  123. # (change requires restart)
  124.  
  125. # - Life time -
  126.  
  127. child_life_time =
  128. # Pool exits after being idle for this many seconds
  129. child_max_connections =
  130. # Pool exits after receiving that many connections
  131. # means no exit
  132. connection_life_time =
  133. # Connection to backend closes after being idle for this many seconds
  134. # means no close
  135. client_idle_limit =
  136. # Client is disconnected after being idle for that many seconds
  137. # (even inside an explicit transactions!)
  138. # means no disconnection
  139.  
  140. #------------------------------------------------------------------------------
  141. # LOGS
  142. #------------------------------------------------------------------------------
  143.  
  144. # - Where to log -
  145.  
  146. log_destination = 'stderr'
  147. # Where to log
  148. # Valid values are combinations of stderr,
  149. # and syslog. Default to stderr.
  150.  
  151. # - What to log -
  152.  
  153. log_line_prefix = '%t: pid %p: ' # printf-style string to output at beginning of each log line.
  154.  
  155. log_connections = off
  156. # Log connections
  157. log_hostname = off
  158. # Hostname will be shown in ps status
  159. # and in logs if connections are logged
  160. log_statement = off
  161. # Log all statements
  162. log_per_node_statement = off
  163. # Log all statements
  164. # with node and backend informations
  165. log_standby_delay = 'none'
  166. # Log standby delay
  167. # Valid values are combinations of always,
  168. # if_over_threshold, none
  169.  
  170. # - Syslog specific -
  171.  
  172. syslog_facility = 'LOCAL0'
  173. # Syslog local facility. Default to LOCAL0
  174. syslog_ident = 'pgpool'
  175. # Syslog program identification string
  176. # Default to 'pgpool'
  177.  
  178. # - Debug -
  179.  
  180. #log_error_verbosity = default # terse, default, or verbose messages
  181.  
  182. #client_min_messages = notice # values in order of decreasing detail:
  183. # debug5
  184. # debug4
  185. # debug3
  186. # debug2
  187. # debug1
  188. # log
  189. # notice
  190. # warning
  191. # error
  192.  
  193. #log_min_messages = warning # values in order of decreasing detail:
  194. # debug5
  195. # debug4
  196. # debug3
  197. # debug2
  198. # debug1
  199. # info
  200. # notice
  201. # warning
  202. # error
  203. # log
  204. # fatal
  205. # panic
  206.  
  207. #------------------------------------------------------------------------------
  208. # FILE LOCATIONS
  209. #------------------------------------------------------------------------------
  210.  
  211. pid_file_name = '/var/run/pgpool/pgpool.pid'
  212. # PID file name
  213. # Can be specified as relative to the"
  214. # location of pgpool.conf file or
  215. # as an absolute path
  216. # (change requires restart)
  217. logdir = '/var/log/pgpool'
  218. # Directory of pgPool status file
  219. # (change requires restart)
  220.  
  221. #------------------------------------------------------------------------------
  222. # CONNECTION POOLING
  223. #------------------------------------------------------------------------------
  224.  
  225. connection_cache = on
  226. # Activate connection pools
  227. # (change requires restart)
  228.  
  229. # Semicolon separated list of queries
  230. # to be issued at the end of a session
  231. # The default is for 8.3 and later
  232. reset_query_list = 'ABORT; DISCARD ALL'
  233. # The following one is for 8.2 and before
  234. #reset_query_list = 'ABORT; RESET ALL; SET SESSION AUTHORIZATION DEFAULT'
  235.  
  236. #------------------------------------------------------------------------------
  237. # REPLICATION MODE
  238. #------------------------------------------------------------------------------
  239.  
  240. replication_mode = off
  241. # Activate replication mode
  242. # (change requires restart)
  243. replicate_select = off
  244. # Replicate SELECT statements
  245. # when in replication mode
  246. # replicate_select is higher priority than
  247. # load_balance_mode.
  248.  
  249. insert_lock = on
  250. # Automatically locks a dummy row or a table
  251. # with INSERT statements to keep SERIAL data
  252. # consistency
  253. # Without SERIAL, no lock will be issued
  254. lobj_lock_table = ''
  255. # When rewriting lo_creat command in
  256. # replication mode, specify table name to
  257. # lock
  258.  
  259. # - Degenerate handling -
  260.  
  261. replication_stop_on_mismatch = off
  262. # On disagreement with the packet kind
  263. # sent from backend, degenerate the node
  264. # which is most likely "minority"
  265. # If off, just force to exit this session
  266.  
  267. failover_if_affected_tuples_mismatch = off
  268. # On disagreement with the number of affected
  269. # tuples in UPDATE/DELETE queries, then
  270. # degenerate the node which is most likely
  271. # "minority".
  272. # If off, just abort the transaction to
  273. # keep the consistency
  274.  
  275. #------------------------------------------------------------------------------
  276. # LOAD BALANCING MODE
  277. #------------------------------------------------------------------------------
  278.  
  279. load_balance_mode = off
  280. # Activate load balancing mode
  281. # (change requires restart)
  282. ignore_leading_white_space = on
  283. # Ignore leading white spaces of each query
  284. white_function_list = ''
  285. # Comma separated list of function names
  286. # that don't write to database
  287. # Regexp are accepted
  288. black_function_list = 'nextval,setval,nextval,setval'
  289. # Comma separated list of function names
  290. # that write to database
  291. # Regexp are accepted
  292.  
  293. database_redirect_preference_list = ''
  294. # comma separated list of pairs of database and node id.
  295. # example: postgres:primary,mydb[-]:,mydb[-]:'
  296. # valid for streaming replicaton mode only.
  297.  
  298. app_name_redirect_preference_list = ''
  299. # comma separated list of pairs of app name and node id.
  300. # example: 'psql:primary,myapp[0-4]:1,myapp[5-9]:standby'
  301. # valid for streaming replicaton mode only.
  302. allow_sql_comments = off
  303. # if on, ignore SQL comments when judging if load balance or
  304. # query cache is possible.
  305. # If off, SQL comments effectively prevent the judgment
  306. # (pre 3.4 behavior).
  307.  
  308. #------------------------------------------------------------------------------
  309. # MASTER/SLAVE MODE
  310. #------------------------------------------------------------------------------
  311.  
  312. master_slave_mode = off
  313. # Activate master/slave mode
  314. # (change requires restart)
  315. master_slave_sub_mode = 'stream'
  316. # Master/slave sub mode
  317. # Valid values are combinations stream, slony
  318. # or logical. Default is stream.
  319. # (change requires restart)
  320.  
  321. # - Streaming -
  322.  
  323. sr_check_period =
  324. # Streaming replication check period
  325. # Disabled () by default
  326. sr_check_user = 'postgres'
  327. # Streaming replication check user
  328. # This is necessary even if you disable
  329. # streaming replication delay check with
  330. # sr_check_period =
  331. sr_check_password = 'your pass word'
  332. # Password for streaming replication check user
  333. sr_check_database = 'postgres'
  334. # Database name for streaming replication check
  335. delay_threshold =
  336. # Threshold before not dispatching query to standby node
  337. # Unit is in bytes
  338. # Disabled () by default
  339.  
  340. # - Special commands -
  341.  
  342. follow_master_command = ''
  343. # Executes this command after master failover
  344. # Special values:
  345. # %d = node id
  346. # %h = host name
  347. # %p = port number
  348. # %D = database cluster path
  349. # %m = new master node id
  350. # %H = hostname of the new master node
  351. # %M = old master node id
  352. # %P = old primary node id
  353. # %r = new master port number
  354. # %R = new master database cluster path
  355. # %% = '%' character
  356.  
  357. #------------------------------------------------------------------------------
  358. # HEALTH CHECK GLOBAL PARAMETERS
  359. #------------------------------------------------------------------------------
  360.  
  361. health_check_period =
  362. # Health check period
  363. # Disabled () by default
  364. health_check_timeout =
  365. # Health check timeout
  366. # means no timeout
  367. health_check_user = 'nobody'
  368. # Health check user
  369. health_check_password = ''
  370. # Password for health check user
  371. health_check_database = ''
  372. # Database name for health check. If '', tries 'postgres' frist, then 'template1'
  373.  
  374. health_check_max_retries =
  375. # Maximum number of times to retry a failed health check before giving up.
  376. health_check_retry_delay =
  377. # Amount of time to wait (in seconds) between retries.
  378. connect_timeout =
  379. # Timeout value in milliseconds before giving up to connect to backend.
  380. # Default is ms ( second). Flaky network user may want to increase
  381. # the value. means no timeout.
  382. # Note that this value is not only used for health check,
  383. # but also for ordinary conection to backend.
  384.  
  385. #------------------------------------------------------------------------------
  386. # HEALTH CHECK PER NODE PARAMETERS (OPTIONAL)
  387. #------------------------------------------------------------------------------
  388. #health_check_period0 =
  389. #health_check_timeout0 =
  390. #health_check_user0 = 'nobody'
  391. #health_check_password0 = ''
  392. #health_check_database0 = ''
  393. #health_check_max_retries0 =
  394. #health_check_retry_delay0 =
  395. #connect_timeout0 =
  396.  
  397. #------------------------------------------------------------------------------
  398. # FAILOVER AND FAILBACK
  399. #------------------------------------------------------------------------------
  400.  
  401. failover_command = '/usr/local/bin/failover_stream.sh %d %H /tmp/trigger_file0'
  402. # Executes this command at failover
  403. # Special values:
  404. # %d = node id
  405. # %h = host name
  406. # %p = port number
  407. # %D = database cluster path
  408. # %m = new master node id
  409. # %H = hostname of the new master node
  410. # %M = old master node id
  411. # %P = old primary node id
  412. # %r = new master port number
  413. # %R = new master database cluster path
  414. # %% = '%' character
  415. failback_command = ''
  416. # Executes this command at failback.
  417. # Special values:
  418. # %d = node id
  419. # %h = host name
  420. # %p = port number
  421. # %D = database cluster path
  422. # %m = new master node id
  423. # %H = hostname of the new master node
  424. # %M = old master node id
  425. # %P = old primary node id
  426. # %r = new master port number
  427. # %R = new master database cluster path
  428. # %% = '%' character
  429.  
  430. fail_over_on_backend_error = on
  431. # Initiates failover when reading/writing to the
  432. # backend communication socket fails
  433. # If set to off, pgpool will report an
  434. # error and disconnect the session.
  435.  
  436. search_primary_node_timeout =
  437. # Timeout in seconds to search for the
  438. # primary node when a failover occurs.
  439. # means no timeout, keep searching
  440. # for a primary node forever.
  441.  
  442. #------------------------------------------------------------------------------
  443. # ONLINE RECOVERY
  444. #------------------------------------------------------------------------------
  445.  
  446. recovery_user = 'nobody'
  447. # Online recovery user
  448. recovery_password = ''
  449. # Online recovery password
  450. recovery_1st_stage_command = ''
  451. # Executes a command in first stage
  452. recovery_2nd_stage_command = ''
  453. # Executes a command in second stage
  454. recovery_timeout =
  455. # Timeout in seconds to wait for the
  456. # recovering node's postmaster to start up
  457. # means no wait
  458. client_idle_limit_in_recovery =
  459. # Client is disconnected after being idle
  460. # for that many seconds in the second stage
  461. # of online recovery
  462. # means no disconnection
  463. # - means immediate disconnection
  464.  
  465. #------------------------------------------------------------------------------
  466. # WATCHDOG
  467. #------------------------------------------------------------------------------
  468.  
  469. # - Enabling -
  470.  
  471. use_watchdog = off
  472. # Activates watchdog
  473. # (change requires restart)
  474.  
  475. # -Connection to up stream servers -
  476.  
  477. trusted_servers = ''
  478. # trusted server list which are used
  479. # to confirm network connection
  480. # (hostA,hostB,hostC,...)
  481. # (change requires restart)
  482. ping_path = '/bin'
  483. # ping command path
  484. # (change requires restart)
  485.  
  486. # - Watchdog communication Settings -
  487.  
  488. wd_hostname = ''
  489. # Host name or IP address of this watchdog
  490. # (change requires restart)
  491. wd_port =
  492. # port number for watchdog service
  493. # (change requires restart)
  494. wd_priority =
  495. # priority of this watchdog in leader election
  496. # (change requires restart)
  497.  
  498. wd_authkey = ''
  499. # Authentication key for watchdog communication
  500. # (change requires restart)
  501.  
  502. wd_ipc_socket_dir = '/var/run/postgresql'
  503. # Unix domain socket path for watchdog IPC socket
  504. # The Debian package defaults to
  505. # /var/run/postgresql
  506. # (change requires restart)
  507.  
  508. # - Virtual IP control Setting -
  509.  
  510. delegate_IP = ''
  511. # delegate IP address
  512. # If this is empty, virtual IP never bring up.
  513. # (change requires restart)
  514. if_cmd_path = '/sbin'
  515. # path to the directory where if_up/down_cmd exists
  516. # (change requires restart)
  517. if_up_cmd = 'ip addr add $_IP_$/24 dev eth0 label eth0:0'
  518. # startup delegate IP command
  519. # (change requires restart)
  520. if_down_cmd = 'ip addr del $_IP_$/24 dev eth0'
  521. # shutdown delegate IP command
  522. # (change requires restart)
  523. arping_path = '/usr/sbin'
  524. # arping command path
  525. # (change requires restart)
  526. arping_cmd = 'arping -U $_IP_$ -w 1'
  527. # arping command
  528. # (change requires restart)
  529.  
  530. # - Behaivor on escalation Setting -
  531.  
  532. clear_memqcache_on_escalation = on
  533. # Clear all the query cache on shared memory
  534. # when standby pgpool escalate to active pgpool
  535. # (= virtual IP holder).
  536. # This should be off if client connects to pgpool
  537. # not using virtual IP.
  538. # (change requires restart)
  539. wd_escalation_command = ''
  540. # Executes this command at escalation on new active pgpool.
  541. # (change requires restart)
  542. wd_de_escalation_command = ''
  543. # Executes this command when master pgpool resigns from being master.
  544. # (change requires restart)
  545.  
  546. # - Watchdog consensus settings for failover -
  547.  
  548. failover_when_quorum_exists = on
  549. # Only perform backend node failover
  550. # when the watchdog cluster holds the quorum
  551. # (change requires restart)
  552.  
  553. failover_require_consensus = on
  554. # Perform failover when majority of Pgpool-II nodes
  555. # aggrees on the backend node status change
  556. # (change requires restart)
  557.  
  558. allow_multiple_failover_requests_from_node = off
  559. # A Pgpool-II node can cast multiple votes
  560. # for building the consensus on failover
  561. # (change requires restart)
  562.  
  563. # - Lifecheck Setting -
  564.  
  565. # -- common --
  566.  
  567. wd_monitoring_interfaces_list = '' # Comma separated list of interfaces names to monitor.
  568. # if any interface from the list is active the watchdog will
  569. # consider the network is fine
  570. # 'any' to enable monitoring on all interfaces except loopback
  571. # '' to disable monitoring
  572. # (change requires restart)
  573.  
  574. wd_lifecheck_method = 'heartbeat'
  575. # Method of watchdog lifecheck ('heartbeat' or 'query' or 'external')
  576. # (change requires restart)
  577. wd_interval =
  578. # lifecheck interval (sec) >
  579. # (change requires restart)
  580.  
  581. # -- heartbeat mode --
  582.  
  583. wd_heartbeat_port =
  584. # Port number for receiving heartbeat signal
  585. # (change requires restart)
  586. wd_heartbeat_keepalive =
  587. # Interval time of sending heartbeat signal (sec)
  588. # (change requires restart)
  589. wd_heartbeat_deadtime =
  590. # Deadtime interval for heartbeat signal (sec)
  591. # (change requires restart)
  592. heartbeat_destination0 = 'host0_ip1'
  593. # Host name or IP address of destination
  594. # for sending heartbeat signal.
  595. # (change requires restart)
  596. heartbeat_destination_port0 =
  597. # Port number of destination for sending
  598. # heartbeat signal. Usually this is the
  599. # same as wd_heartbeat_port.
  600. # (change requires restart)
  601. heartbeat_device0 = ''
  602. # Name of NIC device (such like 'eth0')
  603. # used for sending/receiving heartbeat
  604. # signal to/from destination .
  605. # This works only when this is not empty
  606. # and pgpool has root privilege.
  607. # (change requires restart)
  608.  
  609. #heartbeat_destination1 = 'host0_ip2'
  610. #heartbeat_destination_port1 =
  611. #heartbeat_device1 = ''
  612.  
  613. # -- query mode --
  614.  
  615. wd_life_point =
  616. # lifecheck retry times
  617. # (change requires restart)
  618. wd_lifecheck_query = 'SELECT 1'
  619. # lifecheck query to pgpool from watchdog
  620. # (change requires restart)
  621. wd_lifecheck_dbname = 'template1'
  622. # Database name connected for lifecheck
  623. # (change requires restart)
  624. wd_lifecheck_user = 'nobody'
  625. # watchdog user monitoring pgpools in lifecheck
  626. # (change requires restart)
  627. wd_lifecheck_password = ''
  628. # Password for watchdog user in lifecheck
  629. # (change requires restart)
  630.  
  631. # - Other pgpool Connection Settings -
  632.  
  633. #other_pgpool_hostname0 = 'host0'
  634. # Host name or IP address to connect to for other pgpool
  635. # (change requires restart)
  636. #other_pgpool_port0 =
  637. # Port number for other pgpool
  638. # (change requires restart)
  639. #other_wd_port0 =
  640. # Port number for other watchdog
  641. # (change requires restart)
  642. #other_pgpool_hostname1 = 'host1'
  643. #other_pgpool_port1 =
  644. #other_wd_port1 =
  645.  
  646. #------------------------------------------------------------------------------
  647. # OTHERS
  648. #------------------------------------------------------------------------------
  649. relcache_expire =
  650. # Life time of relation cache in seconds.
  651. # means no cache expiration(the default).
  652. # The relation cache is used for cache the
  653. # query result against PostgreSQL system
  654. # catalog to obtain various information
  655. # including table structures or if it's a
  656. # temporary table or not. The cache is
  657. # maintained in a pgpool child local memory
  658. # and being kept as long as it survives.
  659. # If someone modify the table by using
  660. # ALTER TABLE or some such, the relcache is
  661. # not consistent anymore.
  662. # For this purpose, cache_expiration
  663. # controls the life time of the cache.
  664.  
  665. relcache_size =
  666. # Number of relation cache
  667. # entry. If you see frequently:
  668. # "pool_search_relcache: cache replacement happend"
  669. # in the pgpool log, you might want to increate this number.
  670.  
  671. check_temp_table = on
  672. # If on, enable temporary table check in SELECT statements.
  673. # This initiates queries against system catalog of primary/master
  674. # thus increases load of master.
  675. # If you are absolutely sure that your system never uses temporary tables
  676. # and you want to save access to primary/master, you could turn this off.
  677. # Default is on.
  678.  
  679. check_unlogged_table = on
  680. # If on, enable unlogged table check in SELECT statements.
  681. # This initiates queries against system catalog of primary/master
  682. # thus increases load of master.
  683. # If you are absolutely sure that your system never uses unlogged tables
  684. # and you want to save access to primary/master, you could turn this off.
  685. # Default is on.
  686.  
  687. #------------------------------------------------------------------------------
  688. # IN MEMORY QUERY MEMORY CACHE
  689. #------------------------------------------------------------------------------
  690. memory_cache_enabled = off
  691. # If on, use the memory cache functionality, off by default
  692. memqcache_method = 'shmem'
  693. # Cache storage method. either 'shmem'(shared memory) or
  694. # 'memcached'. 'shmem' by default
  695. # (change requires restart)
  696. memqcache_memcached_host = 'localhost'
  697. # Memcached host name or IP address. Mandatory if
  698. # memqcache_method = 'memcached'.
  699. # Defaults to localhost.
  700. # (change requires restart)
  701. memqcache_memcached_port =
  702. # Memcached port number. Mondatory if memqcache_method = 'memcached'.
  703. # Defaults to .
  704. # (change requires restart)
  705. memqcache_total_size =
  706. # Total memory size in bytes for storing memory cache.
  707. # Mandatory if memqcache_method = 'shmem'.
  708. # Defaults to 64MB.
  709. # (change requires restart)
  710. memqcache_max_num_cache =
  711. # Total number of cache entries. Mandatory
  712. # if memqcache_method = 'shmem'.
  713. # Each cache entry consumes bytes on shared memory.
  714. # Defaults to ,,(.8MB).
  715. # (change requires restart)
  716. memqcache_expire =
  717. # Memory cache entry life time specified in seconds.
  718. # means infinite life time. by default.
  719. # (change requires restart)
  720. memqcache_auto_cache_invalidation = on
  721. # If on, invalidation of query cache is triggered by corresponding
  722. # DDL/DML/DCL(and memqcache_expire). If off, it is only triggered
  723. # by memqcache_expire. on by default.
  724. # (change requires restart)
  725. memqcache_maxcache =
  726. # Maximum SELECT result size in bytes.
  727. # Must be smaller than memqcache_cache_block_size. Defaults to 400KB.
  728. # (change requires restart)
  729. memqcache_cache_block_size =
  730. # Cache block size in bytes. Mandatory if memqcache_method = 'shmem'.
  731. # Defaults to 1MB.
  732. # (change requires restart)
  733. memqcache_oiddir = '/var/log/pgpool/oiddir'
  734. # Temporary work directory to record table oids
  735. # (change requires restart)
  736. white_memqcache_table_list = ''
  737. # Comma separated list of table names to memcache
  738. # that don't write to database
  739. # Regexp are accepted
  740. black_memqcache_table_list = ''
  741. # Comma separated list of table names not to memcache
  742. # that don't write to database
  743. # Regexp are accepted

vi pool_hba.conf修改后如下

  1. # pgpool Client Authentication Configuration File
  2. # ===============================================
  3. #
  4. # The format rule in this file follows the rules in the PostgreSQL
  5. # Administrator's Guide. Refer to chapter "Client Authentication" for a
  6. # complete description. A short synopsis follows.
  7. #
  8. # This file controls: which hosts are allowed to connect, how clients
  9. # are authenticated, which user names they can use, which databases they
  10. # can access. Records take one of these forms:
  11. #
  12. # local DATABASE USER METHOD [OPTION]
  13. # host DATABASE USER CIDR-ADDRESS METHOD [OPTION]
  14. #
  15. # (The uppercase items must be replaced by actual values.)
  16. #
  17. # The first field is the connection type: "local" is a Unix-domain
  18. # socket, "host" is either a plain or SSL-encrypted TCP/IP socket.
  19. #
  20. # DATABASE can be "all", "sameuser", a database name, or a comma-separated
  21. # list thereof. Note that "samegroup" like in PostgreSQL's pg_hba.conf
  22. # file is not supported, since pgpool does not know which group a user
  23. # belongs to. Also note that the database specified here may not exist in
  24. # the backend PostgreSQL. pgpool will authenticate based on the database's
  25. # name, not based on whether it exists or not.
  26. #
  27. # USER can be "all", a user name, or a comma-separated list thereof. In
  28. # both the DATABASE and USER fields you can also write a file name prefixed
  29. # with "@" to include names from a separate file. Note that a group name
  30. # prefixed with "+" like in PostgreSQL's pg_hba.conf file is not supported
  31. # because of the same reason as "samegroup" token. Also note that a user
  32. # name specified here may not exist in the backend PostgreSQL. pgpool will
  33. # authenticate based on the user's name, not based on whether he/she exists.
  34. #
  35. # CIDR-ADDRESS specifies the set of hosts the record matches.
  36. # It is made up of an IP address and a CIDR mask that is an integer
  37. # (between and (IPv4) that specifies the number of significant bits in
  38. # the mask. Alternatively, you can write an IP address and netmask in
  39. # separate columns to specify the set of hosts.
  40. #
  41. # METHOD can be "trust", "reject", "md5" or "pam". Note that "pam" sends passwords
  42. # in clear text.
  43. #
  44. # OPTION is the name of the PAM service. Default service name is "pgpool"
  45. #
  46. # Database and user names containing spaces, commas, quotes and other special
  47. # characters must be quoted. Quoting one of the keywords "all" or "sameuser"
  48. # makes the name lose its special character, and just match a database or
  49. # username with that name.
  50. #
  51. # This file is read on pgpool startup. If you edit the file on a running
  52. # system, you have to restart the pgpool for the changes to take effect.
  53.  
  54. # Put your actual configuration here
  55. # ----------------------------------
  56. #
  57. # If you want to allow non-local connections, you need to add more
  58. # "host" records. In that case you will also need to make pgpool listen
  59. # on a non-local interface via the listen_addresses configuration parameter.
  60. #
  61.  
  62. # TYPE DATABASE USER CIDR-ADDRESS METHOD
  63.  
  64. # "local" is for Unix domain socket connections only
  65. local all all trust
  66. # IPv4 local connections:
  67. host all all 0.0.0.0/ md5
  68. #host all all 127.0.0.1/ trust
  69. host all all ::/ trust

启用配置文件pool_passwd

  1. [root@pgpool etc]# pg_md5 -m -p -u postgres pool_passwd
  2. password:

创建主从切换脚本

  1. [root@pgpool bin]# vi /usr/local/bin/failover_stream.sh
  2. # Failover command for streaming replication.
  3. # This script assumes that DB node is primary, and is standby.
  4. #
  5. # If standby goes down, do nothing. If primary goes down, create a
  6. # trigger file so that standby takes over primary node.
  7. #
  8. # Arguments: $: failed node id. $: new master hostname. $: path to
  9. # trigger file.
  10.  
  11. failed_node=$
  12. new_master=$
  13. trigger_file=$
  14.  
  15. # Do nothing if standby goes down.
  16. if [ $failed_node = ]; then
  17. exit ;
  18. fi
  19.  
  20. # Create the trigger file.
  21. /usr/bin/ssh -T $new_master /bin/touch $trigger_file
  22.  
  23. exit ;
  24.  
  25. [root@pgpool bin]# chmod failover_stream.sh

启动pgpool

  1. [root@VM_176_134_centos pgpool-II]# pgpool -n -d > /tmp/pgpool.log >& &
  2. []
  3. [root@VM_176_134_centos pgpool-II]# ps -aux|grep pgpool
  4. root 0.0 0.0 pts/ S : : su pgpool
  5. pgpool 0.0 0.0 pts/ S : : bash
  6. root 0.0 0.0 pts/ S+ : : vi /var/log/pgpool/pgpool_status
  7. root 0.0 0.1 pts/ S : : pgpool -n -d
  8. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  9. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  10. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  11. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  12. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  13. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  14. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  15. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  16. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  17. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  18. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  19. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  20. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  21. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  22. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  23. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  24. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  25. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  26. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  27. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  28. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  29. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  30. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  31. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  32. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  33. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  34. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  35. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  36. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  37. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  38. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  39. root 0.0 0.0 pts/ S : : pgpool: wait for connection request
  40. root 0.0 0.0 pts/ S : : pgpool: PCP: wait for connection request
  41. root 0.0 0.0 pts/ S : : pgpool: worker process
  42. root 0.0 0.0 pts/ S : : pgpool: health check process()
  43. root 0.0 0.0 pts/ R+ : : grep --color=auto pgpool
  44. [root@VM_176_134_centos pgpool-II]#

启动两台服务器数据库

  1. [root@VM_176_134_centos pgpool-II]# systemctl start postgresql
  2. [root@VM_176_134_centos pgpool-II]# ps -aux|grep postgresql
  3. root 0.0 0.0 pts/ S+ : : grep --color=auto postgresql
  4. [root@VM_176_134_centos pgpool-II]# ps -aux|grep postgres
  5. postgres 0.0 0.2 ? S : : /usr/bin/postgres -D /var/lib/pgsql/data -p
  6. postgres 0.0 0.0 ? Ss : : postgres: logger process
  7. postgres 0.0 0.0 ? Ss : : postgres: checkpointer process
  8. postgres 0.0 0.0 ? Ss : : postgres: writer process
  9. postgres 0.0 0.0 ? Ss : : postgres: wal writer process
  10. postgres 0.0 0.0 ? Ss : : postgres: autovacuum launcher process
  11. postgres 0.0 0.0 ? Ss : : postgres: stats collector process
  12. root 0.0 0.0 pts/ S+ : : grep --color=auto postgres
  13. [root@VM_176_134_centos pgpool-II]#

连接测试

1.连接pgpool,能看到235的数据

2.在pgpool新建test_pgpool表,235的数据库也可以看到表,但备机197上似乎没有看到test_pgpool

 

3.修改配置文件

  1. vi pgpool.conf
  2.  
  3. 改下面两个属性
  4. replication_mode = true
  5. load_balance_mode = true
  6.  
  7. 然后关闭客户端的连接
  8. 235上停止pgpool: pgpool stop
  9. 235上启动pgpool: pgpool

4.通过主节点建表test_pgpool2,可以看到主、备节点均有test_pgpool2

 

5.关掉235上的postgresql,看看能否切换到197

  1. [root@VM_176_134_centos pgpool-II]# systemctl stop postgresql
  2. [root@VM_176_134_centos pgpool-II]# ps -aux|grep postgres
  3. root 0.0 0.0 ? S : : pgpool: postgres postgres 113.116.51.86() idle
  4. root 0.0 0.0 pts/ R+ : : grep --color=auto postgres
  5. [root@VM_176_134_centos pgpool-II]#

可以看到已经切换到197了,表明在运行中,如果235挂掉了,还有197可用。

但是发现再启动235后的数据库后,pgpool不会自动切回来,可能切换脚本有问题,这个不弄了,等专业的来

参考

官方文档:pgpool-II 入门教程

PostgreSQL+pgpool-II复制方案

pgpool-II主备流复制的架设

centos7 pgpool+postgresql的更多相关文章

  1. 19.CentOS7下PostgreSQL安装过程

    CentOS7下PostgreSQL安装过程 装包 sudo yum install postgresql-server postgresql-contrib 说明: 这种方式直接明了,其他方法也可以 ...

  2. centos7部署postgresql集群高可用 patroni + etcd 之patroni篇

    实验环境:centos7.4纯净版 postgres版本: 9.6.15 etcd版本:3.3.11 patroni版本:1.6.0 patroni介绍可参考:https://github.com/z ...

  3. centos7下postgresql数据库安装及配置

    1.安装 #yum install -y postgresql-server 2.postgresql数据库初始化 #service postgresql initdb 3.启动postgresql服 ...

  4. pgpool postgresql集群、中间件

    pgpool-II是一个工作于PostgreSQL服务器端和PostgreSQL客户端之间的中间件,它提供了如下的功能: 1.连接池 pgpool-II中保存了到PostgreSQL服务器的连接,然后 ...

  5. CentOS7安装Postgresql

    执行命令 Yum install postgresql-server Yum install postgresql-contrib 安装完成后,检查postgresql的服务状态 Systemctl ...

  6. 阿里云ecs centos7安装 postgresql 9.4

    rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-3.noarch.rpm yum insta ...

  7. Centos7安装 PostgreSQL步骤

    1. 安装服务器即可. Yum install postgresql-server Yum install postgresql-contrib 2. 验证是否安装成功: rpm -aq| grep ...

  8. centos7 安装 PostgreSql

    确定你是管理员,然后运行命令: yum -y install postgresql-server postgresql-contrib 初始化数据库 postgresql-setup initdb 启 ...

  9. CentOS7 安装Postgresql 11+ 源码编译安装Postgis-2.5.2

    ####安装Postgresql-11yum install zlib-devel gcc makegroupadd postgresuseradd -g postgres postgrespassw ...

随机推荐

  1. vuex的数据交互

    methods:{ ...mapMutations({aaa:hs}) //将mutations的方法暴露出来,进行调用 aaa是他的名字 ...mapActions(['hs']) //将actio ...

  2. scipy优化器optimizer

    #optimazer优化器 from scipy.optimize import minimize def rosem(x): return sum(100.0*(x[1:]-x[:-1])**2.0 ...

  3. VS2017+WIN10自动生成类、接口的说明(修改类模板的方法)

    微软发布VS2017的时候,我第一时间离线一份专业版,安装到了自己的电脑上,开始体验,但是问题来了,在开发中建立类和接口的时候,说 明注释总要自己写一次,烦!~~于是还是像以前一样改IDE默认的类和接 ...

  4. arctan

    ArcTanWhen the ArcTan functional configuration is selected, the input vector (X_IN,Y_IN) is rotated( ...

  5. face parsing

    主页:https://www.sifeiliu.net/project 基于CNN face parsing: https://www.sifeiliu.net/face-parsing codes: ...

  6. Flask-sqlacodegen

    ORM操作有两种方式. 1.模型迁移到数据库中生成表,codefirst:使用flask-migrate: 需要flask-script: from flask_script import Manag ...

  7. Codeforces Round #416 (Div. 2) B. Vladik and Complicated Book

    B. Vladik and Complicated Book time limit per test 2 seconds memory limit per test 256 megabytes inp ...

  8. 25 行 Python 代码实现人脸识别——OpenCV 技术教程

    OpenCV OpenCV 是最流行的计算机视觉库,原本用 C 和 C++ 开发,现在也支持 Python. 它使用机器学习算法在图像中搜索人的面部.对于人脸这么复杂的东西,并没有一个简单的检测能对是 ...

  9. 【BZOJ2111】[ZJOI2010]排列计数(组合数学)

    [BZOJ2111][ZJOI2010]排列计数(组合数学) 题面 BZOJ 洛谷 题解 就是今年九省联考\(D1T2\)的弱化版? 直接递归组合数算就好了. 注意一下模数可以小于\(n\),所以要存 ...

  10. volatile的实现原理与应用

    Java代码在编译后会变成Java字节码,字节码被类加载器加载到JVM里,JVM执行字节码,最终需要转化为汇编指令在CPU上执行,Java中所使用的并发机制依赖于JVM的实现和CPU的指令. vola ...