Update of PostgreSQL server

These instructions assume that the home directory located in pgsql /usr/local/pgsql and the data is in /usr/local/pgsql/data.

If your configuration is different, replace the appropriate paths on your own. Internal data storage format typically changes in every major release of PostgreSQL. So if You are upgrading an existing installation, under version “8.3.x” You should do a backup and then restore the data. If You are upgrading from PostgreSQL “8.3.x”, the new version can use Your current data files so You can skip stages, backup and recovery.

1. Making a backup, make sure that Your database is not updated. This will not affect the integrity of the backup, but the changed data will not be made. If necessary, edit the permissions in the file/usr/local/pgsql/data/pg_hba.conf to deny access from everyone except You. To create a backup of the database type

pg_dumpall > outputfile

If You need to preserve OIDs, use the-o switch. To make a backup, You can use the pg_dumpall command from the version which You currently installed. For best results, however, use the pg_dumpall command from PostgreSQL 8.3.5, since this version contains bug fixes and improvements over older versions. The Council may seem strange since You haven't installed the new version, you can follow it if You plan to install the new version without removing the old version. In this case, You can first finish the installation and then migrate the data. It will also reduce downtime.

2. Stop the old server:

pg_ctl stop

or (depending on the installation of PgSQL on your system)

/etc/rc.d/init.d/postgresql stop

3. Rename or delete the old home directory of pgsql. You can rename the directory instead of deleting it, in case there will be problems with the installation you will be able to go back to the old version. Keep in mind that the home directory database may take considerable disk space. To rename a directory, use the command:

mv /usr/local/pgsql /usr/local/pgsql.old

4. Install new version of PostgreSQL (http://www.postgresql.org/docs/current/static/install-procedure.html)

5. Initialize the newly installed database (you must run the command from the user under which will run the database server, usually the user pgsql).

/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data

6. Restore the necessary settings pg_hba.conf and postgresql.conf.

7. Start the database server (again from the user which should run the database server):

/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data

8. Finally, restore your data from a backup

/usr/local/pgsql/bin/psql -d postgres -f outputfile

Use the new version of PgSQL!

Original article

upd: before you upgrade, carefully consider what you are doing, because versions are not always compatible, and apps that previously worked with your server may stop working.
upd2: in case you are faced with the fact That your applications are incompatible with the updated version, reinstall the previous version and replace it in /usr/local/pgsql/data on a previously saved (if you haven't deleted it, and renamed the p.3).
Article based on information from habrahabr.ru

Comments

Popular posts from this blog

Powershell and Cyrillic in the console (updated)

Active/Passive PostgreSQL Cluster, using Pacemaker, Corosync

Automatic deployment ElasticBeanstalk using Bitbucket Pipelines