Skip to content

Commit 02583d0

Browse files
committed
feat: use /var/lib/postgresql as home for postgres user
1 parent 41957bc commit 02583d0

File tree

7 files changed

+35
-36
lines changed

7 files changed

+35
-36
lines changed

ansible-nix/tasks/setup-postgres.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
state: present
1313

1414
- name: create postgres user
15-
shell: useradd -m -r -s /bin/bash -d /home/postgres postgres -g postgres
15+
shell: adduser --system --home /var/lib/postgresql --no-create-home --shell /bin/bash --group --gecos "PostgreSQL administrator" postgres
1616
args:
1717
executable: /bin/bash
1818
become: yes
@@ -31,7 +31,6 @@
3131
owner: postgres
3232
group: postgres
3333
with_items:
34-
- '/home/postgres'
3534
- '/var/log/postgresql'
3635
- '/var/lib/postgresql'
3736

@@ -63,15 +62,15 @@
6362

6463
- name: Add LOCALE_ARCHIVE to .bashrc
6564
lineinfile:
66-
dest: "/home/postgres/.bashrc"
65+
dest: "/var/lib/postgressql/.bashrc"
6766
line: 'export LOCALE_ARCHIVE=/usr/lib/locale/locale-archive'
6867
create: yes
6968
become: yes
7069

7170

7271
- name: Add LANG items to .bashrc
7372
lineinfile:
74-
dest: "/home/postgres/.bashrc"
73+
dest: "/var/lib/postgresql/.bashrc"
7574
line: "{{ item }}"
7675

7776
loop:

ansible-nix/tasks/setup-wal-g.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
- name: Add script to be run for restore_command
104104
template:
105105
src: "files/walg_helper_scripts/wal_fetch.sh"
106-
dest: /home/postgres/wal_fetch.sh
106+
dest: /var/lib/postgresql/wal_fetch.sh
107107
mode: 0500
108108
owner: postgres
109109
group: postgres

ansible-nix/tasks/stage2/playbook.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
- name: stat unit test file copy
2020
copy:
2121
src: /tmp/unit-tests/unit-test-01.sql
22-
dest: /home/postgres/unit-test-01.sql
22+
dest: /var/lib/postgresql/unit-test-01.sql
2323
# state: present
2424
owner: postgres
2525
group: postgres

ansible-nix/tasks/stage2/setup-extensions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# lineinfile:
44
# path: /etc/postgresql/postgresql.conf
55
# state: present
6-
# line: pljava.libjvm_location = '/home/postgres/.nix-profile/lib/openjdk/lib/server/libjvm.so'
6+
# line: pljava.libjvm_location = '/var/lib/postgresql/.nix-profile/lib/openjdk/lib/server/libjvm.so'
77
# It was decided to leave pljava disabled at https://github.com/supabase/postgres/pull/690 therefore removing this task
88

99
- name: pg_cron - set cron.database_name

ansible-nix/tasks/stage2/stage2-setup-postgres.yml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -89,55 +89,55 @@
8989
group: postgres
9090
mode: 0700
9191

92-
- name: Create symbolic links from /home/postgres/.nix-profile/bin to /usr/lib/postgresql/bin
92+
- name: Create symbolic links from /var/lib/postgresql/.nix-profile/bin to /usr/lib/postgresql/bin
9393
file:
9494
src: "{{ item }}"
9595
dest: "/usr/lib/postgresql/bin/{{ item | basename }}"
9696
state: link
9797
with_fileglob:
98-
- "/home/postgres/.nix-profile/bin/*"
98+
- "/var/lib/postgresql/.nix-profile/bin/*"
9999
become: yes
100100

101-
- name: Create symbolic links from /home/postgres/.nix-profile/bin to /usr/bin
101+
- name: Create symbolic links from /var/lib/postgresql/.nix-profile/bin to /usr/bin
102102
file:
103-
src: "/home/postgres/.nix-profile/bin/psql"
103+
src: "/var/lib/postgresql/.nix-profile/bin/psql"
104104
dest: "/usr/bin/psql"
105105
state: link
106106
become: yes
107107

108-
# - name: Create symbolic links from /home/postgres/.nix-profile/share/pljava to /usr/lib/postgresql/share/postgresql/pljava
108+
# - name: Create symbolic links from /var/lib/postgresql/.nix-profile/share/pljava to /usr/lib/postgresql/share/postgresql/pljava
109109
# file:
110110
# src: "{{ item }}"
111111
# dest: "/usr/lib/postgresql/share/postgresql/pljava/{{ item | basename }}"
112112
# state: link
113113
# with_fileglob:
114-
# - "/home/postgres/.nix-profile/share/pljava/*"
114+
# - "/var/lib/postgresql/.nix-profile/share/pljava/*"
115115
# become: yes
116116
# It was decided to leave pljava disabled at https://github.com/supabase/postgres/pull/690 therefore removing this task
117117

