3

i have a machine where a user deleted their postgresql folder from the command line in an attempt to uninstall postgres. now when we try to install any other packages - even unrelated ones - we keep getting error messages about postgresql-common.

I tried to uninstall everything related to postgresql-9.3 and postgresql-9.4 manually via the command line but that's not working.

This is what happens when I try:

jj@testdev:~/Documents/svc_core_design/svc_core_git/svc-core-docs/net-svc$ sudo apt-get purge postgresql-client-9.3
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'postgresql-client-9.3' is not installed, so not removed
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 postgresql-9.3 : Depends: postgresql-client-9.3 but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
jj@testdev:~/Documents/svc_core_design/svc_core_git/svc-core-docs/net-svc$ 

To see what postgresql components he still has I ran the following command:

sudo dpkg --get-selections | grep -v deinstall

postgresql-9.3                                  purge
postgresql-client-9.4                           install
postgresql-client-common                        install
postgresql-common                               install

I would like to either remove all postgresql related items if possible, or re-install so it's working properly.(don't need both versions if we re-install. Just 9.4 would be fine.) Can you tell me how I can do that via command line?

EDIT 1

Here are the results from trying to run "sudo apt-get -f install" without any package name:

jj@testdev:/var/lib/postgresql$ sudo apt-get -f install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libjs-underscore linux-image-3.16.0-25-generic linux-image-3.16.0-33-generic linux-image-extra-3.16.0-25-generic linux-image-extra-3.16.0-33-generic
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up postgresql-common (166.pgdg14.10+1) ...
insserv: warning: script 'mongod' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `mongod'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `mongod'
 * Starting PostgreSQL 9.3 database server                                                                                                                                                                                                 * Error: /var/lib/postgresql/9.3/main is not accessible or does not exist
                                                                                                                                                                                                                                   [fail]
 * Starting PostgreSQL 9.4 database server                                                                                                                                                                                                 * Error: /var/lib/postgresql/9.4/main is not accessible or does not exist
                                                                                                                                                                                                                                   [fail]
