Can't uninstall RPM package

I was trying to install and uninstall postgres 9.3. After performing a variety of steps, I found that I have deleted something manually and now I am not been able to proceed further.

What I am trying to achieve here is to remove all the traces of postgres. I am not able to remove postgresql93-server-9.3.6-1PGDG.rhel5 package.

I am getting the following error:

[root(at)ZetaSearch01 ~]# rpm -qa | grep postg
postgresql93-server-9.3.6-1PGDG.rhel5
[root(at)ZetaSearch01 ~]# yum remove postgresql93-server-9.3.6-1PGDG.rhel5
Loaded plugins: rhnplugin, security
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package postgresql93-server.x86_64 0:9.3.6-1PGDG.rhel5 set to be erased
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
 Package
Arch
Version
Repository                           Size
========================================================================================================================================================================
Removing:
 postgresql93-server
x86_64
9.3.6-1PGDG.rhel5
installed                            15 M

Transaction Summary
========================================================================================================================================================================
Install      0 Package(s)
Update       0 Package(s)
Remove       1 Package(s)

Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
error reading information on service postgresql-9.3: No such file or
directory

Removed: postgresql93-server.x86_64 0:9.3.6-1PGDG.rhel5
Complete!
[root(at)ZetaSearch01 ~]# rpm -qa | grep postg
postgresql93-server-9.3.6-1PGDG.rhel5
[root(at)ZetaSearch01 ~]#

How to solve this error?

Any help would be appreciated as I am totally novice to postgres and it is my first time, I am trying to do something on postgres.


Solution 1:

How about using the rpm command instead:

rpm {-e|--erase} [--allmatches] [--nodeps]  [--noscripts]  [--notriggers]  [--test]  PACK-AGE_NAME ...

You can try it first directly and then with the --nodeps argument like this:

rpm -ev postgresql93-server-9.3.6-1PGDG.rhel5

Full command details at: RPM erase command

Solution 2:

This kind of error is likely caused by a scriptlet. When removing a package, RPM would run the "preuninstall" before removing a package, and the "postuninstall" after removing it. If the "preuninstall" fails, the package will not be removed.

You can check the scriptlets of your package with rpm -q --scripts postgresql93-server. For example, the postgresql92-server package on my machine contains this (abbreviated version to only show the preuninstall)

$ rpm -q postgresql92-server --scripts  | sed -ne /^preuninstall/,/scriptlet/p
preuninstall scriptlet (using /bin/sh):
if [ $1 = 0 ] ; then
    /sbin/service postgresql-9.2 condstop >/dev/null 2>&1
    chkconfig --del postgresql-9.2
fi
postuninstall scriptlet (using /bin/sh):

I guess your postgresql93-server RPM has something similar, and the last command (the chkconfig --del part) is failing causing the package to not be removed.

Two options I can suggest.

1) remove the package without running the scripts:

rpm -e --noscripts postgresql93-server

2) reinstall the package to hopefully fix whatever was broken, because then the "preuninstall" will be passed 1 as an argument and the failing code will not run.

yum reinstall postgresql93-server
yum remove postgresql93-server