How to remove PostgreSQL from linux ubuntu?

by elise_daugherty , in category: PHP Databases , 9 months ago

How to remove PostgreSQL from linux ubuntu?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer


by darion , 3 months ago


To remove PostgreSQL from your Ubuntu system, follow these steps:

  1. Stop the PostgreSQL service:sudo service postgresql stop
  2. Remove the PostgreSQL package and all of its dependencies:sudo apt-get remove --purge postgresql*
  3. Remove the PostgreSQL data directory and user account:sudo rm -r /etc/postgresql sudo rm -r /etc/postgresql-common sudo rm -r /var/lib/postgresql sudo userdel -r postgres
  4. Remove the PostgreSQL system account and group:sudo groupdel postgres sudo userdel -r postgres

Note: These steps will completely remove PostgreSQL from your system, including all databases and user accounts. Make sure to back up any important data before proceeding.

Alternatively, you can use the pg_dropcluster command to remove a specific PostgreSQL cluster from your system. For example, to remove the default cluster (version 11) created during PostgreSQL installation, you can use the following command:

sudo pg_dropcluster 11 main --stop

This will remove the cluster and stop the corresponding PostgreSQL service.