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

后端 未结 15 2661
挽巷
挽巷 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:14

    Assuming you've used home-brew to install and upgrade Postgres, you can perform the following steps.

    1. Stop current Postgres server:

      launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

    2. Initialize a new 10.1 database:

      initdb /usr/local/var/postgres10.1 -E utf8

    3. run pg_upgrade (note: change bin version if you're upgrading from something other than below):

      pg_upgrade -v \
          -d /usr/local/var/postgres \
          -D /usr/local/var/postgres10.1 \
          -b /usr/local/Cellar/postgresql/9.6.5/bin/ \
          -B /usr/local/Cellar/postgresql/10.1/bin/
      

      -v to enable verbose internal logging

      -d the old database cluster configuration directory

      -D the new database cluster configuration directory

      -b the old PostgreSQL executable directory

      -B the new PostgreSQL executable directory

    4. Move new data into place:

      cd /usr/local/var
      mv postgres postgres9.6
      mv postgres10.1 postgres
      
    5. Restart Postgres:

      launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

    6. Check /usr/local/var/postgres/server.log for details and to make sure the new server started properly.

    7. Finally, re-install the rails pg gem

      gem uninstall pg
      gem install pg
      

    I suggest you take some time to read the PostgreSQL documentation to understand exactly what you're doing in the above steps to minimize frustrations.

提交回复
热议问题