How to upgrade PostgreSQL from version 9.4 to version 11

These guide is primary targeted for external PostgreSQL installation. Embedded PostgreSQL upgrade is included in Dispatcher Paragon server installer.

Requirements

I assume default PostgreSQL binary folder is: "C:\DispatcherParagon\Management\PGSQL" and PostgreSQL data folder is: "C:\DispatcherParagon\Management\PGSQL-data", same as default installation of Dispatcher Paragon Management Server with embedded PostgreSQL database. Please change these folders according to your deployment options.

  1. Download PostgreSQL 11 binaries from https://www.enterprisedb.com/download-postgresql-binaries. Select PostgreSQL 11 version according to your operation system.

  2. Backup PostgreSQL 9.4 data folder "C:\DispatcherParagon\Management\PGSQL-data".

A Step-by-step Guide

Follow next steps to upgrade PostgreSQL installation to version 11.

  1. Stop PostgreSQL service and all dependent services.

  2. Copy downloaded PostgreSQL 11 binaries into new folder, at example "C:\DispatcherParagon\Management\PGSQL_11".

  3. Create postgres_password.txt file in current directory and put postgresql user password into the file.
    images/download/attachments/284926955/image2019-7-15_13-45-3-version-1-modificationdate-1568026237283-api-v2.png

  4. Initialize new data folder (such as C:\DispatcherParagon\Management\PGSQL_11-data), run initdb:

    c:\DispatcherParagon\Management\PGSQL_11\bin\initdb -D "c:/DispatcherParagon/Management/PGSQL_11-data/" -E utf-8 --auth=md5 -U "postgres" --pwfile="postgres_password.txt"

  5. Upgrade PostgreSQL data folder. Before executing pg_upgrade, make sure that Administrator account has granted Full controll permission for both old PGSQL and PGSQL-data directories and new PGSQL_11 and PGSQL_11-data directories.

    C:\DispatcherParagon\Management\PGSQL_11\bin\pg_upgrade -U postgres -b "C:\DispatcherParagon\Management\PGSQL/bin" -B "C:\DispatcherParagon\Management\PGSQL_11/bin" -d "C:\DispatcherParagon\Management\PGSQL-data" -D "C:\DispatcherParagon\Management\PGSQL_11-data"

  6. Change configuration in postgresql.conf which you required. List of changes to default configuration by default installation of Dispatcher Paragon Management Server:

    listen_addresses = '*'
    port = 5433
    max_connections = 120
    shared_buffers = 512MB
    max_prepared_transactions = 20
    work_mem = 128MB
    maintenance_work_mem = 512MB
    effective_cache_size = 1024MB
    logging_collector = on
    log_directory = 'pg_log'
    autovacuum_naptime = 43min
    datestyle = 'iso, dmy'
    default_text_search_config = 'pg_catalog.simple'

  7. Test if PostgreSQL will start correctly:

    "C:\DispatcherParagon\Management\PGSQL_11\bin\pg_ctl.exe" start -D "C:\DispatcherParagon\Management\PGSQL_11-data" -w

    and stop the service after check:

    "C:\DispatcherParagon\Management\PGSQL_11\bin\pg_ctl.exe" stop -D "C:\DispatcherParagon\Management\PGSQL_11-data" -w

  8. Remove old PostgreSQL 9.4 folders: "C:\DispatcherParagon\Management\PGSQL" and "C:\DispatcherParagon\Management\PGSQL-data".

  9. Rename "C:\DispatcherParagon\Management\PGSQL_11" to "C:\DispatcherParagon\Management\PGSQL" and "C:\DispatcherParagon\Management\PGSQL_11-data" to "C:\DispatcherParagon\Management\PGSQL-data".

  10. Delete postgres_password.txt file.

  11. Start PostgreSQL service and all dependent services.

Troubleshooting

pg_upgrade fails with could not write to log file or could not connect to server errors

pg_upgrade can fail with could not write to log file error or that source database could not be started, see screenshots below:

images/download/attachments/284926955/image2019-9-5_10-16-59-version-1-modificationdate-1568026237243-api-v2.png


images/download/attachments/284926955/image2019-9-5_10-19-28-version-1-modificationdate-1568026237207-api-v2.png

Administrator account should have Full control permission set for both old PGSQL and PGSQL-data directories and new PGSQL_11 and PGSQL_11-data directories. On each directory: right click and select Properties → switch to Security tab → click Advanced → on Permissions tab → click Add

images/download/attachments/284926955/scr3-version-1-modificationdate-1568026237197-api-v2.png

click on Select a principal link → fill in Administrator account (in our example it is RND0171\Administrator, this might differ on production environment) → click OK.


images/download/attachments/284926955/scr4-permission-version-1-modificationdate-1568026237183-api-v2.png

Check Full control checkbox → click OK

images/download/attachments/284926955/scr5-permission-after-version-1-modificationdate-1568026237147-api-v2.png

pg_upgrade fails with fe_sendauth no password supplied error message

images/download/attachments/284926955/image2019-9-11_12-29-37-version-1-modificationdate-1568197777560-api-v2.png

Set PGPASSWORD environment variable to postgres' user password (previously provided via postgres_password.txt file.

cmd
set PGPASSWORD=<password>
powershell
$ENV:PGPASSWORD="<password>"


ALTERNATIVELY, temporarily change METHOD value from md5 (or whatever value you find there) to trust in pg_hba.conf for both PGSQL-data and PGSQL_11-data directories.

pg_hba.conf
host all all 0.0.0.0/0 trust

For easy migration do this for all records in both pg_hba.conf files, but do not forget to change it back after pg_upgrade successfully finishes.


If there will be some other problem during upgrade phase which you would not be able to solve you could provide complete new installation of PostgreSQL by installer(https://www.enterprisedb.com/downloads/postgres-postgresql-downloads). You will need to backup all necessary databases from old PostgreSQL version and restore databases into new PostgreSQL 11 installation.