Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have been struggling all weekend, to upgrade an existing postgresql database from version 8.4 to 9.1. I have (had) both versions of databases after I updated my OS from 10.0.4 to 12.04.

I finally became exasperated and in a moment of lapsed judgement, I forcibly removing all 8.4 related files from my machine, using:

find / -type d -name 8.4 2>/dev/null | xargs rm -rf {}

I decided the better way to have removed it would have been `apt-get remove postgresql-8.4'

Well when I tried that, apt-get reported:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  postgresql-8.4
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 15.5 MB disk space will be freed.
Do you want to continue [Y/n]? y
(Reading database ... 304184 files and directories currently installed.)
Removing postgresql-8.4 ...
find: `/usr/share/postgresql/8.4/tsearch_data': No such file or directory
dpkg: error processing postgresql-8.4 (--remove):
 subprocess installed pre-removal script returned error exit status 1
Errors were encountered while processing:
 postgresql-8.4
E: Sub-process /usr/bin/dpkg returned an error code (1)

How do I purge postgresql 8.4 from my machine?

[[Edit]]

After I tried apt-get install --reinstall postgresql-8.4, I get the following error:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  oidentd ident-server
The following NEW packages will be installed:
  postgresql-8.4
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
Need to get 0 B/5,599 kB of archives.
After this operation, 15.5 MB of additional disk space will be used.
Selecting previously unselected package postgresql-8.4.
(Reading database ... 304010 files and directories currently installed.)
Unpacking postgresql-8.4 (from .../postgresql-8.4_8.4.14-0ubuntu12.04.2_amd64.deb) ...
Setting up postgresql-client-8.4 (8.4.14-0ubuntu12.04.2) ...
update-alternatives: error: alternative path /usr/share/postgresql/8.4/man/man1/psql.1.gz doesn't exist.
dpkg: error processing postgresql-client-8.4 (--configure):
 subprocess installed post-installation script returned error exit status 2
dpkg: dependency problems prevent configuration of postgresql-8.4:
 postgresql-8.4 depends on postgresql-client-8.4; however:
  Package postgresql-client-8.4 is not configured yet.
dpkg: error processing postgresql-8.4 (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 postgresql-client-8.4
 postgresql-8.4
E: Sub-process /usr/bin/dpkg returned an error code (1)
share|improve this question
    
please link to your other related questions so other people with similar problems can find the whole story. –  Craig Ringer Nov 19 '12 at 1:32

3 Answers 3

up vote 1 down vote accepted

OK, this was really, REALLY nasty because there's a dependency nest in there that just won't go away with the usual round of apt-get purge, apt-get -f install, etc. The only way around this one (I recreated your problem in a VM and tested) is just to put a directory there for apt to get rid of in the first place.

root@yourbox:/# mkdir -p /usr/share/postgresql/8.4/tsearch_data
root@yourbox:/# apt-get purge postgresql-8.4
root@yourbox:/# apt-get autoremove

With an empty directory there for apt to remove, both the initial purge of the parent package and the autoremoval of the child packages completed without errors in my VM.

share|improve this answer
    
... and now that you've messed more with the packages, you've created a situation where it looks for MORE files that it isn't finding. Now you also have /usr/share/postgresql/8.4/man/man1/psql.1.gz. You'll have to create that as well. touch /usr/share/postgresql/8.4/man/man1/psql.1.gz Basically, read the output - any files or directories it complains about not being able to find, create them. They can be empty, but they need to be there. –  Jim Salter Nov 18 '12 at 21:12
    
Actually I thought of recreating the files as you suggest, but thought it best to come in here and ask first, in case I waste even more time doing soething that dosen't work.. I'll try what you suggest and report back. –  Homunculus Reticulli Nov 18 '12 at 21:17
    
+1 for spending time on helping me fix my problem. It is people like you who make the internet great :) !. Thanks for your help. –  Homunculus Reticulli Nov 18 '12 at 21:37
    
You're welcome! =) –  Jim Salter Nov 18 '12 at 21:52

So, given that the easy solution doesn't work, here's one that requires a bit more work and explanation, but has a better chance of success.

apt at the moment is very confused about your postgres packages. So confused even that we need to make it even more confused.

When installing/removing packages, certain scripts can be run, these are post-install, pre-install etc. scripts and live in /var/lib/dpkg/info. To make removal work even when these scripts fail because you messed up your system, you can add a line that says exit 0 right after the first line in each of these scripts for the affected packages. Don't edit other scripts.

The removal with apt-get remove --purge will then work as far as apt is concerned, but this will leave some mess behind. To remove that mess, you should reinstall the packages you removed using the neutered postrm/prerm scripts and remove them properly this time.

share|improve this answer
    
This is the correct approach; bypass the prerm and postrm scripts, then reinstall and purge cleanly. –  Craig Ringer Nov 19 '12 at 1:33

You better start by reinstalling 8.4:

sudo apt-get install --reinstall postgresql-8.4

Then you can remove it with

sudo apt-get remove --purge postgresql-8.4

If the reinstall fails, show us the error.

share|improve this answer
    
Thanks for the prompt feedback. Please see my updated question. –  Homunculus Reticulli Nov 18 '12 at 20:51
    
Try reinstalling postgresql-client-8.4 as well –  Dennis Kaarsemaker Nov 18 '12 at 20:53
    
I get the same error :( apt-get install --reinstall postgresql-8.4 postgresql-client-8.4 –  Homunculus Reticulli Nov 18 '12 at 20:57
    
Best do them one by one, -client first. –  Dennis Kaarsemaker Nov 18 '12 at 21:00
    
Thanks for your feedback, but are you by any chance guessing how to fix this?. I get the error: " dpkg: dependency problems prevent configuration of postgresql-8.4: postgresql-8.4 depends on postgresql-client-8.4; however: Package postgresql-client-8.4 is not configured yet." when I try what you suggested - i.e. sudo apt-get install --reinstall postgresql-client-8.4 –  Homunculus Reticulli Nov 18 '12 at 21:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.