Skip to content

Commit 53beb0b

Browse files
committed
refactor: Improve PostgreSQL setup and initialization
Consolidate template tasks for postgresql.conf, pg_hba.conf, and pg_ident.conf into a single loop. Ensure placeholder config files are correctly placed within `/etc/postgresql-custom/conf.d/`. Remove the redundant `-D /data/pgdata` argument from the `initdb` commands, as the data directory is now managed by a symlink to `/data/pgdata`. Add debug commands to verify the data directory symlink.
1 parent 55dc27a commit 53beb0b

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

ansible/tasks/setup-postgres.yml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -183,29 +183,23 @@
183183
group: postgres
184184
mode: 0664
185185
owner: postgres
186-
path: '/etc/postgresql-custom/{{ item }}'
186+
path: '/etc/postgresql-custom/conf.d/{{ item }}'
187187
state: touch
188188
with_items:
189189
- 'generated-optimizations.conf'
190190
- 'custom-overrides.conf'
191191

192-
- name: import postgresql.conf
193-
ansible.builtin.template:
194-
dest: /etc/postgresql/postgresql.conf
195-
group: postgres
196-
src: files/postgresql_config/postgresql.conf.j2
197-
198-
- name: import pg_hba.conf
199-
ansible.builtin.template:
200-
dest: /etc/postgresql/pg_hba.conf
201-
group: postgres
202-
src: files/postgresql_config/pg_hba.conf.j2
203-
204-
- name: import pg_ident.conf
192+
- name: import postgresql.conf, pg_hba.conf, and pg_ident.conf
205193
ansible.builtin.template:
206-
dest: /etc/postgresql/pg_ident.conf
194+
dest: /etc/postgresql/{{ conf_item }}
207195
group: postgres
208-
src: files/postgresql_config/pg_ident.conf.j2
196+
src: files/postgresql_config/{{ conf_item }}.j2
197+
loop:
198+
- postgresql.conf
199+
- pg_hba.conf
200+
- pg_ident.conf
201+
loop_control:
202+
loop_var: conf_item
209203

210204
- name: Move custom read-replica.conf file to /etc/postgresql-custom/conf.d/read-replica.conf
211205
ansible.builtin.copy:
@@ -247,6 +241,10 @@
247241
src: '/data/pgdata'
248242
state: 'link'
249243

244+
- command: ls -ld /var/lib/postgresql/data
245+
register: pgdata
246+
- debug:
247+
msg: "{{ pgdata.stdout }}"
250248
- name: Initialize the database
251249
become: true
252250
become_user: 'postgres'
@@ -257,7 +255,6 @@
257255
- --allow-group-access
258256
- --data-checksums
259257
- --username=supabase_admin
260-
- -D /data/pgdata
261258
args:
262259
creates: /var/lib/postgresql/data/PG_VERSION
263260
vars:
@@ -274,7 +271,7 @@
274271
when:
275272
- nixpkg_mode
276273

277-
- name: Check psql_version and modify supautils.conf and postgresql.conf if necessary
274+
- name: Check psql_version and call initdb appropriately
278275
when:
279276
- stage2_nix
280277
block:
@@ -283,6 +280,10 @@
283280
is_psql_17: "{{ psql_version in ['psql_17'] }}"
284281
is_psql_oriole: "{{ psql_version in ['psql_orioledb-17'] }}"
285282

283+
- command: ls -ld /var/lib/postgresql/data
284+
register: pgdata
285+
- debug:
286+
msg: "{{ pgdata.stdout }}"
286287
- name: Initialize the database stage2_nix (non-orioledb)
287288
become: true
288289
become_user: 'postgres'
@@ -293,7 +294,6 @@
293294
- --allow-group-access
294295
- --data-checksums
295296
- --username=supabase_admin
296-
- -D /data/pgdata
297297
args:
298298
creates: /var/lib/postgresql/data/PG_VERSION
299299
environment:

0 commit comments

Comments
 (0)