118-
- name: Create symbolic links from /home/postgres/.nix-profile/bin to /usr/bin
118+
- name: Create symbolic links from /var/lib/postgresql/.nix-profile/bin to /usr/bin
119119
file:
120-
src: "/home/postgres/.nix-profile/bin/psql"
120+
src: "/var/lib/postgresql/.nix-profile/bin/psql"
121121
dest: "/usr/bin/psql"
122122
state: link
123123
become: yes
124124

125-
- name: Create symbolic links from /home/postgres/.nix-profile/share/postgresql to /usr/lib/postgresql/share/postgresql
125+
- name: Create symbolic links from /var/lib/postgresql/.nix-profile/share/postgresql to /usr/lib/postgresql/share/postgresql
126126
file:
127127
src: "{{ item }}"
128128
dest: "/usr/lib/postgresql/share/postgresql/{{ item | basename }}"
129129
state: link
130130
with_fileglob:
131-
- "/home/postgres/.nix-profile/share/postgresql/*"
131+
- "/var/lib/postgresql/.nix-profile/share/postgresql/*"
132132
become: yes
133133

134-
- name: Create symbolic links from /home/postgres/.nix-profile/share/postgresql/extension to /usr/lib/postgresql/share/postgresql/extension
134+
- name: Create symbolic links from /var/lib/postgresql/.nix-profile/share/postgresql/extension to /usr/lib/postgresql/share/postgresql/extension
135135
file:
136136
src: "{{ item }}"
137137
dest: "/usr/lib/postgresql/share/postgresql/extension/{{ item | basename }}"
138138
state: link
139139
with_fileglob:
140-
- "/home/postgres/.nix-profile/share/postgresql/extension/*"
140+
- "/var/lib/postgresql/.nix-profile/share/postgresql/extension/*"
141141
become: yes
142142

143143
- name: create destination directory
@@ -149,26 +149,26 @@
149149
- name: Recursively create symbolic links and set permissions for the contrib/postgis-* dir
150150
shell: >
151151
sudo mkdir -p /usr/lib/postgresql/share/postgresql/contrib && \
152-
sudo find /home/postgres/.nix-profile/share/postgresql/contrib/ -mindepth 1 -type d -exec sh -c 'for dir do sudo ln -s "$dir" "/usr/lib/postgresql/share/postgresql/contrib/$(basename "$dir")"; done' sh {} + \
152+
sudo find /var/lib/postgresql/.nix-profile/share/postgresql/contrib/ -mindepth 1 -type d -exec sh -c 'for dir do sudo ln -s "$dir" "/usr/lib/postgresql/share/postgresql/contrib/$(basename "$dir")"; done' sh {} + \
153153
&& chown -R postgres:postgres "/usr/lib/postgresql/share/postgresql/contrib/"
154154
become: yes
155155

156-
- name: Create symbolic links from /home/postgres/.nix-profile/share/postgresql/timezonesets to /usr/lib/postgresql/share/postgresql/timeszonesets
156+
- name: Create symbolic links from /var/lib/postgresql/.nix-profile/share/postgresql/timezonesets to /usr/lib/postgresql/share/postgresql/timeszonesets
157157
file:
158158
src: "{{ item }}"
159159
dest: "/usr/lib/postgresql/share/postgresql/timezonesets/{{ item | basename }}"
160160
state: link
161161
with_fileglob:
162-
- "/home/postgres/.nix-profile/share/postgresql/timezonesets/*"
162+
- "/var/lib/postgresql/.nix-profile/share/postgresql/timezonesets/*"
163163
become: yes
164164

165-
- name: Create symbolic links from /home/postgres/.nix-profile/share/postgresql/tsearch_data to /usr/lib/postgresql/share/postgresql/tsearch_data
165+
- name: Create symbolic links from /var/lib/postgresql/.nix-profile/share/postgresql/tsearch_data to /usr/lib/postgresql/share/postgresql/tsearch_data
166166
file:
167167
src: "{{ item }}"
168168
dest: "/usr/lib/postgresql/share/postgresql/tsearch_data/{{ item | basename }}"
169169
state: link
170170
with_fileglob:
171-
- "/home/postgres/.nix-profile/share/postgresql/tsearch_data/*"
171+
- "/var/lib/postgresql/.nix-profile/share/postgresql/tsearch_data/*"
172172
become: yes
173173

174174

