2 db_synchronous_commit: "off"
3 db_shared_buffers: "256MB"
5 db_default_text_search_config: "pg_catalog.english"
10 db_checkpoint_segments: 6
11 db_logging_collector: off
12 db_log_min_duration_statement: 100
18 filename: /etc/service/unicorn/run
20 to: sv start postgres || exit 1
23 - exec: apt-get remove -y postgresql-9.5 postgresql-client-9.5 postgresql-contrib-9.5
24 - exec: apt-get update && apt-get install -y postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3
25 - exec: /etc/init.d/postgresql stop
26 - exec: mkdir -p /shared/postgres_run
27 - exec: chown postgres:postgres /shared/postgres_run
28 - exec: chmod 775 /shared/postgres_run
29 - exec: rm -fr /var/run/postgresql
30 - exec: ln -s /shared/postgres_run /var/run/postgresql
31 - exec: socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
32 - exec: rm -fr /shared/postgres_run/.s*
33 - exec: rm -fr /shared/postgres_run/*.pid
34 - exec: mkdir -p /shared/postgres_run/9.3-main.pg_stat_tmp
35 - exec: chown postgres:postgres /shared/postgres_run/9.3-main.pg_stat_tmp
37 filename: "/etc/postgresql/9.3/main/postgresql.conf"
41 path: /etc/service/postgres/run
46 echo -1000 >/proc/self/oom_score_adj
47 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
50 path: /etc/runit/3.d/99-postgres
58 - chown -R root /var/lib/postgresql/9.3/main
59 - "[ ! -e /shared/postgres_data ] && install -d -m 0755 -o postgres -g postgres /shared/postgres_data && sudo -E -u postgres /usr/lib/postgresql/9.3/bin/initdb -D /shared/postgres_data || exit 0"
60 - chown -R postgres:postgres /shared/postgres_data
61 - chown -R postgres:postgres /var/run/postgresql
64 filename: "/etc/postgresql/9.3/main/postgresql.conf"
65 from: "data_directory = '/var/lib/postgresql/9.3/main'"
66 to: "data_directory = '/shared/postgres_data'"
68 # listen on all interfaces
70 filename: "/etc/postgresql/9.3/main/postgresql.conf"
71 from: /#?listen_addresses *=.*/
72 to: "listen_addresses = '*'"
74 # sync commit off is faster and less spiky, also marginally less safe
76 filename: "/etc/postgresql/9.3/main/postgresql.conf"
77 from: /#?synchronous_commit *=.*/
78 to: "synchronous_commit = $db_synchronous_commit"
80 # default is 128MB which is way too small
82 filename: "/etc/postgresql/9.3/main/postgresql.conf"
83 from: /#?shared_buffers *=.*/
84 to: "shared_buffers = $db_shared_buffers"
86 # default is 1MB which is too small
88 filename: "/etc/postgresql/9.3/main/postgresql.conf"
89 from: /#?work_mem *=.*/
90 to: "work_mem = $db_work_mem"
94 filename: "/etc/postgresql/9.3/main/postgresql.conf"
95 from: /#?default_text_search_config *=.*/
96 to: "default_text_search_config = '$db_default_text_search_config'"
98 # Necessary to enable backups
101 - install -d -m 0755 -o postgres -g postgres /shared/postgres_backup
104 filename: "/etc/postgresql/9.3/main/postgresql.conf"
105 from: /#?max_wal_senders *=.*/
106 to: "max_wal_senders = $db_max_wal_senders"
109 filename: "/etc/postgresql/9.3/main/postgresql.conf"
110 from: /#?wal_level *=.*/
111 to: "wal_level = $db_wal_level"
114 filename: "/etc/postgresql/9.3/main/postgresql.conf"
115 from: /#?checkpoint_segments *=.*/
116 to: "checkpoint_segments = $db_checkpoint_segments"
119 filename: "/etc/postgresql/9.3/main/postgresql.conf"
120 from: /#?logging_collector *=.*/
121 to: "logging_collector = $db_logging_collector"
124 filename: "/etc/postgresql/9.3/main/postgresql.conf"
125 from: /#?log_min_duration_statement *=.*/
126 to: "log_min_duration_statement = $db_log_min_duration_statement"
129 filename: "/etc/postgresql/9.3/main/pg_hba.conf"
130 from: /^#local +replication +postgres +peer$/
131 to: "local replication postgres peer"
133 # allow all to connect in with md5 auth
135 filename: "/etc/postgresql/9.3/main/pg_hba.conf"
136 from: /^host.*all.*all.*127.*$/
137 to: "host all all 0.0.0.0/0 md5"
141 # use fast shutdown for pg
143 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
145 # give db a few secs to start up
148 - exec: su postgres -c 'createdb $db_name' || true
149 - exec: su postgres -c 'psql $db_name -c "create user $db_user;"' || true
150 - exec: su postgres -c 'psql $db_name -c "grant all privileges on database $db_name to $db_user;"' || true
151 - exec: su postgres -c 'psql $db_name -c "alter schema public owner to $db_user;"'
152 - exec: su postgres -c 'psql template1 -c "create extension if not exists hstore;"'
153 - exec: su postgres -c 'psql template1 -c "create extension if not exists pg_trgm;"'
154 - exec: su postgres -c 'psql $db_name -c "create extension if not exists hstore;"'
155 - exec: su postgres -c 'psql $db_name -c "create extension if not exists pg_trgm;"'
158 update pg_database set encoding = pg_char_to_encoding('UTF8') where datname = '$db_name' AND encoding = pg_char_to_encoding('SQL_ASCII');
159 cmd: sudo -u postgres psql $db_name
163 path: /var/lib/postgresql/take-database-backup
164 chown: postgres:postgres
169 FILENAME=/shared/postgres_backup/$ID.tar.gz
170 pg_basebackup --format=tar --pgdata=- --xlog --gzip --label=$ID > $FILENAME
174 path: /var/spool/cron/crontabs/postgres
176 # m h dom mon dow command
178 #0 */4 * * * /var/lib/postgresql/take-database-backup
182 cmd: "echo postgres installed!"