1 | #!/bin/sh
|
---|
2 |
|
---|
3 | # Script to upgrade PostgreSQL & PostGIS on a default Debian Wheezy
|
---|
4 | # - part 1
|
---|
5 |
|
---|
6 | # Update system
|
---|
7 | apt-get update
|
---|
8 | apt-get upgrade -y
|
---|
9 | apt-get clean
|
---|
10 |
|
---|
11 | # Backup
|
---|
12 | su postgres
|
---|
13 | pg_dump -Fc gis > gis.dump
|
---|
14 | pg_dump -Fc sahana > sahana.dump
|
---|
15 | exit
|
---|
16 |
|
---|
17 | # Upgrade PostgreSQL
|
---|
18 | apt-get -y install python-software-properties
|
---|
19 | wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
|
---|
20 | add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ wheezy-pgdg main"
|
---|
21 | apt-get update
|
---|
22 | apt-get install postgresql-9.3 postgresql-client-9.3 postgresql-server-dev-9.3
|
---|
23 | /etc/init.d/uwsgi stop
|
---|
24 | /etc/init.d/uwsgi-prod stop
|
---|
25 | /etc/init.d/uwsgi-demo stop
|
---|
26 | /etc/init.d/uwsgi-test stop
|
---|
27 | su postgres
|
---|
28 | pg_dropcluster --stop 9.3 main
|
---|
29 | pg_upgradecluster 9.1 main
|
---|
30 |
|
---|
31 | # Upgrade PostGIS
|
---|
32 | apt-get install -y postgresql-9.3-postgis
|
---|
33 |
|
---|
34 | # Hard-upgrade Data
|
---|
35 | cd ..
|
---|
36 | su postgres
|
---|
37 | dropdb gis
|
---|
38 | dropdb sahana
|
---|
39 | createdb -O gis -E UTF8 gis -T template0
|
---|
40 | createdb -O sahana -E UTF8 sahana -T template0
|
---|
41 | su -c - postgres "psql -q -d sahana -f /usr/share/postgresql/9.3/extension/postgis--2.1.1.sql"
|
---|
42 | su -c - postgres "psql -q -d sahana -c 'grant all on geometry_columns to sahana;'"
|
---|
43 | su -c - postgres "psql -q -d sahana -c 'grant all on spatial_ref_sys to sahana;'"
|
---|
44 | perl /usr/share/postgresql/9.3/contrib/postgis-2.1/postgis_restore.pl gis.dump | psql gis
|
---|
45 | perl /usr/share/postgresql/9.3/contrib/postgis-2.1/postgis_restore.pl sahana.dump | psql sahana
|
---|
46 |
|
---|
47 | # Upgrade management scripts
|
---|
48 | sed -i 's/9.1/9.3/g' /usr/local/bin/clean
|
---|
49 | sed -i 's/1.5/2.1/g' /usr/local/bin/clean
|
---|
50 |
|
---|
51 | cat << EOF > "/usr/local/bin/pg1024"
|
---|
52 | #!/bin/sh
|
---|
53 | sed -i 's|kernel.shmmax = 279134208|#kernel.shmmax = 279134208|' /etc/sysctl.conf
|
---|
54 | sed -i 's|#kernel.shmmax = 552992768|kernel.shmmax = 552992768|' /etc/sysctl.conf
|
---|
55 | sysctl -w kernel.shmmax=552992768
|
---|
56 | sed -i 's|shared_buffers = 56MB|shared_buffers = 160MB|' /etc/postgresql/9.3/main/postgresql.conf
|
---|
57 | sed -i 's|effective_cache_size = 256MB|effective_cache_size = 512MB|' /etc/postgresql/9.3/main/postgresql.conf
|
---|
58 | sed -i 's|work_mem = 2MB|work_mem = 4MB|' /etc/postgresql/9.3/main/postgresql.conf
|
---|
59 | /etc/init.d/postgresql restart
|
---|
60 | EOF
|
---|
61 | chmod +x /usr/local/bin/pg1024
|
---|
62 |
|
---|
63 | cat << EOF > "/usr/local/bin/pg512"
|
---|
64 | #!/bin/sh
|
---|
65 | sed -i 's|#kernel.shmmax = 279134208|kernel.shmmax = 279134208|' /etc/sysctl.conf
|
---|
66 | sed -i 's|kernel.shmmax = 552992768|#kernel.shmmax = 552992768|' /etc/sysctl.conf
|
---|
67 | sysctl -w kernel.shmmax=279134208
|
---|
68 | sed -i 's|shared_buffers = 160MB|shared_buffers = 56MB|' /etc/postgresql/9.3/main/postgresql.conf
|
---|
69 | sed -i 's|effective_cache_size = 512MB|effective_cache_size = 256MB|' /etc/postgresql/9.3/main/postgresql.conf
|
---|
70 | sed -i 's|work_mem = 4MB|work_mem = 2MB|' /etc/postgresql/9.3/main/postgresql.conf
|
---|
71 | /etc/init.d/postgresql restart
|
---|
72 | EOF
|
---|
73 | chmod +x /usr/local/bin/pg512
|
---|
74 |
|
---|
75 | echo 'Test after reboot - and then run part2'
|
---|
76 |
|
---|
77 | # END
|
---|