@@ -188,7 +188,7 @@
188188
- name: Initialize the database
189189
become: yes
190190
become_user: postgres
191-
shell: source /home/postgres/.bashrc && /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data initdb -o "--allow-group-access"
191+
shell: source /var/lib/postgresql/.bashrc && /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data initdb -o "--allow-group-access"
192192
args:
193193
executable: /bin/bash
194194
environment:
@@ -216,7 +216,7 @@
216216
become: yes
217217
become_user: postgres
218218
shell: |
219-
source /home/postgres/.bashrc
219+
source /var/lib/postgresql/.bashrc
220220
/usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data start
221221
environment:
222222
LANG: en_US.UTF-8
@@ -242,7 +242,7 @@
242242
become: yes
243243
become_user: postgres
244244
shell: |
245-
source /home/postgres/.bashrc && \
245+
source /var/lib/postgresql/.bashrc && \
246246
/usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data restart -o "-c shared_preload_libraries='pg_tle'"
247247
args:
248248
executable: /bin/bash

ansible-nix/tasks/stage2/test-image.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- name: Start Postgres Database to load all extensions.
88
become: yes
99
become_user: postgres
10-
shell: source /home/postgres/.bashrc && /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data start "-o -c config_file=/etc/postgresql/postgresql.conf"
10+
shell: source /var/lib/postgresql/.bashrc && /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data start "-o -c config_file=/etc/postgresql/postgresql.conf"
1111
args:
1212
executable: /bin/bash
1313
environment:
@@ -21,7 +21,7 @@
2121
- name: check contents of unit test file
2222
become: yes
2323
become_user: postgres
24-
shell: cat /home/postgres/unit-test-01.sql && ls -l /home/postgres/unit-test-01.sql
24+
shell: cat /var/lib/postgresql/unit-test-01.sql && ls -l /var/lib/postgresql/unit-test-01.sql
2525

2626
- name: verify postgres server is running
2727
become: yes
@@ -37,12 +37,12 @@
3737
LC_ALL: en_US.UTF-8
3838
LC_CTYPE: en_US.UTF-8
3939
LOCALE_ARCHIVE: /usr/lib/locale/locale-archive
40-
PATH: /home/postgres/.nix-profile/bin:$PATH
40+
PATH: /var/lib/postgresql/.nix-profile/bin:$PATH
4141

4242
- name: Run Unit tests (with filename unit-test-*) on Postgres Database
4343
become: yes
4444
become_user: postgres
45-
shell: source /home/postgres/.bashrc && /home/postgres/.nix-profile/bin/pg_prove -U postgres -h localhost -d postgres -f /home/postgres/unit-test-01.sql
45+
shell: source /var/lib/postgresql/.bashrc && /var/lib/postgresql/.nix-profile/bin/pg_prove -U postgres -h localhost -d postgres -f /var/lib/postgresql/unit-test-01.sql
4646
register: retval
4747
failed_when: retval.rc != 0
4848
args:
@@ -53,10 +53,10 @@
5353
LC_ALL: en_US.UTF-8
5454
LC_CTYPE: en_US.UTF-8
5555
LOCALE_ARCHIVE: /usr/lib/locale/locale-archive
56-
PATH: /home/postgres/.nix-profile/bin:$PATH
56+
PATH: /var/lib/postgresql/.nix-profile/bin:$PATH
5757

5858
- name: Run migrations tests
59-
shell: /home/postgres/.nix-profile/bin/pg_prove -U supabase_admin -h localhost -d postgres -v tests/test.sql
59+
shell: /var/lib/postgresql/.nix-profile/bin/pg_prove -U supabase_admin -h localhost -d postgres -v tests/test.sql
6060
register: retval
6161
failed_when: retval.rc != 0
6262
args:
@@ -68,7 +68,7 @@
6868
LC_ALL: en_US.UTF-8
6969
LC_CTYPE: en_US.UTF-8
7070
LOCALE_ARCHIVE: /usr/lib/locale/locale-archive
71-
PATH: /home/postgres/.nix-profile/bin:$PATH
71+
PATH: /var/lib/postgresql/.nix-profile/bin:$PATH
7272

7373
- name: Re-enable PG Sodium references in config
7474
become: yes
@@ -80,7 +80,7 @@
8080
become: yes
8181
become_user: postgres
8282
shell: |
83-
source /home/postgres/.bashrc && \
83+
source /var/lib/postgresql/.bashrc && \
8484
/usr/lib/postgresql/bin/psql --no-password --no-psqlrc -d postgres -h localhost -U supabase_admin -c 'SELECT pg_stat_statements_reset(); SELECT pg_stat_reset();'
8585
args:
8686
executable: /bin/bash

common-nix.vars.pkr.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
postgres-version = "15.6.1.71-nix-staged"
1+
postgres-version = "15.6.1.72-nix-staged"

0 commit comments

Comments
 (0)