6

I am new to postgres and I think I messed up my postgresql, so I want to delete postgresql so that I can reinstall it. The problem is that when I run the following command, the folder /etc/postgresql/9.5 still exists.

sudo apt-get remove postgresql

I also tried:

sudo apt-get --purge remove postgresql

But this did not do the trick either. Does anyone have an idea of how to delete postgresql completely?

2
  • [aside] this question has nothing to do with Python, for clarity you should remove that I think. Also it would probably help if you specified your distribution. Commented Aug 7, 2018 at 22:34
  • askubuntu.com/a/187891/47132 Commented Aug 7, 2018 at 22:40

3 Answers 3

9

You were correct in the command to uninstall postgresql. The /etc/postgresql contains configuration files. You can remove that and other postgres directories yourself using

sudo rm -rf /var/lib/postgresql/
sudo rm -rf /var/log/postgresql/
sudo rm -rf /etc/postgresql/

Base on this answer here, you may also have related packages installed you can list with

dpkg -l | grep postgres

You can remove those using the same command

sudo apt-get --purge remove package-to-be-removed
Sign up to request clarification or add additional context in comments.

Comments

1

You can remove all the packages related to PostgreSQL with just one line of code using a wild card *:

sudo apt-get --purge remove postgresql*

This means you remove all the packages which names start from "postgresql", * means "and everything after". While uninstalling you'll be additionally asked to remove the files associated with the postgres, in your case you should agree with that.

Then you can check whether some packages have left, with this command, for example (outputs the list of packages with the names that start with "postgr"):

sudo dpkg -l | grep postgr*

and it should give you no output (i.e. "no packages"). If you're not sure with the latest command, you can check it before removing anything - you will see the list of PostgreSQL packages.

Comments

0

First of all remove postgresql using this command

sudo apt-get --purge remove postgresql

Then list all the postgres related package

dpkg -l | grep postgres

remove all the packages using the following command

apt-get --purge remove packagename1 packagename2 ..

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

whereis postgres
whereis postgresql

delete the postgres user using the command

userdel -f postgres

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.