2 db_synchronous_commit: "off"
3 db_shared_buffers: "256MB"
5 db_default_text_search_config: "pg_catalog.english"
10 filename: /etc/service/unicorn/run
12 to: sv start postgres || exit 1
15 - exec: mkdir -p /shared/postgres_run
16 - exec: chown postgres:postgres /shared/postgres_run
17 - exec: chmod 775 /shared/postgres_run
18 - exec: rm -fr /var/run/postgresql
19 - exec: ln -s /shared/postgres_run /var/run/postgresql
20 - exec: socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
21 - exec: rm -fr /shared/postgres_run/.s*
22 - exec: rm -fr /shared/postgres_run/*.pid
24 path: /etc/service/postgres/run
29 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
32 path: /etc/runit/3.d/99-postgres
39 path: /root/upgrade_postgres
43 if [ "9.2" = `cat /shared/postgres_data/PG_VERSION` ]; then
44 echo Upgrading PostgreSQL to from version 9.2 to 9.3
45 rm -fr /shared/postgres_data_new
46 install -d -m 0755 -o postgres -g postgres /shared/postgres_data_new && sudo -u postgres /usr/lib/postgresql/9.3/bin/initdb -D /shared/postgres_data_new || exit 0
48 apt-get install -y postgresql-9.2
49 /etc/init.d/postgresql stop
50 rm -fr /shared/postgres_data/postmaster.pid
52 cp /etc/postgresql/9.2/main/*.conf /shared/postgres_data
53 echo >> /shared/postgres_data/postgresql.conf
54 echo "data_directory = '/shared/postgres_data'" >> /shared/postgres_data/postgresql.conf
56 sudo -u postgres /usr/lib/postgresql/9.3/bin/pg_upgrade -d /shared/postgres_data -D /shared/postgres_data_new -b /usr/lib/postgresql/9.2/bin -B /usr/lib/postgresql/9.3/bin || SUCCESS=false
58 if [[ "$SUCCESS" == 'false' ]]; then
59 echo -------------------------------------------------------------------------------------
60 echo UPGRADE OF POSTGRES FAILED
62 echo You are going to need to export your data and import into a clean instance:
64 echo Add the line: 'base_image: "samsaffron/discourse:0.1.1"'
65 echo Change: "templates/postgres.template.yml TO templates/postgres.9.2.template.yml"
67 echo Run "./launcher bootstrap" again
69 echo When your instance is running:
70 echo - Go to the admin UI, enable readonly and backup your site
72 echo Then destroy your container "./launcher destroy standalone"
73 echo Undo the base_image and postgres.9.2 template from your container config
74 echo Run: "sudo mv /var/discourse/shared/postgres_data /var/shared/postgres_data_old"
75 echo Run: "./launcher bootstrap"
77 echo "Login to the blank site, and import your backup (remember to set the allow_restore site setting)"
78 echo Restart your container: "./launcher restart"
79 echo -------------------------------------------------------------------------------------
83 mv /shared/postgres_data /shared/postgres_data_old
84 mv /shared/postgres_data_new /shared/postgres_data
86 echo -------------------------------------------------------------------------------------
87 echo UPGRADE OF POSTGRES COMPLETE
89 echo Old 9.2 database is stored at /shared/postgres_data_old
91 echo Please run "./launcher bootstrap" again
92 echo -------------------------------------------------------------------------------------
97 - chown -R root /var/lib/postgresql/9.3/main
98 - "[ ! -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"
99 - chown -R postgres:postgres /shared/postgres_data
100 - chown -R postgres:postgres /var/run/postgresql
102 - exec: /root/upgrade_postgres
103 - exec: rm /root/upgrade_postgres
106 filename: "/etc/postgresql/9.3/main/postgresql.conf"
107 from: "data_directory = '/var/lib/postgresql/9.3/main'"
108 to: "data_directory = '/shared/postgres_data'"
110 # listen on all interfaces
112 filename: "/etc/postgresql/9.3/main/postgresql.conf"
113 from: /#?listen_addresses *=.*/
114 to: "listen_addresses = '*'"
116 # sync commit off is faster and less spiky, also marginally less safe
118 filename: "/etc/postgresql/9.3/main/postgresql.conf"
119 from: /#?synchronous_commit *=.*/
120 to: "synchronous_commit = $db_synchronous_commit"
122 # default is 128MB which is way too small
124 filename: "/etc/postgresql/9.3/main/postgresql.conf"
125 from: /#?shared_buffers *=.*/
126 to: "shared_buffers = $db_shared_buffers"
128 # default is 1MB which is too small
130 filename: "/etc/postgresql/9.3/main/postgresql.conf"
131 from: /#?work_mem *=.*/
132 to: "work_mem = $db_work_mem"
136 filename: "/etc/postgresql/9.3/main/postgresql.conf"
137 from: /#?default_text_search_config *=.*/
138 to: "default_text_search_config = '$db_default_text_search_config'"
140 # Necessary to enable backups
143 - install -d -m 0755 -o postgres -g postgres /shared/postgres_backup
146 filename: "/etc/postgresql/9.3/main/postgresql.conf"
147 from: /#?max_wal_senders *=.*/
148 to: "max_wal_senders = 4"
151 filename: "/etc/postgresql/9.3/main/postgresql.conf"
152 from: /#?wal_level *=.*/
153 to: "wal_level = hot_standby"
156 filename: "/etc/postgresql/9.3/main/pg_hba.conf"
157 from: /^#local +replication +postgres +peer$/
158 to: "local replication postgres peer"
160 # allow all to connect in with md5 auth
162 filename: "/etc/postgresql/9.3/main/pg_hba.conf"
163 from: /^host.*all.*all.*127.*$/
164 to: "host all all 0.0.0.0/0 md5"
168 # use fast shutdown for pg
170 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
172 # give db a few secs to start up
175 - exec: su postgres -c 'createdb discourse' || true
176 - exec: su postgres -c 'psql discourse -c "create user discourse;"' || true
177 - exec: su postgres -c 'psql discourse -c "grant all privileges on database discourse to discourse;"' || true
178 - exec: su postgres -c 'psql discourse -c "alter schema public owner to discourse;"'
179 - exec: su postgres -c 'psql template1 -c "create extension if not exists hstore;"'
180 - exec: su postgres -c 'psql template1 -c "create extension if not exists pg_trgm;"'
181 - exec: su postgres -c 'psql discourse -c "create extension if not exists hstore;"'
182 - exec: su postgres -c 'psql discourse -c "create extension if not exists pg_trgm;"'
185 path: /var/lib/postgresql/take-database-backup
186 chown: postgres:postgres
191 FILENAME=/shared/postgres_backup/$ID.tar.gz
192 pg_basebackup --format=tar --pgdata=- --xlog --gzip --label=$ID > $FILENAME
196 path: /var/spool/cron/crontabs/postgres
198 # m h dom mon dow command
200 #0 */4 * * * /var/lib/postgresql/take-database-backup
204 cmd: "echo postgres installed!"