pgsql: Remove explicit user option from exec_sql #2050
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What i did
Removed the direct usage of -U $OCF_RESKEY_pgdba within the
exec_sql() function for specifying the psql user.
This change ensures that exec_sql() consistently uses the database
user defined in the global $psql_options. It simplifies user
management by relying on a single source for psql connection
parameters, including credentials, for operations invoked via
this function.
Problem Description
When the monitor_user attribute is configured in the pgsql RA, the main() function exports PGUSER (set to $OCF_RESKEY_monitor_user) and PGPASSWORD (set to $OCF_RESKEY_monitor_password) as global environment variables during resource startup.
The psql_options variable is set as follows:
During the PostgreSQL startup sequence initiated by the RA (pgsql_real_start() → pgsql_real_monitor()), the exec_sql() function is called to check the database's recovery status (by running SELECT pg_is_in_recovery()).
The exec_sql() function, as seen in heartbeat/pgsql#L534, constructs a psql command that explicitly includes the -U $OCF_RESKEY_pgdba option:
This leads to an authentication issue due to the interaction of psql command-line options and environment variables:
Consequently, psql attempts to authenticate as the $OCF_RESKEY_pgdba user but uses the password intended for $OCF_RESKEY_monitor_user. If these passwords differ, the authentication fails. This prevents the RA from obtaining the recovery status, ultimately causing the pgsql resource agent to report an error.
The effective psql invocation attempts the following:
Connect as user: $OCF_RESKEY_pgdba
Using password: Value of PGPASSWORD (which is $OCF_RESKEY_monitor_password)
If the monitor_user's password does not match the pgdba's password, the connection fails, and the RA cannot determine the recovery status, as shown in the logs (see also heartbeat/pgsql#L978):
If you use the same password for monitor_password and pgdba(postgres), you can get the recovery status without any problem.
Enviroment