Ruben
Ruben

Reputation: 1091

Upgrade postgresql from 9.3 to 9.5 in Ubuntu 16.04 LTS

I have Ubuntu 16.04 LTS installed in my machine with postgresql-9.3. (It looks I Keep this instance since 16.04 installs postgresql9.5).

Well, I installed 9.5 and remove 9.3 using...

sudo apt-get remove postgresql-9.3

Unfortunately I didn't know all databases and roles were in that instance (9.3) and are not shared with 9.5. when trying to log in with my users it doesn't work because they don't exist in that instance / cluster (am I right?)

I tried to install 9.3 using Ubuntu repository but it installs me just the 9.5. How can I move the all my roles and databases to 9.5 ??

Upvotes: 4

Views: 3675

Answers (1)

Hervé Piedvache
Hervé Piedvache

Reputation: 798

To see if your database is still on your server check this folder :

ls /var/lib/postgresql/9.3/main/base/

If you have files there, this mean your database is still here !! If nothing in this folder, this mean your life data have been deleted.

Did you made a regular backup of your database ?

If so, you need to install back your previous version of PostgreSQL and make a restore of it.

apt-get install postgresql-9.3
psql -h localhost
create database dbname;
psql -h localhost dbname < backup_file

After the normal process to upgrade on Debian or Ubuntu is this one : service postgresql stop

On vire le clus­ter de la nouvelle version (norma­le­ment vide si on vient juste de l’ins­tal­ler : faire gaffe à ne pas lais­ser passer de temps entre l’ins­tal­la­tion de la nouvelle version et la migra­tion des données, pour que personne n’uti­lise le nouveau clus­ter)

Stop the new updated version of PostreSQL :

service postgresql stop

Drop the new updated version cluster to be sure nothing is inside :

pg_dropcluster --stop 9.5 main

Then data migration :

pg_upgradecluster -m upgrade 9.3 main

Then stop previous version of PotsgreSQL :

pg_dropcluster 9.3 main --stop

Remove the old version :

apt-get autoremove --purge postgresql-9.3 

Then just restart PostgreSQL, the new version with database migrated :

service postgresql start

Hope this help.

But if you didn't do any backup, unfortunatly you should have loose everything.

Upvotes: 5

Related Questions