InstallationGuidelines/Linux/Server/CherokeePostgreSQL: upgrade-postgis-1.sh

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