Skip to content

Commit d73a35c

Browse files
committed
fix(pgsql): handle PostgreSQL list-type GUC parameters correctly (#689)
PostgreSQL has certain GUC parameters that accept comma-separated lists (marked with GUC_LIST_INPUT flag). These parameters must NOT have their entire value wrapped in quotes, otherwise PostgreSQL treats the whole string as a single value rather than parsing it as a comma-separated list. Problem: In v4.0.0, the parameter templates were changed to quote all values: ALTER USER "x" SET "search_path" = '"$user", public'; -- WRONG This causes search_path to be stored as ONE string instead of a list. Solution: Use a whitelist approach to identify list-type parameters and render them without outer quotes: ALTER USER "x" SET "search_path" = "$user", public; -- CORRECT Affected parameters by context level: User/Role level (pg-user.sql, pg-init-roles.sql): - search_path - temp_tablespaces - local_preload_libraries - session_preload_libraries Database level (pg-db.sql): - Above parameters plus log_destination Instance level (patroni.yml -> postgresql.auto.conf): - Above parameters plus: - shared_preload_libraries - unix_socket_directories - debug_io_direct Also adds missing condition for pg_watchdog task to skip when patroni_watchdog_mode is set to 'off'. Fixes: #689
1 parent 24e75c6 commit d73a35c

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

roles/pgsql/tasks/patroni.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- name: grant postgres dbsu watchdog owner
77
tags: pg_watchdog
88
ignore_errors: true
9+
when: patroni_watchdog_mode != 'off'
910
file: path=/dev/watchdog owner={{ pg_dbsu }} group=postgres
1011

1112

@@ -63,8 +64,13 @@
6364
content: |
6465
# Do not edit this file or use ALTER SYSTEM manually!
6566
# It is managed by Pigsty & Ansible automatically!
67+
{% set list_params = ['search_path', 'temp_tablespaces', 'local_preload_libraries', 'session_preload_libraries', 'log_destination', 'shared_preload_libraries', 'unix_socket_directories', 'debug_io_direct'] %}
6668
{% for key, value in pg_parameters.items() %}
69+
{% if key in list_params %}
70+
{{ key }} = {{ value }}
71+
{% else %}
6772
{{ key }} = '{{ value }}'
73+
{% endif %}
6874
{% endfor %}
6975
7076
- name: restart postgres via patroni
@@ -216,8 +222,13 @@
216222
content: |
217223
# Do not edit this file or use ALTER SYSTEM manually!
218224
# It is managed by Pigsty & Ansible automatically!
225+
{% set list_params = ['search_path', 'temp_tablespaces', 'local_preload_libraries', 'session_preload_libraries', 'log_destination', 'shared_preload_libraries', 'unix_socket_directories', 'debug_io_direct'] %}
219226
{% for key, value in pg_parameters.items() %}
227+
{% if key in list_params %}
228+
{{ key }} = {{ value }}
229+
{% else %}
220230
{{ key }} = '{{ value }}'
231+
{% endif %}
221232
{% endfor %}
222233
223234

roles/pgsql/templates/pg-db.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,13 @@ ALTER DATABASE "{{ database.name }}" IS_TEMPLATE {{ database.is_template|lower }
8080

8181
-- parameters
8282
{% if 'parameters' in database and database.parameters is not none %}
83+
{% set list_params = ['search_path', 'temp_tablespaces', 'local_preload_libraries', 'session_preload_libraries', 'log_destination'] %}
8384
{% for key, value in database.parameters.items() %}
8485
{% if value is not none %}
8586
{% if value | string | upper == 'DEFAULT' %}
8687
ALTER DATABASE "{{ database.name }}" SET "{{ key }}" = DEFAULT;
88+
{% elif key in list_params %}
89+
ALTER DATABASE "{{ database.name }}" SET "{{ key }}" = {{ value }};
8790
{% else %}
8891
ALTER DATABASE "{{ database.name }}" SET "{{ key }}" = '{{ value | replace("'", "''") }}';
8992
{% endif %}

roles/pgsql/templates/pg-init-roles.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,13 @@ ALTER USER "{{ user.name }}" CONNECTION LIMIT {{ user.connlimit | int }};
7575

7676
-- parameters
7777
{% if 'parameters' in user and user.parameters is not none and user.parameters|length > 0 %}
78+
{% set list_params = ['search_path', 'temp_tablespaces', 'local_preload_libraries', 'session_preload_libraries'] %}
7879
{% for key, value in user.parameters.items() %}
7980
{% if value is not none %}
8081
{% if value | string | upper == 'DEFAULT' %}
8182
ALTER USER "{{ user.name }}" SET "{{ key }}" = DEFAULT;
83+
{% elif key in list_params %}
84+
ALTER USER "{{ user.name }}" SET "{{ key }}" = {{ value }};
8285
{% else %}
8386
ALTER USER "{{ user.name }}" SET "{{ key }}" = '{{ value | replace("'", "''") }}';
8487
{% endif %}

roles/pgsql/templates/pg-user.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,13 @@ ALTER USER "{{ user.name }}" CONNECTION LIMIT {{ user.connlimit | int }};
8080

8181
-- parameters
8282
{% if 'parameters' in user and user.parameters is not none and user.parameters|length > 0 %}
83+
{% set list_params = ['search_path', 'temp_tablespaces', 'local_preload_libraries', 'session_preload_libraries'] %}
8384
{% for key, value in user.parameters.items() %}
8485
{% if value is not none %}
8586
{% if value | string | upper == 'DEFAULT' %}
8687
ALTER USER "{{ user.name }}" SET "{{ key }}" = DEFAULT;
88+
{% elif key in list_params %}
89+
ALTER USER "{{ user.name }}" SET "{{ key }}" = {{ value }};
8790
{% else %}
8891
ALTER USER "{{ user.name }}" SET "{{ key }}" = '{{ value | replace("'", "''") }}';
8992
{% endif %}

0 commit comments

Comments
 (0)