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?
I'm afraid I will destroy the data in the database or mess it up.
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?
I'm afraid I will destroy the data in the database or mess it up.
This did it for me.
https://gist.github.com/dideler/60c9ce184198666e5ab4
Short and to the point. I honestly don't aim to understand the guts of PostgreSQL, I want to get stuff done.
My solution was to do a combination of these two resources:
https://gist.github.com/tamoyal/2ea1fcdf99c819b4e07d
and
http://www.gab.lc/articles/migration_postgresql_9-3_to_9-4
The second one helped more then the first one. Also to not, don't follow the steps as is as some are not necessary. Also, if you are not being able to backup the data via postgres console, you can use alternative approach, and backup it with pgAdmin 3 or some other program, like I did in my case.
Also, the link: https://help.ubuntu.com/stable/serverguide/postgresql.html Helped to set the encrypted password and set md5 for authenticating the postgres user.
After all is done, to check the postgres
server
version run in terminal:After entering the password run in postgres terminal:
It will output something like:
For setting and starting postgres I have used command:
And then for restoring database from a file:
Or if doesn't work try with this one:
And if you are using Rails do a
bundle exec rake db:migrate
after pulling the code :)On Windows I kept facing different errors messages when trying to use
pg_upgrade
.Saved a lot of time for me to just:
Here is the solution for Ubuntu users
First we have to stop postgresql
Create a new file called /etc/apt/sources.list.d/pgdg.list and add below line
Follow below commands
Now we have everything, just need to upgrade it as below
That's it. Mostly upgraded cluster will run on port number 5433. Check it with below command
Update: This process is the same for upgrading 9.6 to 10; simply modify the commands to reflect versions
9.6
and10
, where9.6
is the old version and10
is the new version. Be sure to adjust the "old" and "new" directories accordingly, too.I just upgraded PostgreSQL 9.5 to 9.6 on Ubuntu and thought I'd share my findings, as there are a couple of OS/package-specific nuances of which to be aware.
(I didn't want to have to dump and restore data manually, so several of the other answers here were not viable.)
In short, the process consists of installing the new version of PostgreSQL alongside the old version (e.g., 9.5 and 9.6), and then running the
pg_upgrade
binary, which is explained in (some) detail at https://www.postgresql.org/docs/9.6/static/pgupgrade.html .The only "tricky" aspect of
pg_upgrade
is that failure to pass the correct value for an argument, or failure to be logged-in as the correct user orcd
to the correct location before executing a command, may lead to cryptic error messages.On Ubuntu (and probably Debian), provided you are using the "official" repo,
deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main
, and provided you haven't changed the default filesystem paths or runtime options, the following procedure should do the job.Install the new version (note that we specify the
9.6
, explicitly):Once installation succeeds, both versions will be running side-by-side, but on different ports. The installation output mentions this, at the bottom, but it's easy to overlook:
Stop both server instances (this will stop both at the same time):
Switch to the dedicated PostgreSQL system user:
Move into his home directory (failure to do this will cause errors):
pg_upgrade
requires the following inputs (pg_upgrade --help
tells us this):These inputs may be specified with "long names", to make them easier to visualize:
We must also pass the
--new-options
switch, because failure to do so results in the following:This occurs because the default configuration options are applied in the absence of this switch, which results in incorrect connection options being used, hence the socket error.
Execute the
pg_upgrade
command from the new PostgreSQL version:Logout of the dedicated system user account:
The upgrade is now complete, but, the new instance will bind to port
5433
(the standard default is5432
), so keep this in mind if attempting to test the new instance before "cutting-over" to it.Start the server as normal (again, this will start both the old and new instances):
If you want to make the new version the default, you will need to edit the effective configuration file, e.g.,
/etc/postgresql/9.6/main/postgresql.conf
, and ensure that the port is defined as such:If you do this, either change the old version's port number to
5433
at the same time (before starting the services), or, simply remove the old version (this will not remove your actual database content; you would need to useapt --purge remove postgresql-9.5
for that to happen):The above command will stop all instances, so you'll need to start the new instance one last time with:
As a final point of note, don't forget to consider
pg_upgrade
's good advice:If you are using homebrew and homebrew services, you can probably just do:
I think this might not work completely if you are using advanced postgres features, but it worked perfectly for me.