Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgresql_set - Fix GUC_LIST_QUOTE parameters #521

Merged

Conversation

RealGreenDragon
Copy link
Contributor

@RealGreenDragon RealGreenDragon commented Jul 9, 2023

SUMMARY

My PR fixes GUC_LIST_QUOTE parameters management in postgresql_set module.

GUC_LIST_QUOTE parameters are multi-value parameters (like GUC_LIST_INPUT parameters) whose elements are surrounded by double-quotes if not match ^[A-Za-z09_]+$ pattern.
Now such double-quotes are ignored by postgresql_set module and it causes an always-changed status in these cases. It is a very serious bug if the parameter is a postmaster, as unix_socket_directories (it became GUC_LIST_QUOTE in PostgreSQL 14).
The bug has not seen until now as GUC_LIST_QUOTE parameters are few and many of them have not valid values that contain special characters (as shared_preload_libraries parameter).

Examples:

#### PostgreSQL 13

pg13=# ALTER SYSTEM SET unix_socket_directories = '/var/run/postgresql';
ALTER SYSTEM

postgres@pg13:~$ grep unix_socket_directories postgresql.auto.conf 
unix_socket_directories = '/var/run/postgresql'

pg13=# ALTER SYSTEM SET unix_socket_directories = '/var/run/postgresql,/tmp'; --> NEVER DONE FROM PR #357 
ALTER SYSTEM

postgres@pg13:~$ grep unix_socket_directories postgresql.auto.conf 
unix_socket_directories = '/var/run/postgresql,/tmp' --> RIGHT BUT NOW NEVER OBTAINED (AS CONSIDERED MULTI_VALUE)

pg13=# ALTER SYSTEM SET unix_socket_directories = '/var/run/postgresql','/tmp';
ERROR:  SET unix_socket_directories takes only one argument

#### PostgreSQL 14

pg14=# ALTER SYSTEM SET unix_socket_directories = '/var/run/postgresql';
ALTER SYSTEM

postgres@pg14:~$ grep unix_socket_directories postgresql.auto.conf 
unix_socket_directories = '"/var/run/postgresql"'

pg13=# ALTER SYSTEM SET unix_socket_directories = '/var/run/postgresql,/tmp'; --> NEVER DONE FROM PR #357 
ALTER SYSTEM

postgres@pg13:~$ grep unix_socket_directories postgresql.auto.conf 
unix_socket_directories = '"/var/run/postgresql,/tmp"' --> WRONG (SO CORRECT BEHAVIOR)

pg14=# ALTER SYSTEM SET unix_socket_directories = '/var/run/postgresql','/tmp';
ALTER SYSTEM

postgres@pg14:~$ grep unix_socket_directories postgresql.auto.conf
unix_socket_directories = '"/var/run/postgresql", "/tmp"'

To solve the bug the only way is to hard-code GUC_LIST_QUOTE parameters list in the code (very short and static in the time) as there is no way to distinguish the case in with a parameter value need an unquote or not (specially with values composed by a single elements). The same approach is applied in pg_dump code (variable_is_guc_list_quote function).

Hard-code also the list of GUC_LIST_INPUT parameters is expensive and for now (I think) not necessary. However I added a check to not consider multi-value unix_socket_directories parameter until PostgreSQL 13, as only from PostgreSQL 14 GUC_LIST_INPUT and GUC_LIST_QUOTE options are added to that parameter.

In test added there is also a general idempotence check after a reboot (as unix_socket_directories parameter is postmaster).

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

postgresql_set

ADDITIONAL INFORMATION

@ PostgreSQL 14 -> Add GUC_LIST_INPUT and GUC_LIST_QUOTE to unix_socket_directories
postgres/postgres@a05dbf4

@ List of GUC params (PostgreSQL 15 only)
https://github.com/postgres/postgres/blob/5edf438eeb00271cca5d19d0ea10a2d6e8d018c4/src/backend/utils/misc/guc_tables.c

@ Fixed list of GUC_LIST_QUOTE params in each supported major version (variable_is_guc_list_quote function)
15 -> https://github.com/postgres/postgres/blob/8382864eb5c9f9ebe962ac20b3392be5ae304d23/src/bin/pg_dump/dumputils.c#L689
14 -> https://github.com/postgres/postgres/blob/b6cf730e80e8571066c0ce76e76ce99b9144c149/src/bin/pg_dump/dumputils.c#L849
13 -> https://github.com/postgres/postgres/blob/2faab87390b03929a8cbb5a9336a04faa45a27c5/src/bin/pg_dump/dumputils.c#L849
12 -> https://github.com/postgres/postgres/blob/117dd58fd9cd01e661a2c36977e16a2722306a6d/src/bin/pg_dump/dumputils.c#L849
11 -> https://github.com/postgres/postgres/blob/f96e531b1c079ae148b927a204845c7150a573f8/src/bin/pg_dump/dumputils.c#L849
10 -> https://github.com/postgres/postgres/blob/02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4/src/bin/pg_dump/dumputils.c#L846
9.6 -> https://github.com/postgres/postgres/blob/a4116b8d5a4f68803452d8f1aa3f74f302049a90/src/bin/pg_dump/dumputils.c#L853
9.5 -> https://github.com/postgres/postgres/blob/202c587e2f28bc295f6935d044e20680b627e7a1/src/bin/pg_dump/dumputils.c#L1536
9.4 -> https://github.com/postgres/postgres/blob/30ffdd24d7222bc01183a56d536c236240674516/src/bin/pg_dump/dumputils.c#L1537

@ GUC_LIST_QUOTE element quote function (quote_identifier function - PostgreSQL 15 only)
https://github.com/postgres/postgres/blob/master/src/backend/utils/adt/ruleutils.c#L11930

@ GUC_LIST_INPUT/GUC_LIST_QUOTE elements split function (SplitGUCList function - PostgreSQL 15 only)
https://github.com/postgres/postgres/blob/6ee01e25b7f79bdf835d12927b306ad922c55fd3/src/backend/utils/adt/varlena.c#L3702

@RealGreenDragon RealGreenDragon changed the title postgresql_set - Fixed GUC_LIST_QUOTE parameters postgresql_set - Fix GUC_LIST_QUOTE parameters Jul 9, 2023
@RealGreenDragon RealGreenDragon marked this pull request as ready for review July 9, 2023 19:38
@RealGreenDragon
Copy link
Contributor Author

Ready for review

@RealGreenDragon RealGreenDragon requested a review from hunleyd July 10, 2023 18:04
@RealGreenDragon
Copy link
Contributor Author

RealGreenDragon commented Jul 10, 2023

@hunleyd Change done, now ansible/third-party-check fails but I don't know why (seems it fails also for all other PRs)

plugins/modules/postgresql_set.py Outdated Show resolved Hide resolved
@hunleyd hunleyd merged commit c5b5bc2 into ansible-collections:main Jul 13, 2023
@Andersson007
Copy link
Collaborator

@RealGreenDragon thanks for the contribution!
@hunleyd @jchancojr thanks for reviewing and merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants