force latest tag
[discourse_docker.git] / image / discourse_dev / postgres.template.yml
1 params:
2 db_synchronous_commit: "off"
3 db_shared_buffers: "512MB"
4 db_work_mem: "20MB"
5 db_default_text_search_config: "pg_catalog.english"
6 db_user: discourse
7 db_wal_level: minimal
8 db_max_wal_senders: 0
9 db_checkpoint_segments: 6
10 db_logging_collector: off
11 db_log_min_duration_statement: 100
12
13 hooks:
14 before_code:
15 - replace:
16 filename: /etc/service/unicorn/run
17 from: "# postgres"
18 to: sv start postgres || exit 1
19
20 env:
21 LANG: en_US.UTF-8
22
23 run:
24 - exec: mkdir -p /shared/postgres_run
25 - exec: chown postgres:postgres /shared/postgres_run
26 - exec: chmod 775 /shared/postgres_run
27 - exec: rm -fr /var/run/postgresql
28 - exec: ln -s /shared/postgres_run /var/run/postgresql
29 - exec: rm -fr /shared/postgres_run/.s*
30 - exec: rm -fr /shared/postgres_run/*.pid
31 - exec: mkdir -p /shared/postgres_run/9.3-main.pg_stat_tmp
32 - exec: chown postgres:postgres /shared/postgres_run/9.3-main.pg_stat_tmp
33 - file:
34 path: /etc/service/postgres/run
35 chmod: "+x"
36 contents: |
37 #!/bin/sh
38 exec 2>&1
39 HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/9.3/bin/postmaster -D /etc/postgresql/9.3/main
40
41 - file:
42 path: /etc/runit/3.d/99-postgres
43 chmod: "+x"
44 contents: |
45 #!/bin/bash
46 sv stop postgres
47
48 - exec:
49 cmd:
50 - chown -R root /var/lib/postgresql/9.3/main
51 - "[ ! -e /shared/postgres_data ] && install -d -m 0755 -o postgres -g postgres /shared/postgres_data && sudo -E -u postgres LANG=en_US.UTF-8 /usr/lib/postgresql/9.3/bin/initdb --locale=C -E UTF-8 -D /shared/postgres_data || exit 0"
52 - chown -R postgres:postgres /shared/postgres_data
53 - chown -R postgres:postgres /var/run/postgresql
54
55 - replace:
56 filename: "/etc/postgresql/9.3/main/postgresql.conf"
57 from: "data_directory = '/var/lib/postgresql/9.3/main'"
58 to: "data_directory = '/shared/postgres_data'"
59
60 # listen on all interfaces
61 - replace:
62 filename: "/etc/postgresql/9.3/main/postgresql.conf"
63 from: /#?listen_addresses *=.*/
64 to: "listen_addresses = '*'"
65
66 # sync commit off is faster and less spiky, also marginally less safe
67 - replace:
68 filename: "/etc/postgresql/9.3/main/postgresql.conf"
69 from: /#?synchronous_commit *=.*/
70 to: "synchronous_commit = $db_synchronous_commit"
71
72 # default is 128MB which is way too small
73 - replace:
74 filename: "/etc/postgresql/9.3/main/postgresql.conf"
75 from: /#?shared_buffers *=.*/
76 to: "shared_buffers = $db_shared_buffers"
77
78 # default is 1MB which is too small
79 - replace:
80 filename: "/etc/postgresql/9.3/main/postgresql.conf"
81 from: /#?work_mem *=.*/
82 to: "work_mem = $db_work_mem"
83
84 # allow for other
85 - replace:
86 filename: "/etc/postgresql/9.3/main/postgresql.conf"
87 from: /#?default_text_search_config *=.*/
88 to: "default_text_search_config = '$db_default_text_search_config'"
89
90 # Necessary to enable backups
91 - exec:
92 cmd:
93 - install -d -m 0755 -o postgres -g postgres /shared/postgres_backup
94
95 - replace:
96 filename: "/etc/postgresql/9.3/main/postgresql.conf"
97 from: /#?max_wal_senders *=.*/
98 to: "max_wal_senders = $db_max_wal_senders"
99
100 - replace:
101 filename: "/etc/postgresql/9.3/main/postgresql.conf"
102 from: /#?wal_level *=.*/
103 to: "wal_level = $db_wal_level"
104
105 - replace:
106 filename: "/etc/postgresql/9.3/main/postgresql.conf"
107 from: /#?checkpoint_segments *=.*/
108 to: "checkpoint_segments = $db_checkpoint_segments"
109
110 - replace:
111 filename: "/etc/postgresql/9.3/main/postgresql.conf"
112 from: /#?logging_collector *=.*/
113 to: "logging_collector = $db_logging_collector"
114
115 - replace:
116 filename: "/etc/postgresql/9.3/main/postgresql.conf"
117 from: /#?log_min_duration_statement *=.*/
118 to: "log_min_duration_statement = $db_log_min_duration_statement"
119
120 - replace:
121 filename: "/etc/postgresql/9.3/main/pg_hba.conf"
122 from: /^#local +replication +postgres +peer$/
123 to: "local replication postgres peer"
124
125 # allow all to connect in with md5 auth
126 - replace:
127 filename: "/etc/postgresql/9.3/main/pg_hba.conf"
128 from: /^host.*all.*all.*127.*$/
129 to: "host all all 0.0.0.0/0 md5"
130
131 - exec:
132 background: true
133 # use fast shutdown for pg
134 stop_signal: INT
135 cmd: HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/9.3/bin/postmaster -D /etc/postgresql/9.3/main
136
137 # give db a few secs to start up
138 - exec: "sleep 5"
139
140 - exec: sudo -E -u postgres LANG=en_US.UTF-8 createdb discourse_development
141 - exec: sudo -E -u postgres LANG=en_US.UTF-8 createdb discourse_test
142 - exec: su postgres -c 'psql -c "create user $db_user with superuser"'
143
144 - exec:
145 background: true
146 cmd: exec chpst -u redis -U redis /usr/bin/redis-server /etc/redis/redis.conf
147
148 - exec: cd /var/www/discourse && sudo -u discourse rake db:migrate
149 - exec: cd /var/www/discourse && sudo -u discourse RAILS_ENV=test rake db:migrate
150 - exec:
151 hook: postgres
152 cmd: "echo postgres installed!"