refactor(postgresql): update postgresql roles and handler to optimize init check logic

This commit is contained in:
2026-04-17 13:58:22 +09:00
parent 9f236b6fa5
commit dbd72f43a4
2 changed files with 14 additions and 11 deletions

View File

@@ -12,7 +12,7 @@
- name: Reload postgresql
ansible.builtin.command:
/usr/bin/podman exec -u postgres postgresql sh -c "pg_ctl reload"
when: not (is_postgresql_init_run | default(false))
when: is_postgresql_init.stat.exists
changed_when: false
listen: "notification_reload_postgresql"
ignore_errors: true # noqa: ignore-errors
@@ -24,7 +24,7 @@
enabled: true
daemon_reload: true
scope: "user"
when: not (is_postgresql_init_run | default(false))
when: is_postgresql_init.stat.exists
changed_when: false
listen: "notification_restart_postgresql"
ignore_errors: true # noqa: ignore-errors

View File

@@ -88,15 +88,13 @@
no_log: true
- name: Check data directory empty
ansible.builtin.find:
paths: "{{ node['home_path'] }}/containers/postgresql/data/"
hidden: true
file_type: "any"
ansible.builtin.stat:
path: "{{ node['home_path'] }}/containers/postgresql/data/.init"
become: true
register: "is_data_dir_empty"
register: "is_postgresql_init"
- name: Prepare initiating DB
when: is_data_dir_empty.matched == 0
when: not is_postgresql_init.stat.exists
become: true
block:
# `init/pg_cluster.sql` should be fetched from postgresql's backup directory before running initiating
@@ -118,9 +116,14 @@
loop: "{{ connected_services }}"
loop_control:
index_var: index_num
- name: Set is_postgresql_init_run
ansible.builtin.set_fact:
is_postgresql_init_run: true
- name: Create .init file
ansible.builtin.file:
path: "{{ node['home_path'] }}/containers/postgresql/data/.init"
state: "touch"
mode: "0644"
owner: "{{ ansible_user }}"
group: "svadmins"
- name: Deploy container file
ansible.builtin.template: