Created
February 9, 2018 13:21
-
-
Save podstava/a198cf9d2bf181e9a16ac161aa4f4f59 to your computer and use it in GitHub Desktop.
upgrade postgres from 9.5 to 10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# Check if exists postgresql repository | |
if [ ! -f /etc/apt/sources.list.d/pgdg.list ]; then | |
echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list | |
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | \ | |
apt-key add - | |
fi | |
# Check if new postgresql version installed | |
if [ ! "$(dpkg -l postgresql-10 &> /dev/null)" ]; then | |
echo "installing..." | |
apt-get update | |
apt-get -y install postgresql-10 | |
fi | |
# Main cluster usually running on 5432 port | |
cluster_old=$(pg_lsclusters | grep 5432 | awk -F " " '{if ($1) print $1 " " $2}'); | |
cl_ver=$( echo "$cluster_old" | sed 's/[[:space:]].*$//') | |
echo "$cl_ver" | |
# Cluster with new version will be running on 5433 or next free port | |
cluster_new=$(pg_lsclusters | grep 5433 | awk -F " " '{if ($1) print $1 " " $2}') | |
if [ "$cl_ver" != "10" ]; then | |
echo "Upgrading $cluster_old to $cluster_new" | |
pg_dropcluster $cluster_new --stop; | |
/etc/init.d/postgresql restart; | |
pg_upgradecluster -m upgrade $cluster_old; | |
fi | |
stop_clus=$(pg_lsclusters | grep 5433 | awk -F " " '{if ($1) print $1 " " $2}'); | |
pg_dropcluster $stop_clus --stop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment