How to upgrade PostgreSQL from version 9.6 to version 10.1 without losing data?

后端 未结 15 2664
挽巷
挽巷 2020-12-02 03:33

I\'m using the PostgreSQL database for my Ruby on Rails application (on Mac OS X 10.9).

Are there any detailed instructions on how to upgrade PostgreSQL database?

15条回答
  •  粉色の甜心
    2020-12-02 04:01

    On Windows 10 since I had npm, I installed rimraf package. npm install rimraf -g

    Backup all your databases one by one using command pg_dump -U $username --format=c --file=$mydatabase.sqlc $dbname

    Then Installed Latest PostgreSQL Version i.e. 11.2 which prompted me to use port 5433 this time.

    Followed by Uninstall of older versions of PostgreSQL mine was 10. Note the uninstaller may give a warning of not deleting folder C:\PostgreSQL\10\data. That's why we have the next step using rimraf to permanently delete the folder and it's sub-folders.

    change into PostgreSQL install directory and ran the command rimraf 10. 10 is a directory name. Note use your older version of PostgreSQL i.e. 9.5 or something.

    Now add C:\PostgreSQL\pg11\bin, C:\PostgreSQL\pg11\lib into the Windows environmental variables. Note my new installed version is 11 thus why I am using pg11.

    Navigate to C:\PostgreSQL\data\pg11 then open postgresql.conf edit port = 5433 to port = 5432

    That's it. Open cmd and type psql -U postgres

    You can now restore all your backed databases one by one using the command pg_restore -U $username --dbname=$databasename $filename

提交回复
热议问题