Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Remove PostgreSQL from a Server

This guide shows how to uninstall PostgreSQL from a Linux server you control.

Databases2 min read5 steps1 screenshots

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

  1. Connect to your server with SSH.
  2. Switch to the postgres user.
    Screenshot: Switch to the postgres user.
su - postgres
  1. Save every database into one file.
pg_dumpall > /tmp/all-databases.sql

This writes all databases and users to a single file.

  1. Type exit to go back to root.
  2. 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.

Tip: Older systems may use different commands. Newer versions work in a similar 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_dumpall before anything else.
  • Stop the service, then remove the packages.
  • Delete the data folder only when you are sure.
  • Check with psql --version.