ubuntu machine had postgresql folder blown away manually - can't install or remove any packages

6,021

Solution 1

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 I can install packages again on this box without errors.

Solution 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.

Share:
6,021

Related videos on Youtube

dot
Author by

dot

Updated on September 18, 2022

Comments

  • dot
    dot over 1 year

    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$ 
    
    • Wilf
      Wilf about 9 years
      What happens when you try sudo apt-get -f install?
    • muru
      muru about 9 years
    • dot
      dot about 9 years
      @muru, the solution in that post does not work. I still get the same error as using apt-get remove.
    • TheWanderer
      TheWanderer about 9 years
      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.
    • dot
      dot about 9 years
      @Zacharee1 re-install doesn't work either. Please see Edit 2 re: details on aptitude results
    • TheWanderer
      TheWanderer about 9 years
      All you did was try to purge it. The output is saying that the package isn't installed, so you should try installing it.
    • dot
      dot about 9 years
      @Zacharee1 no, actually, I've been trying to re-install as well. But as I mentioned in my earlier comment, the install fails with the same message. I tried to install with aptitute as well via the command "sudo aptitude install postgresql-9.4"
    • dot
      dot about 9 years
      this issue is actually preventing me from installing any packages on the machine. All attempts fail with some flavor of the same message about postgresql-common
    • We are Borg
      We are Borg about 9 years
      Did you try sudo apt-get purge postgresql*
  • dot
    dot about 9 years
    kos, please see edit 3
  • dot
    dot about 9 years
    after trying your suggestion, i also retried removing via aptitude toold. what do you think of line 42 on this pastebin? pastebin.com/CjtmQDie
  • kos
    kos about 9 years
    @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