2 db_synchronous_commit: "off"
3 db_shared_buffers: "256MB"
5 db_default_text_search_config: "pg_catalog.english"
8 db_checkpoint_segments: 6
9 db_logging_collector: off
10 db_log_min_duration_statement: 100
15 filename: /etc/service/unicorn/run
17 to: sv start postgres || exit 1
20 - exec: apt-get remove -y postgresql-10 postgresql-client-10 postgresql-contrib-10
21 - exec: apt-get update && apt-get install -y postgresql-9.5 postgresql-client-9.5 postgresql-contrib-9.5
22 - exec: mkdir -p /shared/postgres_run
23 - exec: chown postgres:postgres /shared/postgres_run
24 - exec: chmod 775 /shared/postgres_run
25 - exec: rm -fr /var/run/postgresql
26 - exec: ln -s /shared/postgres_run /var/run/postgresql
27 - exec: socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
28 - exec: rm -fr /shared/postgres_run/.s*
29 - exec: rm -fr /shared/postgres_run/*.pid
30 - exec: mkdir -p /shared/postgres_run/9.5-main.pg_stat_tmp
31 - exec: chown postgres:postgres /shared/postgres_run/9.5-main.pg_stat_tmp
33 path: /etc/service/postgres/run
38 echo -1000 >/proc/self/oom_score_adj
39 HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/9.5/bin/postmaster -D /etc/postgresql/9.5/main
42 path: /etc/runit/3.d/99-postgres
50 - chown -R root /var/lib/postgresql/9.5/main
51 - "[ ! -e /shared/postgres_data ] && install -d -m 0755 -o postgres -g postgres /shared/postgres_data && sudo -E -u postgres /usr/lib/postgresql/9.5/bin/initdb -D /shared/postgres_data || exit 0"
52 - chown -R postgres:postgres /shared/postgres_data
53 - chown -R postgres:postgres /var/run/postgresql
56 filename: "/etc/postgresql/9.5/main/postgresql.conf"
57 from: "data_directory = '/var/lib/postgresql/9.5/main'"
58 to: "data_directory = '/shared/postgres_data'"
60 # listen on all interfaces
62 filename: "/etc/postgresql/9.5/main/postgresql.conf"
63 from: /#?listen_addresses *=.*/
64 to: "listen_addresses = '*'"
66 # sync commit off is faster and less spiky, also marginally less safe
68 filename: "/etc/postgresql/9.5/main/postgresql.conf"
69 from: /#?synchronous_commit *=.*/
70 to: "synchronous_commit = $db_synchronous_commit"
72 # default is 128MB which is way too small
74 filename: "/etc/postgresql/9.5/main/postgresql.conf"
75 from: /#?shared_buffers *=.*/
76 to: "shared_buffers = $db_shared_buffers"
78 # default is 1MB which is too small
80 filename: "/etc/postgresql/9.5/main/postgresql.conf"
81 from: /#?work_mem *=.*/
82 to: "work_mem = $db_work_mem"
86 filename: "/etc/postgresql/9.5/main/postgresql.conf"
87 from: /#?default_text_search_config *=.*/
88 to: "default_text_search_config = '$db_default_text_search_config'"
90 # Necessary to enable backups
93 - install -d -m 0755 -o postgres -g postgres /shared/postgres_backup
96 filename: "/etc/postgresql/9.5/main/postgresql.conf"
97 from: /#?checkpoint_segments *=.*/
98 to: "checkpoint_segments = $db_checkpoint_segments"
101 filename: "/etc/postgresql/9.5/main/postgresql.conf"
102 from: /#?logging_collector *=.*/
103 to: "logging_collector = $db_logging_collector"
106 filename: "/etc/postgresql/9.5/main/postgresql.conf"
107 from: /#?log_min_duration_statement *=.*/
108 to: "log_min_duration_statement = $db_log_min_duration_statement"
111 filename: "/etc/postgresql/9.5/main/pg_hba.conf"
112 from: /^#local +replication +postgres +peer$/
113 to: "local replication postgres peer"
115 # allow all to connect in with md5 auth
117 filename: "/etc/postgresql/9.5/main/pg_hba.conf"
118 from: /^host.*all.*all.*127.*$/
119 to: "host all all 0.0.0.0/0 md5"
123 # use fast shutdown for pg
125 cmd: HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/9.5/bin/postmaster -D /etc/postgresql/9.5/main
127 # give db a few secs to start up
130 - exec: su postgres -c 'createdb $db_name' || true
131 - exec: su postgres -c 'psql $db_name -c "create user $db_user;"' || true
132 - exec: su postgres -c 'psql $db_name -c "grant all privileges on database $db_name to $db_user;"' || true
133 - exec: su postgres -c 'psql $db_name -c "alter schema public owner to $db_user;"'
134 - exec: su postgres -c 'psql template1 -c "create extension if not exists hstore;"'
135 - exec: su postgres -c 'psql template1 -c "create extension if not exists pg_trgm;"'
136 - exec: su postgres -c 'psql $db_name -c "create extension if not exists hstore;"'
137 - exec: su postgres -c 'psql $db_name -c "create extension if not exists pg_trgm;"'
140 update pg_database set encoding = pg_char_to_encoding('UTF8') where datname = '$db_name' AND encoding = pg_char_to_encoding('SQL_ASCII');
141 cmd: sudo -u postgres psql $db_name
145 path: /var/lib/postgresql/take-database-backup
146 chown: postgres:postgres
151 FILENAME=/shared/postgres_backup/$ID.tar.gz
152 pg_basebackup --format=tar --pgdata=- --xlog --gzip --label=$ID > $FILENAME
156 path: /var/spool/cron/crontabs/postgres
158 # m h dom mon dow command
160 #0 */4 * * * /var/lib/postgresql/take-database-backup
164 cmd: "echo postgres installed!"