175

I have ubuntu 9.10(karmic), and when I attempted to install a new program, the postgres was installed as a dependency of that program, no problem at all if the installation occurs with success, but there was an error, and the Postgres was not installed and the application is not working. I had tryed to update the Postgres and nothing, only the message "there was an error and your postgres can not be installed"

Now I want to remove completely the Postgres from my machine, how can I do that, I do not want to kill the process every boot. I just want to remove Postgres.

What is the command line?

Thanks people.

muru
  • 207,228
devasia2112
  • 1,909

5 Answers5

297

The simplest way to do this is to open a terminal and type:

sudo apt-get --purge remove postgresql postgresql-*

This will also prompt you to remove that software that depends on Postgres, which in this case it appears you would like to do.
I do not personally run 9.10 or Postgres, so it is possible that Postgres installs itself in several parts. In that case, a simple:

dpkg -l | grep postgres

Will get you the list of those packages that Postgres installed. Then, just use the same "apt-get --purge remove ...." command but instead of just postgresql, type each package name, separated by spaces, like:

sudo apt-get --purge remove postgresql postgresql-doc postgresql-common

This is dependent on the list of packages installed, of course.

163

Steps that worked for me on Ubuntu 8.04.2 to remove postgres 8.3

  1. List All Postgres related packages

    dpkg -l | grep postgres
    
    ii  postgresql                            8.3.17-0ubuntu0.8.04.1           object-relational SQL database (latest versi
    ii  postgresql-8.3                        8.3.9-0ubuntu8.04                object-relational SQL database, version 8.3
    ii  postgresql-client                     8.3.9-0ubuntu8.04                front-end programs for PostgreSQL (latest ve
    ii  postgresql-client-8.3                 8.3.9-0ubuntu8.04                front-end programs for PostgreSQL 8.3
    ii  postgresql-client-common              87ubuntu2                        manager for multiple PostgreSQL client versi
    ii  postgresql-common                     87ubuntu2                        PostgreSQL database-cluster manager
    ii  postgresql-contrib                    8.3.9-0ubuntu8.04                additional facilities for PostgreSQL (latest
    ii  postgresql-contrib-8.3                8.3.9-0ubuntu8.04                additional facilities for PostgreSQL
    
  2. Remove all above listed

    sudo apt-get --purge remove postgresql postgresql-8.3  postgresql-client  postgresql-client-8.3 postgresql-client-common postgresql-common  postgresql-contrib postgresql-contrib-8.3
    
  3. Remove the following folders

    sudo rm -rf /var/lib/postgresql/
    sudo rm -rf /var/log/postgresql/
    sudo rm -rf /etc/postgresql/
    
  4. Remove the postgres user:

    sudo deluser postgres
    
Tomas
  • 103
57

One command to completely remove postgresql in terminal is sudo apt-get --purge remove postgresql\*. Please note that this command will remove postgresql and all it's compenents.

19

Follow the commands:

  • sudo apt-get --purge remove postgresql

List all postgres related packages:

  • dpkg -l | grep postgres

remove all the above listed packages using the command :

  • apt-get --purge remove package1 package2 ..

Confirm all the files and folders related to postgres/postgresql are deleted using the command :

  • whereis postgres
  • whereis postgresql

Remove all the files and folders listed using rm command.

Delete the user postgres using the command :

  • userdel -f postgres

happy coding :)

T.Tijo
  • 191
1

Thanks to Code Friendly, & I want to share how I solved my problem.

When I updated postgresql from the Synaptic application, it is the postgresql 10 version that was installed. So I had two versions of postgresql (10 & 9.6) installed in my debian machine. Postgresql 9.6 listening on port 5432. Postgresql 10 listening on port 5433 instead of 5432.

When I run the comand msfconsole in a terminal, although metasploit connects to the msf database on port 5432, the following error message appears:


root@kali:~# msfconsole
[-] Failed to connect to the database: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?

I unistall the 9.6 postgresql version from the Synaptic application, but the problem persists (postgresql 9.6 no longer appears in synaptic's installed software list);

But by executing the command that follows we see that the version postgresql 9.6 was not completely unistalled:


root@kali:~# dpkg -l | grep postgresql 
ii  postgresql                     10+187             all          object-relational SQL database (supported version)
ii  postgresql-9.6                 **                 all          object-relational SQL database, version 9.6 server
ii  postgresql-10                  10.0-1+b1          amd64        object-relational SQL database, version 10 server
ii  postgresql-client-10           10.0-1+b1          amd64        front-end programs for PostgreSQL 10
ii  postgresql-client-common       187                all          manager for multiple PostgreSQL client versions
ii  postgresql-common              187                all          PostgreSQL database cluster manager
ii  postgresql-contrib             10+187             all          additional facilities for PostgreSQL (supported version)

With the following command, postgresql-9.6 uninstalled completely:
root@kali:~# sudo apt-get --purge remove postgresql-9.6

Then I edited the file /etc/postgresql/10/main/postgresql.conf, changed the port number to 5432 and the problem is solved.


Another error message appears:

Creating initial database schema /usr/local/bin/bundle:22:in ``load': cannot load such file -- /usr/lib/ruby/exe/bundle (LoadError)     from /usr/local/bin/bundle:22:in `<main>

I found that the cause was that two (2) versions of Ruby are installed in my debian machine, versions (2.2 & 2.3).

Same thing, I uninstall the ruby 2.2 version from the synaptic application and the problem is solved, metasploit starts without problems.

J. Starnes
  • 1,979