Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Arch Linux
infrastructure
Commits
af1bff90
Commit
af1bff90
authored
Nov 21, 2018
by
Jelle van der Waa
🚧
Browse files
postgres: add upgrade postgres script
parent
65cca332
Changes
2
Hide whitespace changes
Inline
Side-by-side
roles/postgres/files/upgrade_pg.sh
0 → 100755
View file @
af1bff90
#!/bin/bash
set
-e
## Set the old version that we want to upgrade from.
TO_VERSION
=
$(
pacman
-Q
postgresql |
grep
-Po
'(?<=postgresql )[0-9]+\.[0-9]'
)
to_major
=
$(
echo
"
$TO_VERSION
"
|
awk
-F
'.'
'{print $1}'
)
to_minor
=
$(
echo
"
$TO_VERSION
"
|
awk
-F
'.'
'{print $2}'
)
if
[[
${
to_major
}
-ne
11
]]
;
then
echo
"WARNING: major upgrade detected, aborting..."
exit
1
fi
export
FROM_VERSION
=
"
$(
cat
/var/lib/postgres/data/PG_VERSION
)
"
# free space check
used_space
=
$(
df
--local
--output
=
pcent /var/lib/postgres/ |
grep
-Po
'[0-9]{1,3}(?=%)'
)
if
[[
${
used_space
}
-ge
50
]]
;
then
echo
"ERROR: not enough free space for upgrade with backup, aborting..."
exit
2
fi
pacman
-S
--needed
postgresql-old-upgrade
chown
postgres:postgres /var/lib/postgres/
if
[[
-d
"/var/lib/postgres/data-
${
FROM_VERSION
}
"
]]
;
then
echo
"ERROR: backup data-
${
FROM_VERSION
}
directory already exists, aborting..."
exit
3
fi
su - postgres
-c
"mv /var/lib/postgres/data /var/lib/postgres/data-
${
FROM_VERSION
}
"
su - postgres
-c
'mkdir /var/lib/postgres/data'
su - postgres
-c
"initdb --locale
$LANG
-E UTF8 -D /var/lib/postgres/data"
vimdiff
"/var/lib/postgres/data/pg_hba.conf"
"/var/lib/postgres/data-
${
FROM_VERSION
}
/pg_hba.conf"
vimdiff
"/var/lib/postgres/data/postgresql.conf"
"/var/lib/postgres/data-
${
FROM_VERSION
}
/postgresql.conf"
#cp -avx "/var/lib/postgres/data-${FROM_VERSION}/server.crt" "/var/lib/postgres/data/server.crt"
#cp -avx "/var/lib/postgres/data-${FROM_VERSION}/server.key" "/var/lib/postgres/data/server.key"
systemctl stop postgresql.service
su - postgres
-c
"pg_upgrade -b /opt/pgsql-
${
FROM_VERSION
}
/bin/ -B /usr/bin/ -d /var/lib/postgres/data-
${
FROM_VERSION
}
-D /var/lib/postgres/data"
systemctl daemon-reload
systemctl start postgresql.service
su - postgres
-c
'/var/lib/postgres/analyze_new_cluster.sh'
su - postgres
-c
'/var/lib/postgres/delete_old_cluster.sh'
roles/postgres/tasks/main.yml
View file @
af1bff90
...
...
@@ -65,3 +65,6 @@
when
:
configure_firewall
tags
:
-
firewall
-
name
:
copy postgresql upgrade script
copy
:
src=upgrade_pg.sh dest=/usr/local/bin/upgrade_pg.sh mode=0755 owner=root group=root
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment