|
| 1 | +:sectnums: |
| 2 | +:sectnumlevels: 5 |
| 3 | + |
| 4 | += Pgpool-II |
| 5 | + |
| 6 | +== Overview |
| 7 | + |
| 8 | +Pgpool-II is middleware placed between database clients and IvorySQL servers. It provides persistent backend connection pools, health and streaming-replication checks, read-query load balancing, and building blocks for automated failover. |
| 9 | + |
| 10 | +This guide was verified with IvorySQL 5.4 (PostgreSQL 18.4) and Pgpool-II 4.7.2 on Ubuntu 22.04 x86_64. The validation used one IvorySQL primary and one streaming-replication standby. |
| 11 | + |
| 12 | +== Verified compatibility |
| 13 | + |
| 14 | +[cols="2,1,3"] |
| 15 | +|=== |
| 16 | +|Capability |Status |Verification |
| 17 | + |
| 18 | +|Build against IvorySQL client libraries |
| 19 | +|Supported |
| 20 | +|Pgpool-II was configured with the IvorySQL installation prefix and built successfully |
| 21 | + |
| 22 | +|Backend connection pooling |
| 23 | +|Supported |
| 24 | +|Repeated client sessions reused Pgpool-II child-process backend pools |
| 25 | + |
| 26 | +|Streaming-replication discovery |
| 27 | +|Supported |
| 28 | +|`SHOW POOL_NODES` identified the primary and standby correctly |
| 29 | + |
| 30 | +|Read-query load balancing |
| 31 | +|Supported |
| 32 | +|Both nodes received SELECT queries with equal configured weights |
| 33 | + |
| 34 | +|Oracle-compatible sessions |
| 35 | +|Supported with notes |
| 36 | +|A session switched to `ivorysql.compatible_mode = oracle` and queried through Pgpool-II successfully |
| 37 | +|=== |
| 38 | + |
| 39 | +== Prerequisites |
| 40 | + |
| 41 | +* IvorySQL 5.4 is installed on every database node. |
| 42 | +* IvorySQL streaming replication is already working and the standby accepts read-only queries. |
| 43 | +* The build host has a C compiler, GNU make, Flex, Bison, and OpenSSL development files. |
| 44 | +* Pgpool-II can reach the PostgreSQL-compatible port of every IvorySQL node. |
| 45 | + |
| 46 | +[IMPORTANT] |
| 47 | +Pgpool-II does not create or repair IvorySQL streaming replication. Verify replication independently before enabling Pgpool-II. |
| 48 | + |
| 49 | +== Build and install Pgpool-II |
| 50 | + |
| 51 | +[source,shell] |
| 52 | +---- |
| 53 | +curl -LO https://www.pgpool.net/source/pgpool-II-4.7.2.tar.gz |
| 54 | +tar -xzf pgpool-II-4.7.2.tar.gz |
| 55 | +cd pgpool-II-4.7.2 |
| 56 | +
|
| 57 | +./configure \ |
| 58 | + --prefix=/usr/local/pgpool-II-4.7.2 \ |
| 59 | + --with-pgsql=/usr/local/ivorysql/ivorysql-5 \ |
| 60 | + --with-openssl |
| 61 | +make -j"$(nproc)" |
| 62 | +sudo make install |
| 63 | +---- |
| 64 | + |
| 65 | +Replace the IvorySQL prefix with the directory that contains `bin/pg_config`, `include/postgresql`, and `lib` in your installation. |
| 66 | + |
| 67 | +Confirm that Pgpool-II uses the expected version: |
| 68 | + |
| 69 | +[source,shell] |
| 70 | +---- |
| 71 | +/usr/local/pgpool-II-4.7.2/bin/pgpool --version |
| 72 | +---- |
| 73 | + |
| 74 | +== Prepare a monitoring role |
| 75 | + |
| 76 | +Create the same login on the primary and make sure its definition reaches the standby. Membership in `pg_monitor` lets Pgpool-II inspect streaming-replication state without using a superuser account. |
| 77 | + |
| 78 | +[source,sql] |
| 79 | +---- |
| 80 | +CREATE ROLE pgpoolcheck LOGIN PASSWORD 'replace-with-a-strong-password'; |
| 81 | +GRANT pg_monitor TO pgpoolcheck; |
| 82 | +---- |
| 83 | + |
| 84 | +Use `pool_passwd` or an operating-system password file instead of putting a production password directly in `pgpool.conf`. Pgpool-II supports SCRAM authentication; configure matching rules in `pool_hba.conf` and the IvorySQL `pg_hba.conf` files. |
| 85 | + |
| 86 | +== Configure Pgpool-II |
| 87 | + |
| 88 | +Start from the installed `pgpool.conf.sample`. The following excerpt shows the settings essential to a two-node validation deployment: |
| 89 | + |
| 90 | +[source,ini] |
| 91 | +---- |
| 92 | +backend_clustering_mode = 'streaming_replication' |
| 93 | +
|
| 94 | +listen_addresses = 'localhost' |
| 95 | +port = 9999 |
| 96 | +unix_socket_directories = '/tmp' |
| 97 | +
|
| 98 | +backend_hostname0 = '10.0.0.11' |
| 99 | +backend_port0 = 5333 |
| 100 | +backend_weight0 = 1 |
| 101 | +backend_data_directory0 = '/data/ivorysql/primary' |
| 102 | +backend_flag0 = 'DISALLOW_TO_FAILOVER' |
| 103 | +backend_application_name0 = 'ivory_primary' |
| 104 | +
|
| 105 | +backend_hostname1 = '10.0.0.12' |
| 106 | +backend_port1 = 5333 |
| 107 | +backend_weight1 = 1 |
| 108 | +backend_data_directory1 = '/data/ivorysql/standby' |
| 109 | +backend_flag1 = 'DISALLOW_TO_FAILOVER' |
| 110 | +backend_application_name1 = 'ivory_standby' |
| 111 | +
|
| 112 | +load_balance_mode = on |
| 113 | +sr_check_period = 10 |
| 114 | +sr_check_user = 'pgpoolcheck' |
| 115 | +sr_check_database = 'postgres' |
| 116 | +
|
| 117 | +health_check_period = 10 |
| 118 | +health_check_user = 'pgpoolcheck' |
| 119 | +health_check_database = 'postgres' |
| 120 | +---- |
| 121 | + |
| 122 | +`DISALLOW_TO_FAILOVER` is intentional in this minimal configuration: it prevents an incomplete example from promoting or detaching nodes automatically. Before using `ALLOW_TO_FAILOVER`, configure and test `failover_command`, standby promotion, follow-primary handling, fencing, and optionally Watchdog. |
| 123 | + |
| 124 | +Start Pgpool-II in the foreground while validating the configuration: |
| 125 | + |
| 126 | +[source,shell] |
| 127 | +---- |
| 128 | +/usr/local/pgpool-II-4.7.2/bin/pgpool \ |
| 129 | + -n -f /etc/pgpool-II/pgpool.conf |
| 130 | +---- |
| 131 | + |
| 132 | +== Verify the integration |
| 133 | + |
| 134 | +Connect to the Pgpool-II port rather than directly to a backend: |
| 135 | + |
| 136 | +[source,shell] |
| 137 | +---- |
| 138 | +psql -h pgpool-host -p 9999 -U application_user -d application_db |
| 139 | +---- |
| 140 | + |
| 141 | +Check node discovery and query distribution: |
| 142 | + |
| 143 | +[source,sql] |
| 144 | +---- |
| 145 | +SHOW POOL_NODES; |
| 146 | +SELECT count(*) FROM application_table; |
| 147 | +SHOW POOL_NODES; |
| 148 | +SHOW POOL_PROCESSES; |
| 149 | +---- |
| 150 | + |
| 151 | +In the IvorySQL 5.4 validation, Pgpool-II reported both nodes as `up`, assigned roles `primary` and `standby`, and showed a replication delay of zero. With equal weights, 21 initial read queries were distributed 9 to the primary and 12 to the standby. |
| 152 | + |
| 153 | +== Oracle-compatible mode |
| 154 | + |
| 155 | +Oracle compatibility can be enabled through the pooled PostgreSQL-compatible connection: |
| 156 | + |
| 157 | +[source,sql] |
| 158 | +---- |
| 159 | +SET ivorysql.compatible_mode = oracle; |
| 160 | +SELECT 'connected through Pgpool-II' AS status FROM dual; |
| 161 | +---- |
| 162 | + |
| 163 | +The validation succeeded through Pgpool-II and continued to use the replicated backend pair. |
| 164 | + |
| 165 | +== Operational considerations |
| 166 | + |
| 167 | +* This guide validates Pgpool-II on IvorySQL's PostgreSQL-compatible endpoint. It does not validate proxying an Oracle client protocol through `ivorysql.port`. |
| 168 | +* Pgpool-II parses SQL to decide where to route it. Test application-specific Oracle syntax and route statements that must see the newest data to the primary. |
| 169 | +* Asynchronous streaming replication can return stale data from a standby. Configure delay thresholds or synchronous replication according to the application's consistency requirements. |
| 170 | +* Do not expose Pgpool-II with `trust` authentication. Use TLS, SCRAM, restricted listen addresses, and least-privilege monitoring accounts in production. |
| 171 | +* Automatic failover is a separate high-availability design. Test promotion, fencing, client retry, and split-brain prevention before enabling it. |
| 172 | + |
| 173 | +For production options, see the https://www.pgpool.net/docs/4.7/en/html/[Pgpool-II 4.7 documentation]. |
0 commit comments