2 db_synchronous_commit: "off"
3 db_shared_buffers: "256MB"
5 db_default_text_search_config: "pg_catalog.english"
12 filename: /etc/service/unicorn/run
14 to: sv start postgres || exit 1
17 - exec: mkdir -p /shared/postgres_run
18 - exec: chown postgres:postgres /shared/postgres_run
19 - exec: chmod 775 /shared/postgres_run
20 - exec: rm -fr /var/run/postgresql
21 - exec: ln -s /shared/postgres_run /var/run/postgresql
22 - exec: socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
23 - exec: rm -fr /shared/postgres_run/.s*
24 - exec: rm -fr /shared/postgres_run/*.pid
25 - exec: mkdir -p /shared/postgres_run/9.3-main.pg_stat_tmp
26 - exec: chown postgres:postgres /shared/postgres_run/9.3-main.pg_stat_tmp
28 path: /etc/service/postgres/run
33 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
36 path: /etc/runit/3.d/99-postgres
43 path: /root/upgrade_postgres
47 if [ "9.2" = `cat /shared/postgres_data/PG_VERSION` ]; then
48 echo Upgrading PostgreSQL to from version 9.2 to 9.3
49 rm -fr /shared/postgres_data_new
50 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
52 apt-get install -y postgresql-9.2
53 /etc/init.d/postgresql stop
54 rm -fr /shared/postgres_data/postmaster.pid
56 cp /etc/postgresql/9.2/main/*.conf /shared/postgres_data
57 echo >> /shared/postgres_data/postgresql.conf
58 echo "data_directory = '/shared/postgres_data'" >> /shared/postgres_data/postgresql.conf
60 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
62 if [[ "$SUCCESS" == 'false' ]]; then
63 echo -------------------------------------------------------------------------------------
64 echo UPGRADE OF POSTGRES FAILED
66 echo You are going to need to export your data and import into a clean instance:
68 echo Add the line: 'base_image: "samsaffron/discourse:0.1.1"'
69 echo Change: "templates/postgres.template.yml TO templates/postgres.9.2.template.yml"
71 echo Run "./launcher bootstrap" again
73 echo When your instance is running:
74 echo - Go to the admin UI, enable readonly and backup your site
76 echo Then destroy your container "./launcher destroy standalone"
77 echo Undo the base_image and postgres.9.2 template from your container config
78 echo Run: "sudo mv /var/discourse/shared/postgres_data /var/shared/postgres_data_old"
79 echo Run: "./launcher bootstrap"
81 echo "Login to the blank site, and import your backup (remember to set the allow_restore site setting)"
82 echo Restart your container: "./launcher restart"
83 echo -------------------------------------------------------------------------------------
87 mv /shared/postgres_data /shared/postgres_data_old
88 mv /shared/postgres_data_new /shared/postgres_data
90 echo -------------------------------------------------------------------------------------
91 echo UPGRADE OF POSTGRES COMPLETE
93 echo Old 9.2 database is stored at /shared/postgres_data_old
95 echo Please run "./launcher bootstrap" again
96 echo -------------------------------------------------------------------------------------
101 - chown -R root /var/lib/postgresql/9.3/main
102 - "[ ! -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"
103 - chown -R postgres:postgres /shared/postgres_data
104 - chown -R postgres:postgres /var/run/postgresql
106 - exec: /root/upgrade_postgres
107 - exec: rm /root/upgrade_postgres
110 filename: "/etc/postgresql/9.3/main/postgresql.conf"
111 from: "data_directory = '/var/lib/postgresql/9.3/main'"
112 to: "data_directory = '/shared/postgres_data'"
114 # listen on all interfaces
116 filename: "/etc/postgresql/9.3/main/postgresql.conf"
117 from: /#?listen_addresses *=.*/
118 to: "listen_addresses = '*'"
120 # sync commit off is faster and less spiky, also marginally less safe
122 filename: "/etc/postgresql/9.3/main/postgresql.conf"
123 from: /#?synchronous_commit *=.*/
124 to: "synchronous_commit = $db_synchronous_commit"
126 # default is 128MB which is way too small
128 filename: "/etc/postgresql/9.3/main/postgresql.conf"
129 from: /#?shared_buffers *=.*/
130 to: "shared_buffers = $db_shared_buffers"
132 # default is 1MB which is too small
134 filename: "/etc/postgresql/9.3/main/postgresql.conf"
135 from: /#?work_mem *=.*/
136 to: "work_mem = $db_work_mem"
140 filename: "/etc/postgresql/9.3/main/postgresql.conf"
141 from: /#?default_text_search_config *=.*/
142 to: "default_text_search_config = '$db_default_text_search_config'"
144 # Necessary to enable backups
147 - install -d -m 0755 -o postgres -g postgres /shared/postgres_backup
150 filename: "/etc/postgresql/9.3/main/postgresql.conf"
151 from: /#?max_wal_senders *=.*/
152 to: "max_wal_senders = 4"
155 filename: "/etc/postgresql/9.3/main/postgresql.conf"
156 from: /#?wal_level *=.*/
157 to: "wal_level = hot_standby"
160 filename: "/etc/postgresql/9.3/main/pg_hba.conf"
161 from: /^#local +replication +postgres +peer$/
162 to: "local replication postgres peer"
164 # allow all to connect in with md5 auth
166 filename: "/etc/postgresql/9.3/main/pg_hba.conf"
167 from: /^host.*all.*all.*127.*$/
168 to: "host all all 0.0.0.0/0 md5"
172 # use fast shutdown for pg
174 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
176 # give db a few secs to start up
179 - exec: su postgres -c 'createdb $db_name' || true
180 - exec: su postgres -c 'psql $db_name -c "create user $db_user;"' || true
181 - exec: su postgres -c 'psql $db_name -c "grant all privileges on database $db_name to $db_user;"' || true
182 - exec: su postgres -c 'psql $db_name -c "alter schema public owner to $db_user;"'
183 - exec: su postgres -c 'psql template1 -c "create extension if not exists hstore;"'
184 - exec: su postgres -c 'psql template1 -c "create extension if not exists pg_trgm;"'
185 - exec: su postgres -c 'psql $db_name -c "create extension if not exists hstore;"'
186 - exec: su postgres -c 'psql $db_name -c "create extension if not exists pg_trgm;"'
189 update pg_database set encoding = pg_char_to_encoding('UTF8') where datname = '$db_name' AND encoding = pg_char_to_encoding('SQL_ASCII');
190 cmd: sudo -u postgres psql $db_name
194 path: /var/lib/postgresql/take-database-backup
195 chown: postgres:postgres
200 FILENAME=/shared/postgres_backup/$ID.tar.gz
201 pg_basebackup --format=tar --pgdata=- --xlog --gzip --label=$ID > $FILENAME
205 path: /var/spool/cron/crontabs/postgres
207 # m h dom mon dow command
209 #0 */4 * * * /var/lib/postgresql/take-database-backup
213 cmd: "echo postgres installed!"