Note: This guide needs root access. Root access means full control of the server. It is for VPS and dedicated server owners.
What is PostgreSQL?
PostgreSQL, also called Postgres, is database software. A database stores data in tables. You may want to remove Postgres if you no longer use it or want to start fresh.
Warning: Removing PostgreSQL can delete all its databases. Websites that use it will stop working. Back up everything first.
Step 1: Back up your data
su - postgres
- Save every database into one file.
pg_dumpall > /tmp/all-databases.sql
This writes all databases and users to a single file.
- Type
exitto go back to root. - Download the file to your own computer. Keep it safe.
Step 2: Stop the service
systemctl stop postgresql
This stops Postgres from running.
Step 3: Remove the packages
On Ubuntu or Debian:
apt-get --purge remove postgresql postgresql-*
On CentOS, AlmaLinux or Rocky Linux:
yum remove postgresql*
These commands uninstall the software. --purge also removes its settings files. On newer systems, dnf replaces yum and works the same way.
Step 4: Remove leftover data (optional)
The data folder may still exist. Only delete it once you are sure your backup works.
rm -rf /var/lib/postgresql
rm -rf /var/lib/pgsql
These remove the folders where Postgres kept its data. One of the two may not exist. That is fine.
Step 5: Check
psql --version
You should see "command not found". That means it is gone.
If you use cPanel, do not remove PostgreSQL by hand. Ask Hostvento support first, since cPanel manages it.
Quick recap
- Back up with
pg_dumpallbefore anything else. - Stop the service, then remove the packages.
- Delete the data folder only when you are sure.
- Check with
psql --version.