invoke-rc.d: initscript postgresql, action "start" failed.
dpkg: error processing package postgresql-common (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 postgresql-common
E: Sub-process /usr/bin/dpkg returned an error code (1)
jj@testdev:/var/lib/postgresql$ sudo 

I've also made sure that the owner on the /var/lib/postgresql folder is postgres, in case that helps. Perhaps I should manually create the folder structure it's complaining about?

  /var/lib/postgresql/9.3/main

Any other suggestions?

EDIT 2

I installed aptitude and tried to purge postgresql 9.3 and 9.4 It fails with:

jj@testdev:/var/lib/postgresql$ sudo aptitude purge postgresql-9.3
The following packages will be REMOVED:  
  postgresql-9.3{p} 
The following partially installed packages will be configured:
  postgresql-common 
0 packages upgraded, 0 newly installed, 1 to remove and 5 not upgraded.
Need to get 0 B of archives. After unpacking 17.6 MB will be freed.
Do you want to continue? [Y/n/?] Y
(Reading database ... 339475 files and directories currently installed.)
Removing postgresql-9.3 (9.3.5-2.pgdg14.10+1) ...
 * Stopping PostgreSQL 9.3 database server                                                                                                                                                                                     * Error: /var/lib/postgresql/9.3/main is not accessible or does not exist
                                                                                                                                                                                                                       [fail]
invoke-rc.d: initscript postgresql, action "stop" failed.
dpkg: error processing package postgresql-9.3 (--purge):
 subprocess installed pre-removal script returned error exit status 1
Errors were encountered while processing:
 postgresql-9.3
E: Sub-process /usr/bin/dpkg returned an error code (1)
Failed to perform requested operation on package.  Trying to recover:
Setting up postgresql-common (166.pgdg14.10+1) ...
 * Starting PostgreSQL 9.3 database server                                                                                                                                                                                     * Error: /var/lib/postgresql/9.3/main is not accessible or does not exist
                                                                                                                                                                                                                       [fail]
 * Starting PostgreSQL 9.4 database server                                                                                                                                                                                     * Error: /var/lib/postgresql/9.4/main is not accessible or does not exist
                                                                                                                                                                                                                       [fail]
invoke-rc.d: initscript postgresql, action "start" failed.
dpkg: error processing package postgresql-common (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 postgresql-common

jj@testdev:/var/lib/postgresql$ 

EDIT 3:

Here are the results of running the command "sudo apt-get purge postgresql-client-9.4 postgresql-client-common postgresql-common"

Removing postgresql-common (166.pgdg14.10+1) ...
 * Stopping PostgreSQL 9.3 database server                                                                                                                                                                                     * Error: /var/lib/postgresql/9.3/main is not accessible or does not exist
                                                                                                                                                                                                                       [fail]
 * Stopping PostgreSQL 9.4 database server                                                                                                                                                                                     * Error: /var/lib/postgresql/9.4/main is not accessible or does not exist
                                                                                                                                                                                                                       [fail]
invoke-rc.d: initscript postgresql, action "stop" failed.
dpkg: error processing package postgresql-common (--purge):
 subprocess installed pre-removal script returned error exit status 1
 * Starting PostgreSQL 9.3 database server                                                                                                                                                                                     * Error: /var/lib/postgresql/9.3/main is not accessible or does not exist
                                                                                                                                                                                                                       [fail]
 * Starting PostgreSQL 9.4 database server                                                                                                                                                                                     * Error: /var/lib/postgresql/9.4/main is not accessible or does not exist
                                                                                                                                                                                                                       [fail]
invoke-rc.d: initscript postgresql, action "start" failed.
dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 1

and when I check what's installed:

jj@testdev:/var/lib/postgresql$ sudo dpkg --get-selections | grep -v deinstall | grep post
libreoffice-sdbc-postgresql         install
postgresql-9.3                  purge
postgresql-9.4                  purge
postgresql-common               purge
printer-driver-postscript-hp            install
jj@testdev:/var/lib/postgresql$ 
  • 1
    What happens when you try sudo apt-get -f install? – Wilf Mar 27 '15 at 18:15
  • From the error message "Try 'apt-get -f install' with no packages" so ... sudo apt-get install -f – Panther Mar 27 '15 at 18:21
  • Related: askubuntu.com/questions/48014/… – muru Apr 15 '15 at 19:33
  • @muru, the solution in that post does not work. I still get the same error as using apt-get remove. – dot Apr 15 '15 at 20:00
  • Maybe try a simple reinstall? Aptitude might also help. Run apt-get install aptitude then run aptitude purge [package name(s)]. Aptitude just tries harder than apt-get to complete the requested operation. – TheWanderer Apr 16 '15 at 1:04
2

Have you tried to just purge the packages left from the failed removal attempt manually?

sudo apt-get purge postgresql-client-9.4 postgresql-client-common postgresql-common

Then:

sudo apt-get update install postgresql

The removal obviously fails because postgresql is not installed, but the reinstallation might be failing because something is wrong with what has been left from the previous installation.

  • kos, please see edit 3 – dot Apr 17 '15 at 14:03
  • after trying your suggestion, i also retried removing via aptitude toold. what do you think of line 42 on this pastebin? pastebin.com/CjtmQDie – dot Apr 17 '15 at 14:17
  • @dot I think I've got this: run sudo gedit /var/lib/dpkg/info/postgresql-9.3.prerm and comment (by adding a # at the start) this line: . /usr/share/postgresql-common/maintscripts-functions, then try purging again – kos Apr 17 '15 at 14:31
2

In the plethora of attempts to delete using aptitude and also apt-get remove / purge, i was getting a message that it couldn't delete postgresql-9.3 because the directories /var/lib/postgresql and /var/log/postgresql were not empty.

So i blew them away and then did the sudo apt-get purge... which sort of worked. And then I did aptitude purge and it worked. Now we can install packages again on this box without errors.

0

I had run into this problem by looking for all postgresql folders using whereis postgresql and then manually deleting them. But then when I needed to reinstall postgresql using apt-get install postrgesql-10 or do a simple apt-get upgrade, I was getting the below as part of the error:

Can't open /usr/share/postgresql-common/maintscripts-functions

What I did was that I copied the actual file from their Github repo here and placed it at that location. Then I did the following steps:

  • dpkg -l | grep postgresql - to list the packages that were installed. This will show you the result like this screenshot.

  • Use the package names from the above result and remove them - sudo apt-get remove <PACKAGE>

  • Next, remove all leftover packages with sudo apt-get autoremove

Restart your machine once after this and you should be good to go!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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