pgpool2.git
3 years agoRetire pool_string module.
Tatsuo Ishii [Fri, 26 Aug 2022 05:23:59 +0000 (14:23 +0900)]
Retire pool_string module.

Currently there are two string manipulation modules: pool_string and
StringInfo. StringInfo is more feature rich and PostgreSQL compatible
because it was imported from PostgreSQL. So replace all usages of
pool_string by StringInfo. This also solves a problem reported by
Peng: i.e. struct name "String" collision: pool_string uses "String"
and PostgreSQL 15's parser also uses "String".

3 years agoDoc: fix typo.
Bo Peng [Thu, 18 Aug 2022 05:18:20 +0000 (14:18 +0900)]
Doc: fix typo.

3 years agoDoc: add release notes.
Bo Peng [Tue, 16 Aug 2022 05:45:17 +0000 (14:45 +0900)]
Doc: add release notes.

3 years agoFix possible memory overrun in allocation of fds.
Masaya Kawamoto [Thu, 4 Aug 2022 08:17:08 +0000 (08:17 +0000)]
Fix possible memory overrun in allocation of fds.

3 years agoFix memory leak pointed out by Coverity
Masaya Kawamoto [Thu, 4 Aug 2022 00:39:56 +0000 (00:39 +0000)]
Fix memory leak pointed out by Coverity

3 years agoDoc: enhance description in the memory requirement section.
Tatsuo Ishii [Tue, 26 Jul 2022 06:23:40 +0000 (15:23 +0900)]
Doc: enhance description in the memory requirement section.

Add explanation about memory usage while pgpool child process is running.

3 years agoDoc: fix typo.
Tatsuo Ishii [Tue, 26 Jul 2022 02:31:44 +0000 (11:31 +0900)]
Doc: fix typo.

3 years agoRename regression test 035.
Masaya Kawamoto [Fri, 22 Jul 2022 06:18:24 +0000 (06:18 +0000)]
Rename regression test 035.

3 years agoSupport for unix_socket_directories and related parameters
Masaya Kawamoto [Wed, 20 Jul 2022 07:13:27 +0000 (07:13 +0000)]
Support for unix_socket_directories and related parameters

Support for unix_socket_directories, unix_socket_group and
unix_socket_permissions.

3 years agoDoc: mention that certain SELECTs are not cached.
Tatsuo Ishii [Tue, 19 Jul 2022 13:14:41 +0000 (22:14 +0900)]
Doc: mention that certain SELECTs are not cached.

SELECTs including TIMESTAMP WITH TIMEZONE or TIME WITH TIMEZONE
SELECTs including CAST to TIMESTAMP WITH TIMEZONE or TIME WITH TIMEZONE
SELECTs including SQLValueFunction (CURRENT_TIME, CURRENT_USER etc.)

3 years agoTest: print Pgpool-II version in the regression test.
Tatsuo Ishii [Sun, 10 Jul 2022 07:04:49 +0000 (16:04 +0900)]
Test: print Pgpool-II version in the regression test.

3 years agoFix pgpool_recovery extension script.
Tatsuo Ishii [Sun, 10 Jul 2022 01:28:06 +0000 (10:28 +0900)]
Fix pgpool_recovery extension script.

It lack 6-argument form of pgpool_recovery (used by v4.2). As a
result, if 4.3 extension is already installed, pgpool_setup fails
because it wants 6-argument form of pgpool_recovery.

3 years agoTest: Fix regression test script to look for pgpool.conf in the proper install directory.
Tatsuo Ishii [Sat, 9 Jul 2022 09:41:18 +0000 (18:41 +0900)]
Test: Fix regression test script to look for pgpool.conf in the proper install directory.

regress.sh did set PGPOOLDIR environment variable despite that
pgpool_setup look for pgpool.conf sample files at $PGPOOLDIR/etc. As a
result, pgpool_setup looked for pgpool.conf.sample at default install
directory (usually /usr/local/etc) even if "-m noinstall" is not
set. If inappropriate pgpool.conf sample files are in
/usr/local/etc., regression test fails.

3 years agoFix to not cache SELECT having functions with return types are timestamptz or timetz.
Tatsuo Ishii [Wed, 6 Jul 2022 12:31:08 +0000 (21:31 +0900)]
Fix to not cache SELECT having functions with return types are timestamptz or timetz.

Functions with return type is timestamptz or timetz is affected by time zone setting.
Consider following scenario:

1) SELECT having such functions gets called and cache created.

2) time zone is changed.

3) same SELECT is called and the cache is used. The cache value is
correct any more because of the time zone change.

Discussion: https://www.pgpool.net/pipermail/pgpool-general/2022-July/008367.html

3 years agoFix query cache to not cache timestamptz and timetz cast.
Tatsuo Ishii [Tue, 5 Jul 2022 05:06:10 +0000 (14:06 +0900)]
Fix query cache to not cache timestamptz and timetz cast.

