Tatsuo Ishii [Mon, 21 Aug 2023 07:05:40 +0000 (16:05 +0900)]
Doc: enhance follow primary command manual.
Mention that it is necessary to run pcp_attach_node if
pcp_recovery_node is not used.
Tatsuo Ishii [Mon, 21 Aug 2023 02:02:09 +0000 (11:02 +0900)]
Test: enhance pgpool_setup.
Enhance failover script generation and follow primary script
generation so that they create better logging.
Tatsuo Ishii [Sat, 19 Aug 2023 06:44:02 +0000 (15:44 +0900)]
Feature: allow to set delay_threshold_by_time in milliseconds.
Previously it was allowed only in seconds. Also put some
refactoring. Create new function "check_replication_delay" which
checks the replication delay and returns 0, -1 or -2, depending on "no
delay", "delayed (delay_threshold_by_time)" or "delayed
(delay_threshold)" accordingly. This should simplify the lengthy
if-statement to check the replication delay.
Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2023-August/004372.html
Tatsuo Ishii [Sat, 19 Aug 2023 06:22:51 +0000 (15:22 +0900)]
Comment: add comment to child process and auth staffs.
Chen Ningwei [Tue, 15 Aug 2023 03:31:41 +0000 (12:31 +0900)]
Doc: add release notes.
Tatsuo Ishii [Wed, 9 Aug 2023 02:10:28 +0000 (11:10 +0900)]
Fix covery warning.
Fix query cache module assigned time_t value to int32 variable. Change
the variable type to int64. Per Coverity. Also use difftime() to
calculate time_t difference. This is a recommended practice.
https://www.jpcert.or.jp/sc-rules/c-msc05-c.html
Bo Peng [Fri, 4 Aug 2023 04:43:33 +0000 (13:43 +0900)]
Fix find_primary_node_repeatedly doesn't terminate within search_primary_node_timeout.
Bo Peng [Thu, 3 Aug 2023 07:57:45 +0000 (16:57 +0900)]
Doc: fix the missing "logger" application name.
Tatsuo Ishii [Tue, 1 Aug 2023 08:20:49 +0000 (17:20 +0900)]
Remove non-standard "//" comments.
Chen Ningwei [Tue, 1 Aug 2023 06:36:31 +0000 (15:36 +0900)]
Add header include to pgstrcasecmp.c
Tatsuo Ishii [Tue, 1 Aug 2023 02:49:26 +0000 (11:49 +0900)]
Doc: clarify the meaning of stop mode.
Chen Ningwei [Mon, 31 Jul 2023 05:17:33 +0000 (14:17 +0900)]
Feature: Import PostgreSQL 16 BETA1 new parser.
Major changes of PostgreSQL 16 parser include:
- Add new option DEFAULT to COPY FROM
COPY ... FROM stdin WITH (default 'xx');
- Allow the STORAGE type to be specified by CREATE TABLE
CREATE TABLE t1 (
c1 VARCHAR(10) STORAGE PLAIN,
c2 TEXT STORAGE EXTENDED
);
- Add EXPLAIN option GENERIC_PLAN to display the generic plan for a parameterized query
EXPLAIN (GENERIC_PLAN) SELECT ...;
- Allow subqueries in the FROM clause to omit aliases
SELECT COUNT(*) FROM (SELECT ... FROM ...);
- Add SQL/JSON constructors
- Add VACUUM options
SKIP_DATABASE_STATS, ONLY_DATABASE_STATS to skip or update all frozen statistics
PROCESS_MAIN to only process TOAST tables
VACUUM (SKIP_DATABASE_STATS);
VACUUM (PROCESS_MAIN FALSE) t1 ;
Bo Peng [Wed, 26 Jul 2023 03:55:06 +0000 (12:55 +0900)]
Doc: remove the incorrect information from release note 4.2.10.
Remove "Fix pgpool_recovery extension script. (Tatsuo Ishii)" from release note 4.2.10.
Tatsuo Ishii [Sun, 23 Jul 2023 21:04:27 +0000 (06:04 +0900)]
Add new field "load_balance_node" to "SHOW pool_pools" and pcp_proc_info.
The new field is "1" if pgpool process is connected by a client and
the session uses the backend id as a load balance node. Users can
execute the commands to find out if there's any session that uses the
backend as the load balance node. If so, shutting down the backend may
cause session disconnection.
Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2023-July/004353.html
Note: I accidentally pushed only doc part of the commit in
4658f84870e8edfd39920f273bab1a12d71d8986.
This is a follow-up commit for actual codes.
Muhammad Usama [Sun, 23 Jul 2023 17:34:05 +0000 (22:34 +0500)]
Install system exit callback only after initialization of shared memory.
When the on-exit callback gets called because of a failure to acquire
shared memory. The cleanup function can produce a segfault while accessing
process_info, that lives in shared memory.
Although we can also fix this by bailing out from the exit callback when
process_info is NULL but installing the function after successful initialization
of shared memory is a better approach as the rest of the system always assumes
the process_info can never be NULL, and also, there is nothing to
clean up before child processes are spawned.
Muhammad Usama [Sun, 23 Jul 2023 17:32:22 +0000 (22:32 +0500)]
Verify the spare children config values only in dynamic process management mode
As suggested by Tatsuo Ishii there is no point in verifying the validity of
min and max spare children configurations for static process management mode,
As these configuration values get ignored in static mode anyway.
Tatsuo Ishii [Sun, 23 Jul 2023 01:33:49 +0000 (10:33 +0900)]
Add new field "load_balance_node" to "SHOW pool_pools" and pcp_proc_info.
The new field is "1" if pgpool process is connected by a client and
the session uses the backend id as a load balance node. Users can
execute the commands to find out if there's any session that uses the
backend as the load balance node. If so, shutting down the backend may
cause session disconnection.
Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2023-July/004353.html
Muhammad Usama [Sat, 22 Jul 2023 13:54:31 +0000 (18:54 +0500)]
Disallowing setting the max_spare_children greater than num_init_children.
Config post-processing stage now throws an error if num_init_children is
smaller than max_spare_children.
Commit also adjusts the number of child processes spawned at startup based on
the configured process management strategy.
For the Aggressive strategy, max_spare_children number of processes is spawned;
for the other two strategies, min_spare_children number of children gets
created at startup.
Tatsuo Ishii [Tue, 18 Jul 2023 01:10:27 +0000 (10:10 +0900)]
Mitigate session disconnection issue in failover/failback/backend error.
Previously Pgpool-II disconnected client sessions in various
cases. This commit tries to avoid some of cases, especially when a
backend goes down and the backend is not either primary (or main node)
nor load balance node.
Suppose we have 3 streaming replication PostgreSQL cluster and the
client uses primary (node 0) and standby 1 (node 1), but does not use
standby 2 (node 2) because the node 2 is not load balance node. In
this case ideally shutting down node 2 should not disconnect the
session. However the session is disconnected if the session processing
a query while failover. The reason why session disconnection in
failover is necessary is, there are bunch of places in the source code
something like this:
for (i = 0; i < NUM_BACKENDS; i++)
{
if (!VALID_BACKEND(i))
continue;
:
:
VALID_BACKEND returns true if the backend is not in down status. If
this code is executed while failover, the code may access the backend
socket which is not available any more and will cause troubles
including segfault. So inside VALID_BACKEND, we check whether failover
is performed, and if so, the pgpool child process exits and the
session disconnects. To aovid it, change VALID_BACKEND so that it
waits for completion of failover. For this purpose new function
wait_for_failover_to_finish() is added. It waits for the completion of
failover up to MAX_FAILOVER_WAIT seconds (for it's fixed to 30). The
change above will prevent unnecessary session disconnection for
existing sessions.
This commit also tries to prevent unnecessary session disconnection
while accepting new sessions. There are multiple places where it could
happen and this commit fixes them:
- accepting new connection from client. In wait_for_new_connections,
call wait_for_failover_to_finish to wait for completion of
failover.
- creating new connection to backend. After accepting connection
request from client and before creating connection to backend, call
wait_for_failover_to_finish to wait for completion of failover.
- fixing broken socket. pool_get_cp checks whether exiting backend
connection is broken. If it's broken, sleep 1 second to expect
failover happens then calls wait_for_failover_to_finish().
- processing an application name. If an application name is included
in a startup message, pgpool sends query like "SET application_name
TO foo" to all backend nodes including node 2, which could cause a
write error. To prevent the error, I modified
connect_using_existing_connection, which is sending the SET command
using do_command, so that do_command does not raise an ERROR by
wrapping it in TRY/CATCH block.
Note that even with all fixes above, I was not able to fix some cases
where pool_write raises error. pool_write is used to write to backend
socket and there are too many places to fix all of them. For now we
need to run "pcp_detach_node 2" before shutdown it. pcp_detach_node
will tell all pgpool child process that node 2 is going down. Even if
a child process does not notice it and writes to backend 2 socket,
there will be no error because node 2 is still alive.
Finally this commit adds new regression test case
037.failover_session. For the test pgbench is used. There are 2 cases
for continuous session (without -C option) and repeating
connection/disconnection (with -C option) each. So there are 4 causes
in the test:
"=== test1: backend_weight2 = 0 and pgbench without -C option"
"=== test2: backend_weight2 = 0 and pgbench with -C option"
"=== test3: load_balance_mode = off and pgbench without -C option"
"=== test4: load_balance_mode = off and pgbench with -C option"
test2 and test4 requires pcp_detach_node before shutting down node 2.
Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2023-July/004352.html
Tatsuo Ishii [Mon, 17 Jul 2023 10:27:43 +0000 (19:27 +0900)]
Fix crash when v2 protocol is used.
When read_kind_from_backend() accumulates statistics data, it was not
prepared for v2 protocol case.
Bug report and patch from MCanivez.
https://www.pgpool.net/mantisbt/view.php?id=807
Slightly modified by me.
Tatsuo Ishii [Wed, 12 Jul 2023 07:35:46 +0000 (16:35 +0900)]
Fix PREPARE in multi-statement case.
If multi-statement query includes PREPARE in the second or latter
position, and subsequent bind message uses the prepared statement, it
fails with "unable to bind" error because the prepared statement is not
saved in sent messages.
To fix this if such a case found after parsing the statement, create a
query context for the named statement and add it to the sent message
list.
Discussion: https://www.pgpool.net/pipermail/pgpool-general/2023-July/008931.html
For this new regression test 079..multi_prepare is added.
Bo Peng [Tue, 11 Jul 2023 06:10:20 +0000 (15:10 +0900)]
Doc: Enhance SSH public key authentication setting section in "8.2. Pgpool-II + Watchdog Setup Example".
Tatsuo Ishii [Sun, 9 Jul 2023 10:09:26 +0000 (19:09 +0900)]
Fix pgproto to work with bind message using params.
Previously pgproto can only process bind messages without params.
Bo Peng [Wed, 5 Jul 2023 08:08:04 +0000 (17:08 +0900)]
Fix typo in log message.
Tatsuo Ishii [Thu, 29 Jun 2023 02:27:31 +0000 (11:27 +0900)]
Doc: fix load balance mode chapter.
In some places "streaming replication mode" was written as "native
replication mode". Also enhance description regarding additional
requirements for load balancing in the streaming replication mode.
Add some indexes.
Tatsuo Ishii [Thu, 29 Jun 2023 01:51:14 +0000 (10:51 +0900)]
Downgrade log message.
It is pointed out in https://www.pgpool.net/mantisbt/view.php?id=806
that there are log entries in the log file:
LOG: pool_pending_message_set_flush_request: msg: Parse
The messages were for debugging and the log level should have been a
DEBUG*. So I changed the log level from LOG to DEBUG5.
Tatsuo Ishii [Wed, 28 Jun 2023 02:56:29 +0000 (11:56 +0900)]
Doc: fix load balance mode chapter.
In some places "streaming replication mode" was written as "native
replication mode". Also enhance description regarding additional
requirements for load balancing in the streaming replication mode.
Add some indexes.
Bo Peng [Tue, 27 Jun 2023 02:46:17 +0000 (11:46 +0900)]
Doc: enhance online recovery documentation.
Mention that 2nd stage of online recovery does not work properly only for multiple pgpool nodes without watchdog enabled.
Bo Peng [Fri, 23 Jun 2023 08:05:53 +0000 (17:05 +0900)]
Fix missing CTE SEARCH and CYCLE rewrites.
In native replication mode, Pgpool-II need to rewrite Date/Time functions to timestamp in WRITE queries.
CTE SEARCH and CYCLE rewrites were missing.
Bo Peng [Mon, 19 Jun 2023 04:19:00 +0000 (13:19 +0900)]
Removed duplicate pcp_listen_address setting in src/sample/pgpool.conf.sample-stream.
Tatsuo Ishii [Wed, 14 Jun 2023 02:17:38 +0000 (11:17 +0900)]
Prevent query cache update under shared lock.
In https://www.pgpool.net/mantisbt/view.php?id=795 it was pointed out
that expired query cache entry can be modified under shared lock. This
could cause shared memory corruption used by query cache. In order to
fix this, we temporarily release the shared lock and then acquire an
exclusive lock before modifying the cache entry. This could create a
window and we need to get the cache entry meta data again to make sure
that the meta data has not been modified by someone else.
Back-patch to V4.4 stable where shared locking for query cache was
introduced.
Bo Peng [Tue, 13 Jun 2023 05:56:29 +0000 (14:56 +0900)]
Feature: allow to route queries to a specific backend node for a specific user connection.
This commit adds a new parameter "user_redirect_preference_list" to
allow to send SELECT queries to a specific backend node for a
specific user connection.
Tatsuo Ishii [Mon, 12 Jun 2023 00:46:47 +0000 (09:46 +0900)]
Add schema qualification to some system catalog inquiry functions.
There were a few places where schema qualification were not used while
issuing system catalog inquiry.
Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2023-June/004346.html
Chen Ningwei [Tue, 6 Jun 2023 05:38:49 +0000 (14:38 +0900)]
Feature: Support mutiple directories specification for pcp_socket_dir.
Tatsuo Ishii [Mon, 5 Jun 2023 11:18:36 +0000 (20:18 +0900)]
Fix delay_threshold_by_time and prefer_lower_standby_delay.
They were broken since delay_threshold_by_time was introduced in 4.4.
- delay_threshold_by_time was not checked in where_to_send. This broke
load balancing when replication is delayed.
- select_load_balancing_node was broken if both
delay_threshold_by_time and prefer_lower_standby_delay were enabled.
In order to fix the issue, where_to_send and
select_load_balancing_node are fixed. Also add test case for
delay_threshold_by_time are added to 033.prefer_lower_standby_delay.
Discussion: https://www.pgpool.net/pipermail/pgpool-general/2023-June/008864.html
Bo Peng [Tue, 30 May 2023 13:17:33 +0000 (22:17 +0900)]
Fix the wrong variable names in replication_mode_recovery_2nd_stage.sample sample script.
Tatsuo Ishii [Mon, 22 May 2023 07:27:40 +0000 (16:27 +0900)]
Test: fix occasional 069.memory_leak_extended test failure.
It turned out that reason of the occasional test failure is, pgpool
child process is gone before running ps command after pgbench
finishes. The cause is a kind mismatch FATAL error, "DISCARD ALL
cannot be executed within a pipeline". To fix this, run pgbench in
background and get the process size before pgbench finishes.
Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2023-May/004338.html
Tatsuo Ishii [Fri, 19 May 2023 06:27:57 +0000 (15:27 +0900)]
Allow to load balance PREPARE/EXECUTE/DEALLOCATE.
Previously PREPARE/EXECUTE/DEALLOCATE are not load balanced. In
streaming replication/logical replication mode, they were sent to
always primary node. In native replication/snapshot isolation
mode,they were always sent to all nodes.
Now they can be load balanced if the SQL statement prepared by PREPARE
command is a read only SELECT.
For this purpose following changes were made:
- is_select_query() looks into "query" member if node is
PrepareStmt. Also second argument "sql" (query string) is not now
mandatory. If sql is NULL, warning is emitted and this function
returns false. If allow_sql_comments is off and node is PrepareStmt
and query is SelectStmt, is_select_query() does not return false
anymore.
- pool_has_function_call() looks into "query" member if node is
PrepareStmt.
- Add PREPARE/EXECUTE/DEALLOCATE test cases to 001.load_balance test.
- Add send_prepare() function which is similar to parse_before_bind in
extended query protocol case to keep up
disable_load_balance_on_write rule. send_prepare() is called by
SimpleQuery() when EXECUTE message is sent by frontend in SL mode so
that it sends PREPARE message to primary node if it has not sent to
primary because of load balance. Note that send_prepare() does
nothing if the clustering mode is other than SL mode. In native
replication mode or snapshot isolation mode, all backend has the
same data, and there's no point to keep up
disable_load_balance_on_write rule.
- Remove descriptions of restrictions regarding load balance for
PREPARE/EXECUTE/DEALLOCATE in "Restrictions" section in the docs.
Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2023-May/004334.html
Tatsuo Ishii [Fri, 19 May 2023 00:00:29 +0000 (09:00 +0900)]
Remove pool_config.c and scan.c from git repository.
They are generated files and we should not keep in the git repository.
Bo Peng [Wed, 17 May 2023 12:11:20 +0000 (21:11 +0900)]
Doc: modify release notes.
Bo Peng [Wed, 17 May 2023 11:48:49 +0000 (20:48 +0900)]
Doc: add release notes.
Tatsuo Ishii [Fri, 12 May 2023 08:16:01 +0000 (17:16 +0900)]
Test: stabilize some tests.
069.memory_leak_extended, 070.memory_leak_extended_memqcache and
073.pg_terminate_backend uses "sleep 1" to confirm pgpool starting up,
which makes the tests unstable because there's no guarantee that pgpool
becomes ready within 1 second. Use wait_for_pgpool_startup instead to
stabilize the tests.
Tatsuo Ishii [Mon, 8 May 2023 00:58:17 +0000 (09:58 +0900)]
Refactor pool_where_to_send.
pool_where_to_send() is a module in charge of judging where to a query
in terms of load balancing. It had been already big and I felt
difficulty to maintain it. Therefore I extracted two relatively large
code path, namely for streaming replication mode and native
replication mode (plus snapshot isolation mode) into
where_to_send_main_replica() and where_to_send_native_replication()
respectively.
Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2023-May/004333.html
Tatsuo Ishii [Sun, 7 May 2023 02:24:45 +0000 (11:24 +0900)]
Refactor send_to_where().
Previously it had lengthy list of recognized query nodes to find out
unrecognized query quickly. The list must be updated if PostgreSQL
adds new query node. Since the list does very small contribution to
performance with large maintenance pain, I decided that keeping the
query node list is not worth the trouble and remove the list.
Also the second argument of send_to_where() is not actually used, I
remove the argument.
Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2023-May/004332.html
Tatsuo Ishii [Tue, 2 May 2023 00:38:44 +0000 (09:38 +0900)]
Test: unbreak 033.prefer_lower_standby_delay.
Commit "
7a28bbb1 Fix 033.prefer_lower_standby_delay" broke
033.prefer_lower_standby_delay for PostgreSQL 13 or before because
they do not have pg_get_wal_replay_pause_state().
Tatsuo Ishii [Sun, 30 Apr 2023 06:41:02 +0000 (15:41 +0900)]
Fix prefer_lower_delay_standby bug.
When client connects to pgpool, one of standbys are chosen as the load
balancing node. If standby delay exceeds delay_threshold while the
session continues, prefer_lower_delay_standby will choose the least
delay standby node as the new load balancing node and set the target
backend to the node. Unfortunately the decision was made *before* the
checking that SELECT query includes writing function etc., pgpool
happily sends SELECT which cannot be executed on standby. To fix
this, prefer_lower_delay_standby treatment is moved after the writing
function etc. check.
033.prefer_lower_standby_delay regression test is modified to include
the case above. Also I have done some refactoring:
- Remove unnecessary while loop for each clustering mode because the
test is only useful for streaming replication mode.
- Add checking wal_replay_pause is actually executed.
Bug reported by: https://www.pgpool.net/mantisbt/view.php?id=798
along with suggested fix.
Tatsuo Ishii [Sat, 29 Apr 2023 12:44:59 +0000 (21:44 +0900)]
Test: fix regress.sh to show correct number of total tests.
Previously it ignored the number of timed out tests. As a result total
number of tests showed incorrect number because num-total tests was
calculated as num-ok + num-failed.
This is an oversight when timeout was introduced in
6688332da.
Chen Ningwei [Tue, 25 Apr 2023 02:47:47 +0000 (11:47 +0900)]
Feature: Change default behavior of pcp commands for searching password file.
Previously pcp command does not searching for .pcppass/PCPPASSFILE if -w/--no-password option
is not given, which is inconsistent with psql.
Chen Ningwei [Tue, 25 Apr 2023 01:34:26 +0000 (10:34 +0900)]
Doc: add explanation for wd_priority.
Tatsuo Ishii [Wed, 19 Apr 2023 10:41:21 +0000 (19:41 +0900)]
Doc: add restriction regarding PREPARE/EXECUTE/DEALLOCATE.
Tatsuo Ishii [Wed, 19 Apr 2023 03:40:48 +0000 (12:40 +0900)]
Doc: add caution to use -D option with pgpool.
Tatsuo Ishii [Mon, 17 Apr 2023 08:39:27 +0000 (17:39 +0900)]
Use psqlscan only when query string is large.
This is a follow-up commit to
48da8715bf403965507eef0321c0ab10054ac71c.
Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2023-April/004320.html
Tatsuo Ishii [Sun, 16 Apr 2023 02:31:49 +0000 (11:31 +0900)]
Test: increase timeout in 077.invalid_failover_node test.
Increase timeout for pcp_promote_node from 2*30 = 60 sec to 3*30 = 90
sec. It seems the test fails just because too small timeout value.
Tatsuo Ishii [Sun, 16 Apr 2023 01:45:08 +0000 (10:45 +0900)]
More schema qualification added to system function.
Tatsuo Ishii [Sat, 15 Apr 2023 07:26:23 +0000 (16:26 +0900)]
Test: skip the test if there's no test.sh.
This is useful when developers want to run the test on git repository
because the check suppresses false positive errors. There could newer
branch's test directories remain without any contents and regress.sh
reports wrong failures.
Tatsuo Ishii [Sat, 15 Apr 2023 03:20:30 +0000 (12:20 +0900)]
Remove unused variable.
This is an oversight in commit:
https://git.postgresql.org/gitweb/?p=pgpool2.git;a=commit;h=
2ec15ef6656155fa2b88a4147a5767c8d844747b
Tatsuo Ishii [Sat, 15 Apr 2023 03:20:00 +0000 (12:20 +0900)]
Doc: fix typo in previous commit.
Tatsuo Ishii [Sat, 15 Apr 2023 02:59:43 +0000 (11:59 +0900)]
Add new config parameter "log_pcp_processes",
This allows to disable logging about normal PCP Process fork and exit
status. When pcp command is executed, pgpool logs its fork/exit event
even if there's no error. This could fill up the pgpool log.
Abnormal fork/exit event will be logged even if the parameter is
disabled.
Author: Maximilien Cuony
Review and Japanese document by: Tatsuo Ishii
Tatsuo Ishii [Fri, 14 Apr 2023 08:18:34 +0000 (17:18 +0900)]
Refactor pool_query_context.c.
Remove redundant code.
Bo Peng [Fri, 14 Apr 2023 04:00:59 +0000 (13:00 +0900)]
Doc: Enhancing installation documentation.
- add detailed decriptions of packages
- mention that pgpool-II-pgXX-extensions needs to be installed on PostgreSQL servers
Bo Peng [Thu, 13 Apr 2023 07:29:18 +0000 (16:29 +0900)]
Doc: remove the configuration of "- D" start OPTS from "8.2. Pgpool-II + Watchdog Setup Example".
Tatsuo Ishii [Thu, 13 Apr 2023 00:25:09 +0000 (09:25 +0900)]
Doc: add "Backing up PostgreSQL database" section to "Server Setup and Operation" chapter.
Tatsuo Ishii [Sun, 9 Apr 2023 04:11:12 +0000 (13:11 +0900)]
Doc: remove unnecessary restriction regarding multi-statement.
This applies to master branch only for now because this needs
commit:
https://git.postgresql.org/gitweb/?p=pgpool2.git;a=commit;h=
48da8715bf403965507eef0321c0ab10054ac71c
If we decide to back port this, we will apply this change to stable
branches.
Tatsuo Ishii [Sun, 9 Apr 2023 02:36:30 +0000 (11:36 +0900)]
Doc: fix restrictions section.
- Add mention about SCRAM-SHA-256 authentication
- Add mention about snapshot isolation mode
Tatsuo Ishii [Thu, 6 Apr 2023 03:43:06 +0000 (12:43 +0900)]
Fix occasional 005.jdbc test failure.
The direct cause of the error is:
2023-02-22 08:51:47.705: PostgreSQL JDBC Driver pid 12420: LOG: Parse: Error or notice message from backend: : DB node id: 0 backend pid: 12488 statement: "COMMIT" message: "prepared statement "S_1" already exists"
Actually the root of the error is this:
2023-02-22 08:51:45.242: PostgreSQL JDBC Driver pid 12420: LOG: pool_send_and_wait: Error or notice message from backend: : DB node id: 0 backend pid: 12488 statement: "DISCARD ALL" message: "DISCARD ALL cannot be executed within a pipeline"
"DISCARD ALL" was generated by pgpool (reset_query_list) to discard
some objects including prepared statements created in the
session. Since DISCARD ALL failed, the prepared statement S_1 was not
removed. Thus the next session failed because S_1 already existed.
To fix this, new global boolean flag reset_query_error is
introduced. The flag is set inside pool_send_and_wait() when a reset
query executed by SimpleQuery() results in ERROR. If the flag is true,
backend_cleanup() discards the backend connection so that any objects,
including named statement, corresponding to the session is discarded
For now I will push this to master branch only to see if the 005.jdbc
error gets fixed. If ok, I will back patch to all supported branched.
Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2023-February/004293.html
Tatsuo Ishii [Mon, 3 Apr 2023 23:21:28 +0000 (08:21 +0900)]
Doc: add index for online recovery.
Tatsuo Ishii [Mon, 3 Apr 2023 21:42:27 +0000 (06:42 +0900)]
Doc: add explanation when pg node status is shown as "unknown".
Tatsuo Ishii [Mon, 3 Apr 2023 12:17:36 +0000 (21:17 +0900)]
Doc: add explanation when pg node status is shown as "unknown".
Tatsuo Ishii [Thu, 30 Mar 2023 00:15:42 +0000 (09:15 +0900)]
More schema qualification fix.
This is a follow up to:
https://git.postgresql.org/gitweb/?p=pgpool2.git;a=commit;h=
49ca4800d1a804c1f6ef5807d9fbeeef85888fb6
Back patch to all supported branches: 4.4 to 4.0
Tatsuo Ishii [Wed, 29 Mar 2023 01:28:25 +0000 (10:28 +0900)]
Remove configure.
This is a follow up to commit:
https://git.postgresql.org/gitweb/?p=pgpool2.git;a=commit;h=
caeb3a8681d7aa0f5b24539de12d29dd5a8d9997
Also add configure and src/utils/psqlscan.c to .gitignore.
Bo Peng [Tue, 28 Mar 2023 13:48:40 +0000 (22:48 +0900)]
Change pgpool_setup to append some parameters to the end of the configuration file.
Tatsuo Ishii [Sat, 25 Mar 2023 07:21:27 +0000 (16:21 +0900)]
Judge multi statement query using psqlscan.
Psqlscan is a module in the PostgreSQL source tree. It is essentially
subset of PostgreSQL SQL scanner but it is specialized for detecting
the end of each SQL statement. Therefore we can count the number of
SQL statements in a query string by using it.
Because psqlscan is not designed as an external library, it is hard to
call it from outside of PostgreSQL source tree. So I decided to import
psqlscan source code. This module consists of multiple files. Program
sources are deployed in src/utils directory and header files are
deployed in src/include/utils directory.
psqlscan module was originally designed for frontend programs and uses
malloc directly. So I changed them so that it calls palloc and
friends. Additionally pgstrcasecmp.c and pqexpbuffer.c are also
imported. They are used by psqlscan.
The example usage of psqlscan can be found in
multi_statement_query():src/protocol/pool_proto_modules.c.
Discussion:
https://www.pgpool.net/pipermail/pgpool-hackers/2023-February/004291.html
Tatsuo Ishii [Tue, 28 Mar 2023 01:55:59 +0000 (10:55 +0900)]
Use schema qualification for internal queries.
Some of objects such as function and cast did not use "pg_catalog."
schema qualification. This does not lead to immediate security
concern but using the schema qualification is always good practice.
Not that for this I had to increase some buffer length:
- POOL_RELCACHE.query was changed from 1024 to 1500.
- query buffer size in pool_search_relcache was changed from 1024 to 1500.
Back patch to all supported branches: 4.4 to 4.0
Tatsuo Ishii [Tue, 28 Mar 2023 00:49:08 +0000 (09:49 +0900)]
Doc: fix typo in the description of backend_application_name.
Tatsuo Ishii [Wed, 22 Mar 2023 11:53:38 +0000 (20:53 +0900)]
Fix compile error on systems using musl libc.
Patch provided by leimaohui.
https://www.pgpool.net/mantisbt/view.php?id=790
Tatsuo Ishii [Wed, 22 Mar 2023 05:15:20 +0000 (14:15 +0900)]
Doc: mention that the target node to promote must be up and running.
Back patch to 4.3 in which the -n option of pcp_promote_node was
introduced.
Tatsuo Ishii [Fri, 10 Mar 2023 04:23:59 +0000 (13:23 +0900)]
Add notice_per_node_statement to "show pool_status".
This was missed in commit:
85ce852329c0e9775076234cd4a82c20fa173659
Tatsuo Ishii [Sat, 25 Feb 2023 01:31:55 +0000 (10:31 +0900)]
Test: simplify 001.load_balance test.
Previously we checked the version of psql, so that we could adapt the
change in psql: i.e. SHOW_ALL_RESULTS addition.
By doing:
\set SHOW_ALL_RESULTS off
in 7.sql, the test results are now identical PostgreSQL 15 and before.
As a result, expected*-pre15 files were removed.
Tatsuo Ishii [Thu, 23 Feb 2023 10:35:08 +0000 (19:35 +0900)]
Allow to run certain multi-statement queries.
Previously multi-statement queries including INSERT/UPDATE was not
recognized as a multi-statement because of optimization for lengthy
INSERT/UPDATE queries in streaming replication mode. This commit
temporarily turns off the optimization and adds regression test for
that.
Hopefully before releasing 4.5 we find a way to determine whether the
query is a multi-statement query or not in less expensive way. And if
it is not a multi-statement query, we can turn on the optimization.
Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2023-February/004291.html
Tatsuo Ishii [Wed, 22 Feb 2023 01:20:15 +0000 (10:20 +0900)]
Doc: mention that AES256 support requires --with-openssl option.
Tatsuo Ishii [Tue, 21 Feb 2023 08:25:20 +0000 (17:25 +0900)]
Doc: add index for "AES256".
Also fix previous commit for adding index ".pcppass" and "PCPPASSFILE".
Tatsuo Ishii [Tue, 21 Feb 2023 05:49:02 +0000 (14:49 +0900)]
Doc: explicitly stat that it is -w option of pcp command is needed to use .pcppass.
Also add .pcppass and PCPPASSFILE to index.
Backpatch-through: master and 4.4 to 4.0.
Tatsuo Ishii [Sat, 18 Feb 2023 07:34:14 +0000 (16:34 +0900)]
Fix that show pool_version shows row description twice.
test=# show pool_version;
pool_version
--------------
(0 rows)
pool_version
-----------------------
4.3.5 (tamahomeboshi)
(1 row)
Tatsuo Ishii [Fri, 17 Feb 2023 08:06:20 +0000 (17:06 +0900)]
Test: fix 001.loadbalance test failure.
Since this commit:
https://git.postgresql.org/gitweb/?p=pgpool2.git;a=commit;h=
f8c3d7b49a1c6496eca2203e95248b86c204bbfa
001.loadbalance test fails on pre PostgreSQL 15, because of the change
in psql. PostgreSQL 15's psql now prints the whole query results in a
multi-statement query. Consider following example:
SELECT \BEGIN\;SELECT 1;ROLLBACK;
In 15, the result of SELECT will be printed by psql, while pre-15 will
not. This causes some test results not to match with expected
results. To fix this, I added expected7-r-pre15 etc. for pre-15.
test.sh now recognizes "-pre15" suffix. If the server version is
pre-15 and an expected file with suffix "pre-15" exists, the file will
be used.
Tatsuo Ishii [Wed, 15 Feb 2023 11:13:03 +0000 (20:13 +0900)]
Doc: fix "2.8 Creating insert lock table" section.
It only refereed to the native replication where it should have refereed
to the snapshot isolation mode. Also enhance some xreflabels for
clustering mode.
Tatsuo Ishii [Sun, 12 Feb 2023 11:08:08 +0000 (20:08 +0900)]
Test: enhance regression 001.load_balance.
Tatsuo Ishii [Sun, 12 Feb 2023 10:59:00 +0000 (19:59 +0900)]
Allow to use multiple statements extensively.
This commit tries to eliminate pgpool's long standing limitations
regarding multiple statements (multi-statements).
Previously
BEGIN;SELECT;
SAVEPOINT foo;
will fail in streaming replication mode because "BEGIN" was sent to
the primar node, but "SAVEPOINT" will be sent to both the primary and
standbys, and standbys will complain "SAVEPOINT can only be used in
transaction blocks".
Basic idea to solve the problem is, tracking explicit transactions
started by multi-statement queries so that all commands including
PREPARE, EXECUTE, DEALLOCATE, SAVEPOINT and COMMIT/ROLLBACK are sent
to the primary node in streaming replication mode or logical
replication mode. In native replication or snapshot isolation mode,
those queries are sent to all of the backend nodes.
For this purpose new member: is_tx_started_by_multi_statement is added
to session context and also support functions are added.
extern bool is_tx_started_by_multi_statement_query(void);
extern void set_tx_started_by_multi_statement_query(void);
extern void unset_tx_started_by_multi_statement_query(void);
Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2023-February/004287.html
Back-patch-through: 4.2 as backport to 4.1 and before looks difficult
Tatsuo Ishii [Tue, 7 Feb 2023 10:39:37 +0000 (19:39 +0900)]
Test: simplify 001.load_balance.
Commit
85ce8523 allows to use expected/result style tests. This
commit applies it to 001.load_balance. The expected files are under
"expected" directory. Suffix "-s" is for streaming replication mode
and "-r" is for native replication and snapshot isolation mode.
Tatsuo Ishii [Tue, 7 Feb 2023 08:25:17 +0000 (17:25 +0900)]
Add notice_per_node_statement.
The new GUC variable allows to emit NOTICE message of queries per
backend basis. It's similar to log_per_node_statement but as the log
level is NOTICE, the log is printed on client's terminal, thus users
can know where their queries go to without looking into pgpool log
files.
Also this is useful to create expected/results style test cases.
Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2023-February/004276.html
Tatsuo Ishii [Sun, 5 Feb 2023 09:56:05 +0000 (18:56 +0900)]
Fix multiple query cache bug.
1) pool_add_item_shmem_cache() calls pool_init_cache_block() when
there's no free cache item hash table entry. But this is
unnecessary since pool_reuse_block() is already called from
pool_add_item_shmem_cache(). This is actually harmless because the
second pool_init_cache_block() call just set the same data as the
first call of pool_init_cache_block(). It's just a waste of CPU
cycle.
2) The cache blocks are supposed to be initialized while Pgpool-II
starts up but actually not. Each cache block has the free space
length in the block header after initialization. Since the free
space length is not set, pool_get_block() fails to find a cache
block which has enough free space, and it calls pool_reuse_block(),
which is actually unnecessary (you will see something like
"pool_reuse_block: blockid: 0" in pgpool log). Since
pool_reuse_block() returns a free block anyway, this is just a
waste of CPU cycle but better to fix.
Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2023-January/004259.html
Backpatch-through: 4.0
Tatsuo Ishii [Sun, 5 Feb 2023 07:13:15 +0000 (16:13 +0900)]
Fix sr worker to not send wrong query to standby server in corner case.
When ALWAYS_PRIMARY flag is set, PRIMARY_NODE_ID macro returns node
id, rather than -1 even if the primary is down. This confuses the test
if a node is primary or not, because PRIMARY_NODE_ID macro returns
main node id. In this case streaming replication delay check worker
sends "SELECT pg_current_wal_lsn()" or "SELECT
pg_current_xlog_location()" depending on PostgreSQL's version to
standby which of course raises an error.
To fix this, test the primary node is down or not, and if it's down,
skip the replication delay loop. If primary is down, there's no point
to perform streaming replication delay checking anyway.
Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2023-February/004279.html
Backpatch-through: 4.0
Tatsuo Ishii [Thu, 2 Feb 2023 10:34:00 +0000 (19:34 +0900)]
Fix comment mistakes.
Tatsuo Ishii [Thu, 2 Feb 2023 05:29:33 +0000 (14:29 +0900)]
Fix comment mistakes.
Tatsuo Ishii [Wed, 1 Feb 2023 13:39:41 +0000 (22:39 +0900)]
Doc: enhance show pool_cache manual.
Add a table to explain each items shown by show pool_cache.
Tatsuo Ishii [Tue, 31 Jan 2023 11:36:29 +0000 (20:36 +0900)]
Remove unnecessary macro.
The macro "DUAL_MODE" is no longer used anywhere.
Moreover, if it is used, it causes a compile error.
Tatsuo Ishii [Tue, 31 Jan 2023 09:49:48 +0000 (18:49 +0900)]
Fix kind mimatch error with DEALLOCATE
When conditions below are all met:
- streaming replication mode
- load balance node is other than primary
- PREPARE is used in a multi-statement query
Kind mimatch error occurs.
For DEALLOCATE pool_where_to_send() sets the nodes to be sent to all
backend if pgpool failed to find a prepared statement previously
received. For example with "SELECT 1\;PREPARE foo;", pgpool ignores
"PREPARE" part and just sends the whole multi-statement query to
primary. So primary actually has the prepared statement "foo" but
pgpool thinks that there's no prepared statement named "foo". And
pgpool sends DEALLOCATE to both primary and standby, then a kind
mismatch error raised. Fix is, just sending DEALLOCATE to primary node
in this case if pgpool is in streaming replication mode. Same thing
can be said to EXECUTE too. I fixed this and merge similar treatment
with EXECUTE into where_to_send_deallocate() to make the code simpler.
I also found another bug: in replication mode or SI mode, pgpool needs
to send multi-statement query to all backend because the
multi-statement query maybe a write query. However pgpool sends to
main node only in this case.
Test cases are added to 071..execute_and_deallocate.
Backpatch-through: 4.0
Problem reported in:
https://www.pgpool.net/mantisbt/view.php?id=780
Tatsuo Ishii [Mon, 30 Jan 2023 02:02:22 +0000 (11:02 +0900)]
Obtain stronger lock while commiting shared relcache.
Previously pool_search_relcache() obtained only shared lock, which is
not safe enough to call pool_catalog_commit_cache() because it
registers new cache entry. Unfortunately our locking system does not
allow to escalate a shared lock to an exclusive lock. So we release
the shared lock then acquire the exclusive lock before calling
pool_catalog_commit_cache(). There's a window between them and we may
end up with an effort to register duplicate cache entry. But
underlying infrastructure of the query system will reject it and
should be safe.
Back-patch through 4.4 where the shared locking of the query cache
system was introduced.
Tatsuo Ishii [Sat, 28 Jan 2023 03:17:23 +0000 (12:17 +0900)]
Test: refactor 071.execute_and_deallocate/test.sh.
Previously the test was performed on only streaming replication mode.
Now the test covers native replication mode, snapshot isolation mode
and raw mode. Note that since case 6 test tries to test load balancing
on node 1, the case is not applied to raw mode.
Tatsuo Ishii [Sat, 28 Jan 2023 02:37:18 +0000 (11:37 +0900)]
Test: fix indentation for further refactoring.
Tatsuo Ishii [Wed, 25 Jan 2023 05:45:34 +0000 (14:45 +0900)]
Doc: fix typo in the description of read_only_function_list.