How to Uninstall Postgres in PostgreSQL

Galaxy Glossary

How do I completely uninstall PostgreSQL from my system?

Completely removes PostgreSQL binaries, services, configs, and data from your operating system.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Description

How to Uninstall PostgreSQL

Uninstalling PostgreSQL means deleting the server binaries, stopping and disabling related services, purging configuration files, and wiping the data directory. Use your OS package manager for a clean, conflict-free removal.

Why might you need to uninstall PostgreSQL?

Common reasons include reclaiming disk space, upgrading to a fresh major version, removing conflicting installations, or switching to a containerized setup. A clean uninstall avoids leftover libraries that can break future installs.

How do I uninstall PostgreSQL on Debian/Ubuntu?

Stop the service first, purge all packages, and remove data and users.

sudo systemctl stop postgresql
sudo apt-get --purge remove postgresql\*
sudo apt-get autoremove --purge -y
sudo rm -rf /var/lib/postgresql/ /etc/postgresql/ /etc/postgresql-common/ /var/log/postgresql/
sudo deluser postgres

How do I uninstall PostgreSQL on RHEL/CentOS/Fedora?

Use dnf or yum depending on the version.

sudo systemctl stop postgresql
sudo dnf remove postgresql* # yum remove postgresql* on older systems
sudo rm -rf /var/lib/pgsql/ /var/log/pgsql/ /etc/postgresql/
sudo userdel postgres -r

How do I uninstall PostgreSQL installed with Homebrew on macOS?

Homebrew keeps data outside Cellar; delete both.

brew services stop postgresql
brew uninstall --zap postgresql
rm -rf /usr/local/var/postgres

How do I uninstall PostgreSQL on Windows?

Use the Control Panel or Winget, then delete remaining folders.

winget uninstall PostgreSQL

After removal, delete C:\Program Files\PostgreSQL and the data directory if you chose a custom path.

How can I verify PostgreSQL is fully removed?

Run psql --version. A “command not found” or empty result means binaries are gone. Also run systemctl status postgresql (Linux) or check Services (Windows) to confirm no running service remains.

Best practices for a clean uninstall

• Backup any required databases first with pg_dumpall.
• Stop the PostgreSQL service before removing packages.
• Use the package manager’s purge/zap flag to erase configs.
• Remove the postgres system user only when no other clusters exist.

What are common pitfalls?

1. Forgetting to delete the data directory leaves gigabytes on disk.
2. Skipping the service stop step can lock files or cause errors.

Why How to Uninstall Postgres in PostgreSQL is important

How to Uninstall Postgres in PostgreSQL Example Usage


sudo apt-get --purge remove postgresql*

How to Uninstall Postgres in PostgreSQL Syntax


# Debian/Ubuntu
sudo systemctl stop postgresql
sudo apt-get --purge remove postgresql*

# RHEL/CentOS/Fedora
yum remove postgresql*      # or dnf remove

# macOS (Homebrew)
brew services stop postgresql
brew uninstall --zap postgresql

# Windows (winget)
winget uninstall PostgreSQL

Common Mistakes

Frequently Asked Questions (FAQs)

Does uninstalling PostgreSQL delete my databases?

No, package removal keeps data unless you manually delete the data directory. Back up first, then remove the directory if you truly want everything gone.

Can I keep older data while reinstalling a newer version?

Yes. Skip the data-directory deletion step, install the new version, then use pg_upgrade to migrate data.

Is it safe to remove the postgres user?

Only remove the postgres system user after confirming no PostgreSQL clusters remain. Other software rarely relies on that account.

Want to learn about other SQL terms?