Even if query is constant + cast (like '2022-07-05
14:07:00'::timestamptz), the result can be changed by SET TIME ZONE
command etc. and the result should not be cached.
Also regression test data added.

Discussion: https://www.pgpool.net/pipermail/pgpool-general/2022-July/008353.html

3 years agoFix bug in query cache.
Tatsuo Ishii [Mon, 4 Jul 2022 05:23:48 +0000 (14:23 +0900)]
Fix bug in query cache.

[pgpool-general: 8285] Timestamp cast not cached

reported that query like "Select '2022-02-18
07:00:00.006547’::timestamp" is not cached.

The function non_immutable_function_call_walker() which judges whether
the query contains non immutable functions mistakenly assumes that any
query including cast to timestamp etc. should not to be cached. These
codes were originally added to detect CURRENT_TIMESTAMP etc. as they
are transformed to type cast in raw parser. Unfortunately this is
overkill since "'2022-02-18 07:00:00.006547’::timestamp" is also
transformed to a type cast.

Fortunately Pgpool-II 3.7 and after imported PostgreSQL 10 or newer
parser, which transforms CURRENT_TIMESTAMP etc. to SQLValueFunction.

As a result, the type cast handling code in
non_immutable_function_call_walker() is not necessary anymore. So this
commit removed the code.

Note: an interested thing in the report is, "Select '2022-02-18
07:00:00.006547’::timestamp" is not cached while "Select '2022-02-18
07:00:00.006547’::date" is cached. Why? Well
non_immutable_function_call_walker() (wrongly) assumes that the type
cache is always created by SystemTypeName (a parser's function), which
always adds pg_catalog schema. This only happens when the type name is
a reserved keyword. TIMESTAMP is a reserved keyword (and TIME too). So
non_immutable_function_call_walker() catches TIMESTAMP cast as
expected, but DATE is not a reserved keyword and it is transformed to
type name without "pg_catalog" schema. So
non_immutable_function_call_walker() misses it, and it is cached.

3 years agoAdd ssh options to restore_command in sample scripts.
Bo Peng [Fri, 1 Jul 2022 05:41:00 +0000 (14:41 +0900)]
Add ssh options to restore_command in sample scripts.

Patch is created by Jon SCHEWE and updated by Bo Peng.

3 years agoDoc: fix description about using PCP password file when connect to Unix domain socket
Masaya Kawamoto [Thu, 30 Jun 2022 03:58:37 +0000 (03:58 +0000)]
Doc: fix description about using PCP password file when connect to Unix domain socket

The localhost entry in pcppass matches only for the default PCP socket
directory path, not all Unix socket connections. This behavior is the
same as pgpass.

3 years agoAllow to run pgpool_setup on PostgreSQL 15.
Tatsuo Ishii [Thu, 23 Jun 2022 01:01:35 +0000 (10:01 +0900)]
Allow to run pgpool_setup on PostgreSQL 15.

basebackup.sh created by pgpool_setup uses pg_start_backup() and
pg_stop_backup().  PostgreSQL 15 renamed them. But there's more
problem. The renamed functions (pg_backup_start() and
pg_backup_stop()) must be called within a same connection. Adapting
these requires non-trivial changes. So I decided to rewrite the code
to not use pg_start_backup() and pg_stop_backup() so that it uses
pg_basebackup command instead.

Per https://www.pgpool.net/mantisbt/view.php?id=757

3 years agoEnable debug1 while executing 074.bug700_memqcache_segfault.
Tatsuo Ishii [Sat, 21 May 2022 09:09:00 +0000 (18:09 +0900)]
Enable debug1 while executing 074.bug700_memqcache_segfault.

This is necessary to pursuit occasional timeout in the test.  Also add
debug logging to pool_push_pending_data() for the same purpose.
ereport for debugging to

3 years agoAllow pgpool_setup to test sample scripts and sample config files contained in RPMs.
Bo Peng [Mon, 13 Jun 2022 14:04:57 +0000 (23:04 +0900)]
Allow pgpool_setup to test sample scripts and sample config files contained in RPMs.

Currently, pgpool_setup generates scripts (e.g. failover.sh, follow_primary.sh) to test pgpool.

This commit addes a new option "-c" in src/test/regression/regress.sh
and a new environment variables TEST_SAMPLES in pgpool_setup.
Option "-c" enables TEST_SAMPLES and allows pgpool_setup to test sample scripts and
sample config files contained in RPMs.

This commit also changes "backend_hostnameX = '/tmp'" to "backend_hostnameX = 'localhost'".

3 years agoRename configuration parameter delegate_IP to delegate_ip.
Bo Peng [Mon, 13 Jun 2022 11:48:46 +0000 (20:48 +0900)]
Rename configuration parameter delegate_IP to delegate_ip.

For compatibility with the old versions, the old paramter delegate_IP can still work.
If the old paramter delegate_IP is used, Pgpool-II will set the value to
delegate_ip and throw a warning message.

This commit also fixes segfault of fail_over_on_backend_error
and changes the behavior to set the value to failover_on_backend_error
if fail_over_on_backend_error is used.

3 years agoAdd pool_config.c to src/tools/pgmd5/.gitignore.
Tatsuo Ishii [Mon, 13 Jun 2022 07:09:46 +0000 (16:09 +0900)]
Add pool_config.c to src/tools/pgmd5/.gitignore.

This should avoid the error:
error: The following untracked working tree files would be overwritten by checkout:
src/tools/pgmd5/pool_config.c

3 years agoAdd debug logs to print each initial shared memory allocation.
Tatsuo Ishii [Mon, 6 Jun 2022 13:14:04 +0000 (22:14 +0900)]
Add debug logs to print each initial shared memory allocation.

3 years agoDoc: fix memory requirement section.
Tatsuo Ishii [Mon, 6 Jun 2022 13:06:37 +0000 (22:06 +0900)]
Doc: fix memory requirement section.

- enhance the formula to calculate shared memory requirement so that it computes more accurate result.

- fix shared memory requirement for shared rel cache. The old value 64MB was simply wrong.

- fix process memory requirement. Previously the formula was based on
  RSS. However PSS should be used because RSS includes shared memory
  such as the memory used for libraries. This resuls in lot smaller
  memory requirement than before.

3 years agoRemove spaces in sample scripts.
Bo Peng [Sun, 5 Jun 2022 16:26:15 +0000 (01:26 +0900)]
Remove spaces in sample scripts.

3 years agoAllow to rewrite archive_command in sample scripts.
Bo Peng [Sun, 5 Jun 2022 13:45:21 +0000 (22:45 +0900)]
Allow to rewrite archive_command in sample scripts.

3 years agoUpdate PSQL connection information in sample scripts.
Bo Peng [Sun, 5 Jun 2022 06:54:12 +0000 (15:54 +0900)]
Update PSQL connection information in sample scripts.

3 years agoRevert "Enable debug1 while executing 074.bug700_memqcache_segfault."
Tatsuo Ishii [Sat, 4 Jun 2022 04:23:22 +0000 (13:23 +0900)]
Revert "Enable debug1 while executing 074.bug700_memqcache_segfault."

This reverts commit ce669517c946f36e1663891408ce67b90e0bf605.

Now that the problem was fixed by the commit:

https://git.postgresql.org/gitweb/?p=pgpool2.git;a=commit;h=4725950d19ca81d78e3a3994f665fe9a095ddb4c

those debug aid is not necessary anymore.

3 years agoFix segfault in end_internal_transaction().
Tatsuo Ishii [Thu, 2 Jun 2022 07:55:10 +0000 (16:55 +0900)]
Fix segfault in end_internal_transaction().

This was introduced by the commit:
https://git.postgresql.org/gitweb/?p=pgpool2.git;a=commit;h=050be475d738ab4f8268dce21e2e5361b7dbcbee

In raw mode, end_internal_transaction() should not be called.

3 years agoDoc: fix wrong explanation on memqcache_maxcache, memqcache_expire.
Tatsuo Ishii [Thu, 2 Jun 2022 01:03:12 +0000 (10:03 +0900)]
Doc: fix wrong explanation on memqcache_maxcache, memqcache_expire.

Those parameters cannot be changed by reloading config file. Restarting
pgpool is required.

Discussion: https://www.pgpool.net/pipermail/pgpool-general/2022-June/008254.html

3 years agoWhen CloseComplete is received, foward to frontend without buffering.
Tatsuo Ishii [Tue, 31 May 2022 12:23:48 +0000 (21:23 +0900)]
When CloseComplete is received, foward to frontend without buffering.

It seems occasional timeour error in 074.bug700_memqcache_segfault seems to be caused by the buildfarm log as of
[pgpool-buildfarm: 2158] Pgpool-II buildfarm results CentOS7
* master  PostgreSQL 12  CentOS7
testing 074.bug700_memqcache_segfault...timeout.

From the pgpool.log:
2022-05-28 17:14:52.612: pgproto pid 45886: DEBUG:  pool_discard_temp_query_cache: cache discarded: 0x1be53e8
2022-05-28 17:14:52.612: pgproto pid 45886: DEBUG:  memcache reset buffer
2022-05-28 17:14:52.612: pgproto pid 45886: DETAIL:  discard: 0x1be57a8
2022-05-28 17:14:52.612: pgproto pid 45886: DEBUG:  memcache discarding query cache array
2022-05-28 17:14:52.612: pgproto pid 45886: DETAIL:  num_caches: 0
2022-05-28 17:14:52.612: pgproto pid 45886: DEBUG:  memcache reset buffer
2022-05-28 17:14:52.612: pgproto pid 45886: DETAIL:  create: 0x1be57a8
2022-05-28 17:14:52.612: pgproto pid 45886: DEBUG:  memcache reset buffer
2022-05-28 17:14:52.612: pgproto pid 45886: DETAIL:  discard temp buffer of 0x1be7c08 (SELECT 1)
2022-05-28 17:14:52.612: pgproto pid 45886: DEBUG:  CloseComplete: remove sent message. kind:B, name:P1
2022-05-28 17:14:52.612: pgproto pid 45886: DEBUG:  processing command complete
2022-05-28 17:14:52.612: pgproto pid 45886: DETAIL:  set transaction state to T
2022-05-28 17:14:52.612: pgproto pid 45886: DEBUG:  memcache reset buffer
2022-05-28 17:14:52.612: pgproto pid 45886: DETAIL:  discard: 0x1be57a8
2022-05-28 17:14:52.612: pgproto pid 45886: DEBUG:  memcache discarding query cache array
2022-05-28 17:14:52.612: pgproto pid 45886: DETAIL:  num_caches: 0
2022-05-28 17:14:52.612: pgproto pid 45886: DEBUG:  memcache reset buffer
2022-05-28 17:14:52.612: pgproto pid 45886: DETAIL:  create: 0x1be57a8
2022-05-28 17:14:52.612: pgproto pid 45886: DEBUG:  memcache reset buffer
2022-05-28 17:14:52.612: pgproto pid 45886: DETAIL:  discard temp buffer of 0x1be7c08 (SELECT 1)
2022-05-28 17:14:52.612: pgproto pid 45886: DEBUG:  CloseComplete: remove sent message. kind:B, name:P2

It seems the CloseComplete message was received from backend but if looking into results.txt:

FE=> Query (query="SET statement_timeout TO 1000")
<= BE CommandComplete(SET)
<= BE ReadyForQuery(I)
FE=> Parse(stmt="S1", query="SELECT 1")
FE=> Bind(stmt="S1", portal="P1")
FE=> Execute(portal="P1")
FE=> Close(portal="P1")
FE=> Bind(stmt="S1", portal="P2")
FE=> Execute(portal="P2")
FE=> Close(portal="P2")
FE=> Sync
<= BE ParseComplete
<= BE BindComplete
<= BE DataRow
<= BE CommandComplete(SELECT 1)
<= BE CloseComplete
<= BE BindComplete
<= BE DataRow
<= BE CommandComplete(SELECT 1)

It seems the frontend did not receive the CloseComplete
message. SimpleForwardToFrontend() did buffering when it forwarded the
CloseComplete message. I guess this is the cause of the timeout. So
let's change SimpleForwardToFrontend() so that it forwards
CloseComplete message without buffering and see what buildfarm says.

3 years agoSkipping useless ereport/elog calls.
Muhammad Usama [Tue, 31 May 2022 11:19:31 +0000 (16:19 +0500)]
Skipping useless ereport/elog calls.

Although ereport() and elog() themselves are quite cheap when the error message
level is too low to be printed, some places need to do substantial work before
they can call those macros at all. message_level_is_interesting() can be handy
to allow optimizing away such setup work when nothing is to be printed.

Function message_level_is_interesting(elevel) is borrowed from PostgreSQL
source that reports whether ereport/elog will do anything.

3 years agoFix internal transaction handling bug in snapshot isolation mode.
Tatsuo Ishii [Tue, 31 May 2022 10:46:16 +0000 (19:46 +0900)]
Fix internal transaction handling bug in snapshot isolation mode.

When SELECT is executed in snapshot isolation mode, it is surrounded
in an "internal transaction".  For example if there are 3 backends,
each backend starts an internal transaction with "BEGIN" command.
However, there was an oversight in end_internal_transaction(), which
is responsible for closing the transaction. It only closed the
transaction on "load balance node". This causes a problem with certain
query following SELECT, for example VACUUM. Suppose the SELECT is
executed on backend node 2, then transaction on node 0 and node 1 were
not closed. If VACUUM is executed on node 0, it fails because the
transaction is not closed on node 0 (remember, VACUUM cannot be
executed in an explicit transaction).

Also add a test case for this to the 030.snapshot_isolation test.

3 years agoUpdated the sample scripts to allow ssh login user and ssh key file to be set using...
Bo Peng [Mon, 30 May 2022 16:10:06 +0000 (01:10 +0900)]
Updated the sample scripts to allow ssh login user and ssh key file to be set using variables.

3 years agoFix accepting INET fd bug.
Tatsuo Ishii [Wed, 25 May 2022 01:07:19 +0000 (10:07 +0900)]
Fix accepting INET fd bug.

This was introduced in commit: 9f727c1e267f1363012a3af599b7d7515e4ec355.

While pgpool_main initializes itself, first accepting UNIX/INET domain
sockets are set in "fds" array.  Then forks child process.  So far so
good. Later on pgpool_main initializes pcp sockets. But at this point
it accidentally initialized "fds" array again. As a result, if child
process is forked again, wrong fds were used by those child
process. Immediate result is, frontend could not connect to pgpool by
INET domain listen addresses (-h localhost).

Problem found by Bo peng.

3 years agoEnable debug1 while executing 074.bug700_memqcache_segfault.
Tatsuo Ishii [Sat, 21 May 2022 09:09:00 +0000 (18:09 +0900)]
Enable debug1 while executing 074.bug700_memqcache_segfault.

This is necessary to pursuit occasional timeout in the test.  Also add
debug logging to pool_push_pending_data() for the same purpose.
ereport for debugging to

3 years agoAdd volatile modifier to a variable used in the query cache module.
Tatsuo Ishii [Fri, 20 May 2022 04:55:20 +0000 (13:55 +0900)]
Add volatile modifier to a variable used in the query cache module.

"sts" variable used in pool_fetch_memory_cache() did not have volatile
modifier although it is used in PG_TRY() block. If an exception arises
the value set to variable will be lost in the PG_CATCH block. The bad
effect of this will not be triggered unless error occurs and I think
the bad effect has rarely been observed in the wild (as for as I know,
I have never heard such a report). Anyway, bug is bug.

3 years agoDoc: add release notes.
Bo Peng [Wed, 18 May 2022 02:13:54 +0000 (11:13 +0900)]
Doc: add release notes.

3 years agoDoc: move the example of "Pgpool-II on Kubernetes" to https://github.com/pgpool/pgpoo...
Bo Peng [Wed, 18 May 2022 00:14:28 +0000 (09:14 +0900)]
Doc: move the example of "Pgpool-II on Kubernetes" to https://github.com/pgpool/pgpool2_on_k8s/tree/master/docs.

3 years agoEnhance in stopping pgpool main process.
Tatsuo Ishii [Sat, 14 May 2022 00:44:21 +0000 (09:44 +0900)]
Enhance in stopping pgpool main process.

If "pgpool stop" couldn't terminate the main process within certain
period (currently 5 seconds), send the signal again. The reason why
pgpool does not accept the stopping signal is not clear at the moment,
I expect this reduces errors of buildfarm timeout. See if this works.

3 years agoFix comment.
Tatsuo Ishii [Tue, 10 May 2022 05:20:26 +0000 (14:20 +0900)]
Fix comment.

3 years agoFix not to abort session while in failed transaction.
Tatsuo Ishii [Sun, 8 May 2022 09:00:20 +0000 (18:00 +0900)]
Fix not to abort session while in failed transaction.

When an explicit transaction fails, subsequent commands should be
ignored until commit or rollback command comes in. However pgpool
sometimes aborted the session if relcache lookup happened. example:

test=# begin;
BEGIN
test=*# insert into ttt values(1);
ERROR:  relation "ttt" does not exist
LINE 1: insert into ttt values(1);
                    ^
test=!# select * from t1;
FATAL:  Backend throw an error message
DETAIL:  Exiting current session because of an error from backend
HINT:  BACKEND Error: "current transaction is aborted, commands ignored until end of transaction block"
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Succeeded.

To prevent  this, check the transaction  state and if it's  already in
aborted state, do not try to  process the command, but just reply back
to frontend with an error message:

ERROR:  current transaction is aborted, commands ignored until end of transaction block

By the way, while implementing the fix, I found old bugs with replication mode.

- ReadyForQuery() mistakenly called end_internal_transaction() even if
  it's not in replication/si mode. Moreover,
  end_internal_transaction() is called even if the internal
  transaction has not started.

- end_internal_transaction() did not call pool_unset_failed_transaction();

These bugs were harmless until I tried to fix the issue (session
aborting).

New regression test 078 for this added.

Discussion: https://www.pgpool.net/pipermail/pgpool-general/2022-April/008155.html

3 years agoDoc: update configuration example.
Masaya Kawamoto [Mon, 9 May 2022 04:54:16 +0000 (04:54 +0000)]
Doc: update configuration example.

3 years agoChange the PID length of pcp_proc_count command to 7 characters long.
Bo Peng [Mon, 2 May 2022 05:15:32 +0000 (14:15 +0900)]
Change the PID length of pcp_proc_count command to 7 characters long.

3 years agoDoc: update the example output of pcp_watchdog_info.
Bo Peng [Thu, 28 Apr 2022 09:05:54 +0000 (18:05 +0900)]
Doc: update the example output of pcp_watchdog_info.

3 years agoDoc: update the example output of pcp_watchdog_info.
Bo Peng [Thu, 28 Apr 2022 08:34:39 +0000 (17:34 +0900)]
Doc: update the example output of pcp_watchdog_info.

3 years agoDoc: mention that escaping is required if you are providing the password as an argume...
Bo Peng [Thu, 28 Apr 2022 04:22:52 +0000 (13:22 +0900)]
Doc: mention that escaping is required if you are providing the password as an argument to pg_enc and the password contains a "$" character.

3 years agoFix for [pgpool-general: 7896] Possible race condition..
Muhammad Usama [Wed, 27 Apr 2022 10:30:58 +0000 (15:30 +0500)]
Fix for [pgpool-general: 7896] Possible race condition..

Watchdog does not allow the remote nodes reported lost by life-check to rejoin
the cluster until the life-check process confirms the existence of life in the
previously lost nodes. This is good enough except for the case when the
(lost by life-check) node tries to rejoin the cluster after it was restarted
(Pgpool-II service restarted).
What happens is the cluster keeps rejecting the restarted node because
the cluster's life-check doesn't agree while the restarted node's life-check
waits to be added to cluster before it can start sending the heart-beats.

The fix is to allow the previously lost remote node become the part of the
cluster after restart, no matter the lost-reason.

Issue report:
https://www.pgpool.net/pipermail/pgpool-general/2021-November/007954.html

3 years agoRevert "Attempt to fix buildfarm timeout error."
Tatsuo Ishii [Mon, 25 Apr 2022 07:54:13 +0000 (16:54 +0900)]
Revert "Attempt to fix buildfarm timeout error."

This reverts commit 480c0ce0b76828428fd4823160012bb44d5eb53f.

It seems the fix is useless and causes problem with failover.

3 years agoAttempt to fix buildfarm timeout error.
Tatsuo Ishii [Thu, 21 Apr 2022 06:24:26 +0000 (15:24 +0900)]
Attempt to fix buildfarm timeout error.

After inspecting the buildfarm log, I noticed it seems as if terminate
signal was ignored.  My theory is system(3), which is used in
trigger_failover() ignores SIGINT and SIGQUIT.  To deal with this,
check the return value of system(3) to determine whether signal was
sent while executing system(3). If so, call exit_handler after
failover.

3 years agoAdd more logging to exit_handler in pgpool main process.
Tatsuo Ishii [Thu, 21 Apr 2022 05:27:27 +0000 (14:27 +0900)]
Add more logging to exit_handler in pgpool main process.

3 years agoImprove regression test to detect segmentation fault.
Bo Peng [Mon, 18 Apr 2022 15:36:54 +0000 (00:36 +0900)]
Improve regression test to detect segmentation fault.

3 years agoTest: stabilize 018.detach_primary.
Tatsuo Ishii [Sun, 17 Apr 2022 12:48:51 +0000 (21:48 +0900)]
Test: stabilize 018.detach_primary.

The test occasionally failed with timeout. The cause seems the test
proceeds before watchdog are ready.  So wait till watchdog is ready
using pcp_watchdog_info.

3 years agoTest: enhance 074.bug700_memqcache_segfault
Tatsuo Ishii [Sun, 17 Apr 2022 04:52:14 +0000 (13:52 +0900)]
Test: enhance 074.bug700_memqcache_segfault

Set statement_timeout at the beginning of the test to avoid the time
out error because it takes long time before failure.

3 years agoFix exit_handler in pgpool main process.
Tatsuo Ishii [Thu, 14 Apr 2022 11:01:56 +0000 (20:01 +0900)]
Fix exit_handler in pgpool main process.

It was allowed to be interrupted by signals (SIGTERM, SIGINT and
SOGQUIT) while the exit_handler. As a resit, exit_handler is executed
while executing exit_handler. This could cause infinite wait in
terminate_childrens() which is called from exit_handler.  To prevent
this, protect variable "exiting" using semaphore to make sure that
only one instance of exit_handler runs at the same time.

Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2022-April/004149.html

3 years agoFix memory leak pointed out by Coverity.
Masaya Kawamoto [Mon, 11 Apr 2022 07:20:58 +0000 (07:20 +0000)]
Fix memory leak pointed out by Coverity.

3 years agoFix pgpool child process to obtain process information.
Tatsuo Ishii [Sat, 9 Apr 2022 06:54:45 +0000 (15:54 +0900)]
Fix pgpool child process to obtain process information.

ProcesInfo was obtained by using pool_get_process_info(). But this API
is not suitable for child process because:

- does inefficient linear search over all ProcessInfo slots (there are
  num_init_children slots).

- due to race condition the search key pid might not be set or removed
  in the slot. I think it is possible that by the time when child
  process starts execution, the pid is not yet set in the slot in the
  shared memory. Also when child process is killed by parent process,
  it may set pid to 0 before the child process receive kill signal.

So use pool_get_my_process_info() instead of pool_get_process_info().
which just returns the slot by using global variable my_proc_id as a
key and let child process use it.  my_proc_id was set by the parent
process when the child process was spawn.

The call to pool_get_process_info() in child.c was added in v4.3. So
back patch to V4_3_STABLE.

3 years agoRevert "Fix pgpool child process to obtain process information."
Tatsuo Ishii [Sat, 9 Apr 2022 06:05:26 +0000 (15:05 +0900)]
Revert "Fix pgpool child process to obtain process information."

This reverts commit 06f69d19030deb1d72230ce489c5a4d800ad593c.

3 years agoFix pgpool child process to obtain process information.
Tatsuo Ishii [Sat, 9 Apr 2022 00:08:34 +0000 (09:08 +0900)]
Fix pgpool child process to obtain process information.

ProcesInfo was obtained by using pool_get_process_info(). But this API
is not suitable for child process because:

- does inefficient linear search over all ProcessInfo slots (there are
  num_init_children slots).

- due to race condition the search key pid might not be set or removed
  in the slot. I think it is possible that by the time when child
  process starts execution, the pid is not yet set in the slot in the
  shared memory. Also when child process is killed by parent process,
  it may set pid to 0 before the child process receive kill signal.

So add new API pool_get_process_info_by_process_id() which just
returns the slot by using global variable my_proc_id as a key and let
child process use it.  my_proc_id was set by the parent process when
the child process was spawn.

The call to pool_get_process_info() in child.c was added in v4.3. So
back patch to V4_3_STABLE.

3 years agoFix shared memory allocation function.
Tatsuo Ishii [Wed, 6 Apr 2022 07:30:35 +0000 (16:30 +0900)]
Fix shared memory allocation function.

pool_shared_memory_segment_get_chunk() which is responsible for shared
memory allocation, failed to consider request size alignment. If
requeste size is not in MAXALIGN (typically 8) bytes, it could overrun
the shared memory area. Probably harmless in the wild but better to
fix.

3 years agoFix possible null pointer dereference per Coverity.
Tatsuo Ishii [Wed, 6 Apr 2022 05:50:56 +0000 (14:50 +0900)]
Fix possible null pointer dereference per Coverity.

3 years agoRevert "Prevent hang in terminate_all_childrens()."
Tatsuo Ishii [Mon, 4 Apr 2022 07:23:44 +0000 (16:23 +0900)]
Revert "Prevent hang in terminate_all_childrens()."

This reverts commit a5e2e0411dc3ef91aafc8f4c5e1d7369e7eb3b46.

3 years agoPrevent hang in terminate_all_childrens().
Tatsuo Ishii [Fri, 1 Apr 2022 10:54:49 +0000 (19:54 +0900)]
Prevent hang in terminate_all_childrens().

waitpid() was used in the function without WNOHANG was being set.
This could cause hang in waitpic().
Also fix typo. Rename terminate_all_childrens to terminate_all_children.

3 years agoFix logging for disabled pool_passwd
Muhammad Usama [Tue, 29 Mar 2022 14:31:49 +0000 (19:31 +0500)]
Fix logging for disabled pool_passwd

Refrain from emitting 'password file descriptor is NULL' warning
and error messages when pool_passwd is disabled.

3 years agoAdd pending signal check in check_requests().
Tatsuo Ishii [Sat, 26 Mar 2022 07:32:59 +0000 (16:32 +0900)]
Add pending signal check in check_requests().

Still struggling why shutdown signal is not delivered. For this
purpose add sigpending() before release the signal mask.

3 years agoAllow shutdown interrupt while processing SIGCHILD in pgpool main.
Tatsuo Ishii [Sat, 19 Mar 2022 09:25:15 +0000 (18:25 +0900)]
Allow shutdown interrupt while processing SIGCHILD in pgpool main.

Currently most signals are blocked in pgpool main loop. In some
situations the SIGCHLD handler (reaper()) takes long time or blocked
in wait system call. I suspect that this could cause occasional
timeout in some regression tests. So allow interrupts while executing
reaper(). Also re-implement CHECK_REQUEST macro as a function. There's
no point to implement CHECK_REQUEST using macro.

3 years agoFix bug with pg_enc and pg_md5.
Tatsuo Ishii [Fri, 18 Mar 2022 11:52:07 +0000 (20:52 +0900)]
Fix bug with pg_enc and pg_md5.

When these commands are invoked with "-i" option (read username/password
pairs from a file), it did not create proper entries in pool_passwd.
This bug was introduced by the commit:
https://git.postgresql.org/gitweb/?p=pgpool2.git;a=commit;h=441bde41767fe3bccad513735f946dd2dec5059b

Bug reported in https://www.pgpool.net/mantisbt/view.php?id=747

3 years agoEnhance 077.invalid_failover_node regression test.
Tatsuo Ishii [Tue, 15 Mar 2022 08:29:23 +0000 (17:29 +0900)]
Enhance 077.invalid_failover_node regression test.

It seems the timeout for pcp_promote_node was not long enough.
Increase it from 30 seconds to 60 seconds.

3 years agoEnhance error message while processing parse message.
Tatsuo Ishii [Sat, 12 Mar 2022 04:33:42 +0000 (13:33 +0900)]
Enhance error message while processing parse message.

In non-streaming replication mode, a sync message is sent to backend
after a parse message is sent to backend, expecting to get a ready for
query message.  If different message is returned, pgpool will complain
that. This commit adds more information: the message kind returned and
the backend node id.

3 years agoCleanup pgpool main process logging.
Tatsuo Ishii [Fri, 11 Mar 2022 04:40:28 +0000 (13:40 +0900)]
Cleanup pgpool main process logging.

Downgrade some logs for forking process to not flood the log
file. Also emphasis important events such as failover starting.

3 years agoDowngrade log level of ParameterStatus message.
Tatsuo Ishii [Fri, 11 Mar 2022 01:38:08 +0000 (10:38 +0900)]
Downgrade log level of ParameterStatus message.

In commit 4bcba5258130c3cd9f855157a4359aad2fa7acfc the log level when
ParameterStatus message arrives from backend was changed from DEBUG5
to LOG. There are multiple complains about the change because chances
of the event is more frequent than I thought. So revert back the log
level to DEBUG5.

Discussion: https://www.pgpool.net/pipermail/pgpool-general/2022-March/008101.html

3 years agoFix not to include garbage in "%m" log_line_prefix.
Tatsuo Ishii [Thu, 10 Mar 2022 10:55:10 +0000 (19:55 +0900)]
Fix not to include garbage in "%m" log_line_prefix.

When "%m" (milliseconds) is used in log_line_prefix, the millisecond
part was copied to log_line_prefix string without null termination. As
a result, sometimes garbage was included after the milliseconds part.

3 years agoImplement comma separated multiple pcp listen addresses.
Tatsuo Ishii [Sat, 5 Mar 2022 02:59:08 +0000 (11:59 +0900)]
Implement comma separated multiple pcp listen addresses.

Pgpool-II only allowed to set single hostname, IP or '*' in
pcp_listen_addresses parameter. Now we can set multiple listen
addresses to the parameter like listen_addresses.  Note that the
documentations for pcp_listen_addresses are shamelessly stolen from
PostgreSQL.

Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2022-February/004131.html

3 years agoFix main process exiting while performing finding primary node.
Tatsuo Ishii [Fri, 4 Mar 2022 11:00:41 +0000 (20:00 +0900)]
Fix main process exiting while performing finding primary node.

Pgpool-II main process tries to find primary node whenever the cluster
status is changed by failover/failback. While doing it, if a backend
is failing or shutting down, socket write to the backend could
fail. Unfortunately in the case do_query() throws FATAL error, which
makes the Pgpool-II main process die like this.

2022-03-04 18:13:12.711: main pid 795826: WARNING:  write on backend 1 failed with error :"Broken pipe"
2022-03-04 18:13:12.711: main pid 795826: DETAIL:  while trying to write data from offset: 0 wlen: 32
2022-03-04 18:13:12.711: main pid 795826: LOG:  notice_backend_error: called from pgpool main. ignored.
2022-03-04 18:13:12.711: main pid 795826: LOG:  unable to flush data to backend
2022-03-04 18:13:12.711: main pid 795826: DETAIL:  do not failover because I am the main process
2022-03-04 18:13:12.711: main pid 795826: FATAL:  Backend throw an error message
2022-03-04 18:13:12.711: main pid 795826: DETAIL:  Exiting current session because of an error from backend
2022-03-04 18:13:12.711: main pid 795826: HINT:  BACKEND Error: "terminating connection due to administrator command"
2022-03-04 18:13:12.715: main pid 795826: LOG:  shutting down

To prevent it, change ereport(FATAL) to ereport(ERROR) in do_query().

3 years agoFix: [pgpool-general: 8030] ... segfaults on CentOS 8
Muhammad Usama [Thu, 3 Mar 2022 10:25:31 +0000 (15:25 +0500)]
Fix: [pgpool-general: 8030] ... segfaults on CentOS 8

Event names array used by debug messages had a missing
entry for WD_EVENT_I_AM_APPEARING_FOUND

3 years agoEnhance regression test 077.invalid_failover_node.
Tatsuo Ishii [Tue, 1 Mar 2022 08:35:54 +0000 (17:35 +0900)]
Enhance regression test 077.invalid_failover_node.

Print starting time to see if timeout is suitable for this test.
Also print relative time from the start of retry loop.

3 years agoChange the default value of pcp_listen_addresses from '*' to 'localhost'.
Tatsuo Ishii [Mon, 28 Feb 2022 07:16:18 +0000 (16:16 +0900)]
Change the default value of pcp_listen_addresses from '*' to 'localhost'.

Sync with compiled default.

3 years agoChange the default value of pcp_listen_addresses from '*' to 'localhost'.
Tatsuo Ishii [Mon, 28 Feb 2022 06:52:11 +0000 (15:52 +0900)]
Change the default value of pcp_listen_addresses from '*' to 'localhost'.

'*' was not very secure. Also the default value of listen_address in
Pgpool-II and PostgreSQL are 'localhost'.

3 years agoMore tweak regression test 077.invalid_failover_node/test.sh script.
Tatsuo Ishii [Sun, 27 Feb 2022 23:50:56 +0000 (08:50 +0900)]
More tweak regression test 077.invalid_failover_node/test.sh script.

Previous commit was not quite correct and actually the timeout was to
not increased.

3 years agoDoc: update copyright year.
Bo Peng [Sun, 27 Feb 2022 03:36:16 +0000 (12:36 +0900)]
Doc: update copyright year.

3 years agoMore tweak regression test 077.invalid_failover_node/test.sh script.
Tatsuo Ishii [Fri, 25 Feb 2022 23:19:34 +0000 (08:19 +0900)]
More tweak regression test 077.invalid_failover_node/test.sh script.

Build farm complained that failover on node 1 did not complete with 20
seconds.  Let's increase it to 30 seconds before timeout and see what
build farm says.

3 years agoFixed follow_primary.sh.sample script to check the status of PostgreSQL using pg_isready.
Bo Peng [Fri, 25 Feb 2022 05:29:02 +0000 (14:29 +0900)]
Fixed follow_primary.sh.sample script to check the status of PostgreSQL using pg_isready.

3 years agoMore tweak regression test 077.invalid_failover_node/test.sh script.
Tatsuo Ishii [Thu, 24 Feb 2022 23:45:14 +0000 (08:45 +0900)]
More tweak regression test 077.invalid_failover_node/test.sh script.

Build farm complained that failover on node 1 did not complete with 5
seconds.  Let's increase it to 20 seconds before timeout and see what
build farm says.

3 years agoAllow to specify duplicated entry in listen_addresses.
Tatsuo Ishii [Thu, 24 Feb 2022 08:27:15 +0000 (17:27 +0900)]
Allow to specify duplicated entry in listen_addresses.

If duplicated entry exists in listen_addresses, pgpool did not
start. On the other hand PostgreSQL just complains and ignores the
duplicated entry.  So this commit follow the behavior of PostgreSQL.
Also PostgreSQL ignores wrong host name or IP. So pgpool follows it
too.

Plus fix comment for listen_addresses in pool_config_variable.c so
that it uses plural (i.e. hotsname(s)).

3 years agoTweak regression test 077.invalid_failover_node/test.sh script.
Tatsuo Ishii [Wed, 23 Feb 2022 12:01:51 +0000 (21:01 +0900)]
Tweak regression test 077.invalid_failover_node/test.sh script.

Build farm complained that pcp_promote_node did not complete with 5
seconds.  Let's increase it to 20 seconds before timeout and see what
build farm says.

3 years agoImplement comma separated multiple listen addresses.
Tatsuo Ishii [Wed, 23 Feb 2022 03:29:44 +0000 (12:29 +0900)]
Implement comma separated multiple listen addresses.

Pgpool-II only allowed to set single hostname, IP or '*' to the
listen_addresses parameter. Now we can set multiple listen addresses
to the parameter as PostgreSQL already does.  Note that the
documentations for listen_addresses are shamelessly stolen from
PostgreSQL.

Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2022-February/004131.html

3 years agoAdd regression test case for testing "invalid degenerate backend request".
Tatsuo Ishii [Tue, 22 Feb 2022 02:04:42 +0000 (11:04 +0900)]
Add regression test case for testing "invalid degenerate backend request".

This is the test for commit: 214e0017

3 years agoAdd patch to enable parameters related to logging_collector.
Bo Peng [Tue, 22 Feb 2022 04:38:51 +0000 (13:38 +0900)]
Add patch to enable parameters related to logging_collector.

3 years agoFix invalid degenerate backend request problem.
Tatsuo Ishii [Tue, 22 Feb 2022 01:42:09 +0000 (10:42 +0900)]
Fix invalid degenerate backend request problem.

When health check process sends failover request, it fails in rare
cases with message: "invalid degenerate backend request , node id : 2
status: [2] is not valid for failover". This is caused if backend node
status managed in private_backend_status and the one in the share
memory area do not agree. private_backend_status is initialized upon
starting up of process. It's not updated during process's life
cycle. Usually this is ok, but for example consider following
scenario:

(1) When pgpool starts, node 1 is down in pgpool_status. So health
check process did not start for node 1.

(2) pcp_promote_node --switchover gets called. Health check process
for node 1 starts and private_backend_status for node 1 remains down.

(3) Node 1 is back to online by follow master command.

(4) Node 1 is shutdown.

(5) The health check process detects node 1 is down and requests
failover. But since private_backend_status is down, it is refused with
the message.

To fix this, we can simply delete the call to
pool_initialize_private_backend_status() at the process start
up. Originally the intention for private_backend_status() is that
pgpool child process is not bothered by the status change in the
middle of process. This is not necessary for health check and
streaming replication check.

Note that I was not able to find a scenario for prior 4.3. Once I
find, I will back patch this to pre 4.3 branches.

Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2022-February/004128.html

3 years agoAdd release notes.
Masaya Kawamoto [Thu, 17 Feb 2022 00:09:10 +0000 (00:09 +0000)]
Add release notes.

3 years agoFixed the streaming replication check process not to retry if it cannot connect to...
Bo Peng [Thu, 10 Feb 2022 02:02:38 +0000 (11:02 +0900)]
Fixed the streaming replication check process not to retry if it cannot connect to the backend.

If the backend takes so long to respond, the connection times out,
then the streaming replication check process will continue to retry.
This retry causes a long time failover.

3 years agoAdd validations of wd_lifecheck_password and recovery_password format
Masaya Kawamoto [Thu, 10 Feb 2022 01:39:52 +0000 (01:39 +0000)]
Add validations of wd_lifecheck_password and recovery_password format

This feature was reverted once due to regression
test failure by dea2fbf65fdb3250f825e20f20fc3081779d8a3e.

3 years agoFix missed static declaration.
Tatsuo Ishii [Wed, 9 Feb 2022 23:45:43 +0000 (08:45 +0900)]
Fix missed static declaration.

The static declaration of fork_follow_child() was missing. Also fix
typo in a comment.

3 years agoRemove ifdef out code.
Tatsuo Ishii [Tue, 8 Feb 2022 05:56:13 +0000 (14:56 +0900)]
Remove ifdef out code.

Ancient health check is no longer needed to be preserved.

3 years agoRefactor failover().
Tatsuo Ishii [Tue, 8 Feb 2022 05:26:29 +0000 (14:26 +0900)]
Refactor failover().

failover() was too large and hard to maintain. By refactoring it, the
size is reduced from 798 lines to 215 lines.  It is now splitted into
following subroutines. failover() just calls them.

static int handle_failback_request(FAILOVER_CONTEXT *failover_context, int node_id);
static int handle_failover_request(FAILOVER_CONTEXT *failover_context, int node_id);
static void kill_failover_children(FAILOVER_CONTEXT *failover_context, int node_id);
static void exec_failover_command(FAILOVER_CONTEXT *failover_context, int new_main_node_id, int promote_node_id);
static int determine_new_primary_node(FAILOVER_CONTEXT *failover_context, int node_id);
static int exec_follow_primary_command(FAILOVER_CONTEXT *failover_context, int node_id, int new_primary_node_id);
static void save_node_info(FAILOVER_CONTEXT *failover_context, int new_primary_node_id, int new_main_node_id);
static void exec_child_restart(FAILOVER_CONTEXT *failover_context, int node_id);
static void exec_notice_pcp_child(FAILOVER_CONTEXT *failover_context);

3 years agoFixed mistakes introduced in the previous commit.
Bo Peng [Mon, 7 Feb 2022 03:19:01 +0000 (12:19 +0900)]
Fixed mistakes introduced in the previous commit.

3 years agoFixed sample failover script.
Bo Peng [Mon, 7 Feb 2022 03:06:45 +0000 (12:06 +0900)]
Fixed sample failover script.

This script did not consider the case when the old primary node id is "-1".

3 years agoFix failover() to deal with the case when no former primary node exists.
Tatsuo Ishii [Sun, 6 Feb 2022 08:11:52 +0000 (17:11 +0900)]
Fix failover() to deal with the case when no former primary node exists.

Consider a case when no primary node exists when Pgpool-II starts
up. In this case Req_info->primary_node_id is -1. failover() did not
consider this and skipped to call find_primary_node_repeatedly().
Also follow_master_command was not executed if
Req_info->primary_node_id is -1.

This commit fixes the bug above.

Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2022-February/004114.html

3 years agoFix pgpool_setup in failover scrip creation.
Tatsuo Ishii [Sun, 6 Feb 2022 07:23:46 +0000 (16:23 +0900)]
Fix pgpool_setup in failover scrip creation.

When pgpool_set creates failover.sh, it did not consider the case when
no primary server existed.