نسخه ۹.۶ دیتابیس postgresql ویژگی های مفیدی داره که احتمالا مورد نیازتون باشه. آپگرید نسخه ۹.۲ به ۹.۶ کار پیچیده ایی نیست به شرطی که به درستی و طبق مراحل زیر پیش برید:
#0 : قبل از نصب
ابتدا چک کنید ورژن postgresql دقیقا چی هستش الان. با دستور زیر
psql --version
با یوزر postgres که به کل دیتابیس ها دسترسی داره لاگین کنید و یه بک آپ کامل از کل دیتای فعلی بگیرید و به یه جای امن منتقل کنید:
su - postgres pg_dumpall > backup_all_postgresql_data.sql
وقتی که این آموزش رو دارم می نویسم آخرین نسخه ۹.۶ هستش. شما می تونید هر ورژنی بالاتر از ورژن ۹.۶ رو نصب کنید با همین روندی که در ادامه هست. فقط جاهایی که لازمه تو دستورات ورژن رو باید تغییر بدید.
#1 : مرحله اول نصب postgresql 9.6
# download last package from official postgresql website cd /tmp wget https://yum.postgresql.org/9.6/redhat/rhel-7.4-x86_64/pgdg-centos96-9.6-3.noarch.rpm # install postgresql9.6 rpm -ivh pgdg-centos96-9.6-3.noarch.rpm yum install postgresql96-server postgresql96-contrib # initial /usr/pgsql-9.6/bin/postgresql96-setup initdb mv /usr/bin/pg_ctl{,-orig} echo '#!/bin/bash' > /usr/bin/pg_ctl echo '"$0"-orig "${@/unix_socket_directory/unix_socket_directories}"' >> /usr/bin/pg_ctl chmod +x /usr/bin/pg_ctl
#2 : آپدیت/ایمپورت دیتای موجود روی ورژن قبل به ورژن جدید
systemctl stop postgresql # At this point both servers are stoped # As Postgres user su postgres cd ~ /usr/pgsql-9.6/bin/pg_upgrade -v -b /usr/bin/ -B /usr/pgsql-9.6/bin/ -d /var/lib/pgsql/data/ -D /var/lib/pgsql/9.6/data/ exit # Back to root user # Rollback pg_ctl mv -f /usr/bin/pg_ctl{-orig,} #### APPLY OLD postgresql config params to postgresql-9.6 (pg_hba.conf, postgresql.conf) (manually), maybe use pgtune for postgresql.conf...
#3 : استارت سروریس جدید (نسخه ۹.۶) و غیر فعال کردن نسخه قبل
systemctl start postgresql-9.6 systemctl enable postgresql-9.6 systemctl disable postgresql # temporary ln -s /usr/pgsql-9.6/bin/psql /usr/bin/psql --force ln -s /usr/pgsql-9.6/bin/pg_dump /usr/bin/pg_dump --force # Postgres user su postgres cd ~ ./analyze_new_cluster.sh exit # back as root # remove old postgresql yum remove postgresql # Export new path echo 'export PATH=$PATH:/usr/pgsql-9.6/bin' >> /etc/bashrc
در نهایت می تونید فولدر دیتای ورژن قبل رو به اختیار حذف کنید یا نگه دارید.