-
-
Notifications
You must be signed in to change notification settings - Fork 174
/
Copy pathstage2-setup-postgres.yml
273 lines (235 loc) · 9.83 KB
/
stage2-setup-postgres.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# - name: Install openjdk11 for pljava from nix binary cache
# become: yes
# shell: |
# sudo -u postgres bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install nixpkgs#openjdk11"
# It was decided to leave pljava disabled at https://github.com/supabase/postgres/pull/690 therefore removing this task
- name: Check psql_version and modify supautils.conf and postgresql.conf if necessary
block:
- name: Check if psql_version is psql_orioledb-17
set_fact:
is_psql_oriole: "{{ psql_version in ['psql_orioledb-17'] }}"
- name: Check if psql_version is psql_17
set_fact:
is_psql_17: "{{ psql_version in ['psql_17'] }}"
- name: Remove specified extensions from postgresql.conf if orioledb-17 or 17 build
ansible.builtin.command:
cmd: >
sed -i 's/ timescaledb,//g'
/etc/postgresql/postgresql.conf
when: is_psql_oriole or is_psql_17 and stage2_nix
become: yes
- name: Remove specified extensions from supautils.conf if orioledb-17 or 17 build
ansible.builtin.command:
cmd: >
sed -i 's/ timescaledb,//g; s/ plv8,//g; s/ pgjwt,//g'
/etc/postgresql-custom/supautils.conf
when: is_psql_oriole or is_psql_17 and stage2_nix
become: yes
- name: Remove db_user_namespace from postgresql.conf if orioledb-17 or 17 build
ansible.builtin.command:
cmd: >
sed -i 's/db_user_namespace = off/#db_user_namespace = off/g;'
/etc/postgresql/postgresql.conf
when: is_psql_oriole or is_psql_17 and stage2_nix
become: yes
- name: Append orioledb to shared_preload_libraries append within closing quote
ansible.builtin.command:
cmd: >
sed -i 's/\(shared_preload_libraries.*\)'\''\(.*\)$/\1, orioledb'\''\2/'
/etc/postgresql/postgresql.conf
when: is_psql_oriole and stage2_nix
become: yes
- name: Add default_table_access_method setting
ansible.builtin.lineinfile:
path: /etc/postgresql/postgresql.conf
line: "default_table_access_method = 'orioledb'"
state: present
when: is_psql_oriole and stage2_nix
become: yes
- name: Add ORIOLEDB_ENABLED environment variable
ansible.builtin.lineinfile:
path: /etc/environment
line: 'ORIOLEDB_ENABLED=true'
when: is_psql_oriole and stage2_nix
become: yes
- name: Install Postgres from nix binary cache
become: yes
shell: |
sudo -u postgres bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/{{ git_commit_sha }}#{{psql_version}}/bin"
when: stage2_nix
- name: Install pg_prove from nix binary cache
become: yes
shell: |
sudo -u postgres bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/{{ git_commit_sha }}#pg_prove"
when: stage2_nix
- name: Install supabase-groonga from nix binary cache
become: yes
shell: |
sudo -u postgres bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/{{ git_commit_sha }}#supabase-groonga"
when: stage2_nix
- name: Install debug symbols for postgres version
become: yes
shell: |
sudo -u postgres bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/{{ git_commit_sha }}#{{postgresql_version}}_debug"
when: stage2_nix
- name: Install source files for postgresql version
become: yes
shell: |
sudo -u postgres bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/{{ git_commit_sha }}#{{postgresql_version}}_src"
when: stage2_nix
- name: Install jq from nix binary cache
become: yes
shell: |
sudo -u postgres bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install nixpkgs#jq"
when: stage2_nix
- name: Set ownership and permissions for /etc/ssl/private
become: yes
file:
path: /etc/ssl/private
owner: root
group: postgres
mode: '0750'
when: stage2_nix
- name: Set permissions for postgresql.env
become: yes
file:
path: /etc/environment.d/postgresql.env
owner: postgres
group: postgres
mode: '0644'
when: stage2_nix
- name: Ensure /usr/lib/postgresql/bin directory exists
file:
path: /usr/lib/postgresql/bin
state: directory
owner: postgres
group: postgres
when: stage2_nix
- name: Ensure /usr/lib/postgresql/share directory exists
file:
path: /usr/lib/postgresql/share/postgresql
state: directory
owner: postgres
group: postgres
when: stage2_nix
- name: Ensure /usr/lib/postgresql/share/contrib directory exists
file:
path: /usr/lib/postgresql/share/postgresql/contrib
state: directory
owner: postgres
group: postgres
when: stage2_nix
- name: Ensure /usr/lib/postgresql/share/timezonesets directory exists
file:
path: /usr/lib/postgresql/share/postgresql/timezonesets
state: directory
owner: postgres
group: postgres
when: stage2_nix
- name: Ensure /usr/lib/postgresql/share/tsearch_data directory exists
file:
path: /usr/lib/postgresql/share/postgresql/tsearch_data
state: directory
owner: postgres
group: postgres
when: stage2_nix
- name: Ensure /usr/lib/postgresql/share/extension directory exists
file:
path: /usr/lib/postgresql/share/postgresql/extension
state: directory
owner: postgres
group: postgres
when: stage2_nix
- name: import pgsodium_getkey script
template:
src: files/pgsodium_getkey_readonly.sh.j2
dest: "/usr/lib/postgresql/bin/pgsodium_getkey.sh"
owner: postgres
group: postgres
mode: 0700
when: stage2_nix
- name: Create symbolic links from /var/lib/postgresql/.nix-profile/bin to /usr/lib/postgresql/bin
shell: >-
find /var/lib/postgresql/.nix-profile/bin/ -maxdepth 1 -type f,l -exec sh -c 'ln -s "$0" "{{ item }}/$(basename $0)"' {} \;
loop:
- /usr/lib/postgresql/bin
- /usr/bin
become: yes
when: stage2_nix
- name: Check if /usr/bin/pg_config exists
stat:
path: /usr/bin/pg_config
register: pg_config_stat
when: stage2_nix
- name: Remove existing /usr/bin/pg_config if it is not a symlink
file:
path: /usr/bin/pg_config
state: absent
when: pg_config_stat.stat.exists and not pg_config_stat.stat.islnk and stage2_nix
become: yes
- name: Ensure postgres user has ownership of symlink
shell: >-
find /var/lib/postgresql/.nix-profile/bin/ -maxdepth 1 -type f,l -exec chown postgres:postgres "/usr/bin/$(basename {})" \;
become: yes
when: stage2_nix
- name: Create symbolic links from /var/lib/postgresql/.nix-profile/share/postgresql to /usr/lib/postgresql/share/postgresql
shell: >-
find /var/lib/postgresql/.nix-profile/share/postgresql/ -maxdepth 1 -type f,l -exec sh -c 'ln -s "$0" "/usr/lib/postgresql/share/postgresql/$(basename $0)"' {} \;
become: yes
when: stage2_nix
- name: Create symbolic links from /var/lib/postgresql/.nix-profile/share/postgresql/extension to /usr/lib/postgresql/share/postgresql/extension
shell: >-
find /var/lib/postgresql/.nix-profile/share/postgresql/extension/ -maxdepth 1 -type f,l -exec sh -c 'ln -s "$0" "/usr/lib/postgresql/share/postgresql/extension/$(basename $0)"' {} \;
become: yes
when: stage2_nix
- name: create destination directory
file:
path: /usr/lib/postgresql/share/postgresql/contrib/
state: directory
recurse: yes
when: stage2_nix
- name: Check psql_version and run postgis linking if not oriole-xx
block:
- name: Check if psql_version is psql_orioledb-17
set_fact:
is_psql_oriole: "{{ psql_version == 'psql_orioledb-17' }}"
- name: Recursively create symbolic links and set permissions for the contrib/postgis-* dir
shell: >
sudo mkdir -p /usr/lib/postgresql/share/postgresql/contrib && \
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 {} + \
&& chown -R postgres:postgres "/usr/lib/postgresql/share/postgresql/contrib/"
become: yes
when: stage2_nix and not is_psql_oriole
- name: Create symbolic links from /var/lib/postgresql/.nix-profile/share/postgresql/timezonesets to /usr/lib/postgresql/share/postgresql/timeszonesets
shell: >-
find /var/lib/postgresql/.nix-profile/share/postgresql/timezonesets/ -maxdepth 1 -type f,l -exec sh -c 'ln -s "$0" "/usr/lib/postgresql/share/postgresql/timezonesets/$(basename $0)"' {} \;
become: yes
when: stage2_nix
- name: Create symbolic links from /var/lib/postgresql/.nix-profile/share/postgresql/tsearch_data to /usr/lib/postgresql/share/postgresql/tsearch_data
shell: >-
find /var/lib/postgresql/.nix-profile/share/postgresql/tsearch_data/ -maxdepth 1 -type f,l -exec sh -c 'ln -s "$0" "/usr/lib/postgresql/share/postgresql/tsearch_data/$(basename $0)"' {} \;
become: yes
when: stage2_nix
- set_fact:
pg_bindir: "/usr/lib/postgresql/bin"
when: stage2_nix
- name: pgsodium - set pgsodium.getkey_script
become: yes
lineinfile:
path: /etc/postgresql/postgresql.conf
state: present
# script is expected to be placed by finalization tasks for different target platforms
line: pgsodium.getkey_script= '{{ pg_bindir }}/pgsodium_getkey.sh'
when: stage2_nix
- name: Create symbolic link for pgsodium_getkey script
file:
src: "/usr/lib/postgresql/bin/pgsodium_getkey.sh"
dest: "/usr/lib/postgresql/share/postgresql/extension/pgsodium_getkey"
state: link
become: yes
when: stage2_nix
- name: Append GRN_PLUGINS_DIR to /etc/environment.d/postgresql.env
ansible.builtin.lineinfile:
path: /etc/environment.d/postgresql.env
line: 'GRN_PLUGINS_DIR=/var/lib/postgresql/.nix-profile/lib/groonga/plugins'
become: yes