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

后端 未结 15 2704
挽巷
挽巷 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 03:52

    Standing on the shoulders of the other poor creatures trodding through this muck, I was able to follow these steps to get back up and running after an upgrade to Yosemite:

    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 9.4 database:

      initdb /usr/local/var/postgres9.4 -E utf8

    3. Install postgres 9.3 (as it was no longer present on my machine):

      brew install homebrew/versions/postgresql93

    4. Add directories removed during Yosemite upgrade:

      mkdir -p /usr/local/var/postgres/{pg_tblspc,pg_twophase,pg_stat_tmp}/touch /usr/local/var/postgres/{pg_tblspc,pg_twophase,pg_stat_tmp}/.keep

    5. run pg_upgrade:

      pg_upgrade -v -d /usr/local/var/postgres -D /usr/local/var/postgres9.4 -b /usr/local/Cellar/postgresql93/9.3.5/bin/ -B /usr/local/Cellar/postgresql/9.4.0/bin/

    6. Move new data into place:

      cd /usr/local/var
      mv postgres postgres9.3
      mv postgres9.4 postgres
      
    7. Restart Postgres:

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

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

    9. Finally, re-install related libraries?

      pip install --upgrade psycopg2
      gem uninstall pg
      gem install pg
      

提交回复
热议问题