卸载apt-get 安装的PostgreSQL版本

文章目录

卸载apt-get 安装的PostgreSQL版本

卸载通过apt-get安装的PostgreSQL 就版本,可以按照以下步骤进行。

查找已安装的PostgreSQL包

在卸载之前,建议先查找并确认已安装的PostgreSQL包及其版本。

可以使用以下命令来查找与PostgreSQL相关的所有已安装包:

clike 复制代码
dpkg -l | grep postgresql

例:

clike 复制代码
root@autodl-container-616f40a3b3-41cb82d9:~# dpkg -l | grep postgresql
ii  postgresql                    10+190ubuntu0.1     all                 object-relational SQL database (supported version)
ii  postgresql-10                 10.23-0ubuntu0.18.0 amd64               object-relational SQL database, version 10 server
ii  postgresql-client             10+190ubuntu0.1     all                 front-end programs for PostgreSQL (supported version)
ii  postgresql-client-10          10.23-0ubuntu0.18.0 amd64               front-end programs for PostgreSQL 10
ii  postgresql-client-common      190ubuntu0.1        all                 manager for multiple PostgreSQL client versions
ii  postgresql-common             190ubuntu0.1        all                 PostgreSQL database-cluster manager
ii  postgresql-server-dev-10      10.23-0ubuntu0.18.0 amd64               development files for PostgreSQL 10 server-side programming
ii  postgresql-server-dev-all     190ubuntu0.1        all                 extension build tool for multiple PostgreSQL versions

卸载PostgreSQL:

使用apt-get的--purge remove选项来卸载PostgreSQL及其配置文件。

通常apt-get卸载时不需要指定小版本号,因为它会卸载所有相关的PostgreSQL包。

不过,如果出于某种原因你需要更精确地指定版本,可能需要查找确切的包名(这通常包括版本号)。但大多数情况下,以下命令就足够了:

clike 复制代码
sudo apt-get --purge remove postgresql*

这个命令会卸载所有以"postgresql"开头的包,包括PostgreSQL服务器、客户端库、文档等。--purge选项会同时删除配置文件。

例:

clike 复制代码
root@autodl-container-616f40a3b3-41cb82d9:/usr/lib/postgresql# cd ~
root@autodl-container-616f40a3b3-41cb82d9:~# apt-get --purge remove postgresql*
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'postgresql-10-pgrouting' for glob 'postgresql*'
Note, selecting 'postgresql-common' for glob 'postgresql*'
Note, selecting 'postgresql-10-pgrouting-doc' for glob 'postgresql*'
Note, selecting 'postgresql-10-repmgr' for glob 'postgresql*'
Note, selecting 'postgresql-9.2-repmgr' for glob 'postgresql*'
Note, selecting 'postgresql-10-dirtyread' for glob 'postgresql*'
Note, selecting 'postgresql-pltcl' for glob 'postgresql*'
Note, selecting 'postgresql-10-asn1oid' for glob 'postgresql*'
Note, selecting 'postgresql-contrib-10' for glob 'postgresql*'
Note, selecting 'postgresql-server-dev-all' for glob 'postgresql*'
Note, selecting 'postgresql-plv8' for glob 'postgresql*'
Note, selecting 'postgresql-10-postgis-2.2-scripts' for glob 'postgresql*'
Note, selecting 'postgresql-10-unit' for glob 'postgresql*'
Note, selecting 'postgresql-10-pgfincore' for glob 'postgresql*'
Note, selecting 'postgresql-10-prioritize' for glob 'postgresql*'
Note, selecting 'postgresql-10-postgis-scripts' for glob 'postgresql*'
Note, selecting 'postgresql-10-pldebugger' for glob 'postgresql*'
Note, selecting 'postgresql-10-mimeo' for glob 'postgresql*'
Note, selecting 'postgresql-9.5-repmgr' for glob 'postgresql*'
Note, selecting 'postgresql-10-python3-multicorn' for glob 'postgresql*'
Note, selecting 'postgresql-10-bgw-replstatus' for glob 'postgresql*'
Note, selecting 'postgresql-10-postgis-2.4' for glob 'postgresql*'
Note, selecting 'postgresql-10-amcheck' for glob 'postgresql*'
Note, selecting 'postgresql-10-jsquery' for glob 'postgresql*'
Note, selecting 'postgresql-filedump' for glob 'postgresql*'
Note, selecting 'postgresql-10-pgmemcache' for glob 'postgresql*'
Note, selecting 'postgresql-10-postgis-2.4-scripts' for glob 'postgresql*'
Note, selecting 'postgresql-10-ogr-fdw' for glob 'postgresql*'
Note, selecting 'postgresql-10-pglogical' for glob 'postgresql*'
Note, selecting 'postgresql-10-postgis-2.3-scripts' for glob 'postgresql*'
Note, selecting 'postgresql-python3-multicorn' for glob 'postgresql*'
Note, selecting 'postgresql-postgis-java' for glob 'postgresql*'
Note, selecting 'postgresql-10-pgrouting-scripts' for glob 'postgresql*'
Note, selecting 'postgresql-10-pgsphere' for glob 'postgresql*'
Note, selecting 'postgresql-10-pgtap' for glob 'postgresql*'
Note, selecting 'postgresql-doc-10' for glob 'postgresql*'
Note, selecting 'postgresql-python-multicorn' for glob 'postgresql*'
Note, selecting 'postgresql-10-cron' for glob 'postgresql*'
Note, selecting 'postgresql-all' for glob 'postgresql*'
Note, selecting 'postgresql-10-pgmp' for glob 'postgresql*'
Note, selecting 'postgresql-9.3-repmgr' for glob 'postgresql*'
Note, selecting 'postgresql-10-pgq3' for glob 'postgresql*'
Note, selecting 'postgresql-10-plproxy' for glob 'postgresql*'
Note, selecting 'postgresql-7.4' for glob 'postgresql*'
Note, selecting 'postgresql-9.0-repmgr' for glob 'postgresql*'
Note, selecting 'postgresql-doc' for glob 'postgresql*'
Note, selecting 'postgresql-8.0' for glob 'postgresql*'
Note, selecting 'postgresql-10-debversion' for glob 'postgresql*'
Note, selecting 'postgresql-10' for glob 'postgresql*'
Note, selecting 'postgresql-10-q3c' for glob 'postgresql*'
Note, selecting 'postgresql-10-prefix' for glob 'postgresql*'
Note, selecting 'postgresql-10-slony1-2' for glob 'postgresql*'
Note, selecting 'postgresql-pgtap' for glob 'postgresql*'
Note, selecting 'postgresql-9.1' for glob 'postgresql*'
Note, selecting 'postgresql-9.3' for glob 'postgresql*'
Note, selecting 'postgresql-9.4' for glob 'postgresql*'
Note, selecting 'postgresql-9.5' for glob 'postgresql*'
Note, selecting 'postgresql-9.6' for glob 'postgresql*'
Note, selecting 'postgresql-10-plr' for glob 'postgresql*'
Note, selecting 'postgresql-client' for glob 'postgresql*'
Note, selecting 'postgresql-10-citus' for glob 'postgresql*'
Note, selecting 'postgresql-10-pgextwlist' for glob 'postgresql*'
Note, selecting 'postgresql-10-plsh' for glob 'postgresql*'
Note, selecting 'postgresql-10-plv8' for glob 'postgresql*'
Note, selecting 'postgresql-10-pgaudit' for glob 'postgresql*'
Note, selecting 'postgresql-plperl' for glob 'postgresql*'
Note, selecting 'postgresql-10-mysql-fdw' for glob 'postgresql*'
Note, selecting 'postgresql-9.6-repmgr' for glob 'postgresql*'
Note, selecting 'postgresql-10-rum' for glob 'postgresql*'
Note, selecting 'postgresql-hll' for glob 'postgresql*'
Note, selecting 'postgresql' for glob 'postgresql*'
Note, selecting 'postgresql-10-ip4r' for glob 'postgresql*'
Note, selecting 'postgresql-10-powa' for glob 'postgresql*'
Note, selecting 'postgresql-contrib' for glob 'postgresql*'
Note, selecting 'postgresql-10-slony1' for glob 'postgresql*'
Note, selecting 'postgresql-plpython3' for glob 'postgresql*'
Note, selecting 'postgresql-10-pgq-node' for glob 'postgresql*'
Note, selecting 'postgresql-server' for glob 'postgresql*'
Note, selecting 'postgresql-q3c' for glob 'postgresql*'
Note, selecting 'postgresql-plpython' for glob 'postgresql*'
Note, selecting 'postgresql-plr' for glob 'postgresql*'
Note, selecting 'postgresql-10-partman' for glob 'postgresql*'
Note, selecting 'postgresql-autodoc' for glob 'postgresql*'
Note, selecting 'postgresql-10-orafce' for glob 'postgresql*'
Note, selecting 'postgresql-10-pllua' for glob 'postgresql*'
Note, selecting 'postgresql-pltcl-10' for glob 'postgresql*'
Note, selecting 'postgresql-10-repack' for glob 'postgresql*'
Note, selecting 'postgresql-10-preprepare' for glob 'postgresql*'
Note, selecting 'postgresql-comparator' for glob 'postgresql*'
Note, selecting 'postgresql-9.4-repmgr' for glob 'postgresql*'
Note, selecting 'postgresql-pgsphere' for glob 'postgresql*'
Note, selecting 'postgresql-server-dev-10' for glob 'postgresql*'
Note, selecting 'postgresql-plperl-10' for glob 'postgresql*'
Note, selecting 'postgresql-9.1-repmgr' for glob 'postgresql*'
Note, selecting 'postgresql-10-similarity' for glob 'postgresql*'
Note, selecting 'postgresql-client-10' for glob 'postgresql*'
Note, selecting 'postgresql-plpython-10' for glob 'postgresql*'
Note, selecting 'postgresql-plpython3-10' for glob 'postgresql*'
Note, selecting 'postgresql-client-common' for glob 'postgresql*'
Note, selecting 'postgresql-10-python-multicorn' for glob 'postgresql*'
Note, selecting 'postgresql-10' instead of 'postgresql-contrib-10'
Package 'postgresql-7.4' is not installed, so not removed
Package 'postgresql-8.0' is not installed, so not removed
Package 'postgresql-9.1' is not installed, so not removed
Note, selecting 'postgresql-plperl-10' instead of 'postgresql-plperl'
Note, selecting 'postgresql-plpython-10' instead of 'postgresql-plpython'
Note, selecting 'postgresql-plpython3-10' instead of 'postgresql-plpython3'
Note, selecting 'postgresql-pltcl-10' instead of 'postgresql-pltcl'
Package 'postgresql-9.3' is not installed, so not removed
Package 'postgresql-9.4' is not installed, so not removed
Package 'postgresql-9.5' is not installed, so not removed
Package 'postgresql-9.6' is not installed, so not removed
Note, selecting 'postgresql-10-plr' instead of 'postgresql-plr'
Package 'postgresql-server' is not installed, so not removed
Package 'postgresql-postgis-java' is not installed, so not removed
Note, selecting 'postgresql-10-pgtap' instead of 'postgresql-pgtap'
Note, selecting 'postgresql-10-plv8' instead of 'postgresql-plv8'
Package 'postgresql-10-postgis-2.2-scripts' is not installed, so not removed
Package 'postgresql-10-postgis-2.3-scripts' is not installed, so not removed
Note, selecting 'postgresql-10-python-multicorn' instead of 'postgresql-python-multicorn'
Note, selecting 'postgresql-10-python3-multicorn' instead of 'postgresql-python3-multicorn'
Note, selecting 'postgresql-10-slony1-2' instead of 'postgresql-10-slony1'
Note, selecting 'postgresql-pgsphere' instead of 'postgresql-10-pgsphere'
Note, selecting 'postgresql-q3c' instead of 'postgresql-10-q3c'
Package 'postgresql-9.6-repmgr' is not installed, so not removed
Package 'postgresql-9.5-repmgr' is not installed, so not removed
Package 'postgresql-9.4-repmgr' is not installed, so not removed
Package 'postgresql-9.3-repmgr' is not installed, so not removed
Package 'postgresql-9.2-repmgr' is not installed, so not removed
Package 'postgresql-9.1-repmgr' is not installed, so not removed
Package 'postgresql-9.0-repmgr' is not installed, so not removed
Package 'postgresql-10-amcheck' is not installed, so not removed
Package 'postgresql-10-asn1oid' is not installed, so not removed
Package 'postgresql-10-bgw-replstatus' is not installed, so not removed
Package 'postgresql-10-citus' is not installed, so not removed
Package 'postgresql-10-cron' is not installed, so not removed
Package 'postgresql-10-debversion' is not installed, so not removed
Package 'postgresql-10-dirtyread' is not installed, so not removed
Package 'postgresql-10-ip4r' is not installed, so not removed
Package 'postgresql-10-jsquery' is not installed, so not removed
Package 'postgresql-10-mimeo' is not installed, so not removed
Package 'postgresql-10-mysql-fdw' is not installed, so not removed
Package 'postgresql-10-ogr-fdw' is not installed, so not removed
Package 'postgresql-10-orafce' is not installed, so not removed
Package 'postgresql-10-partman' is not installed, so not removed
Package 'postgresql-10-pgaudit' is not installed, so not removed
Package 'postgresql-10-pgextwlist' is not installed, so not removed
Package 'postgresql-10-pgfincore' is not installed, so not removed
Package 'postgresql-10-pglogical' is not installed, so not removed
Package 'postgresql-10-pgmemcache' is not installed, so not removed
Package 'postgresql-10-pgmp' is not installed, so not removed
Package 'postgresql-10-pgrouting' is not installed, so not removed
Package 'postgresql-10-pgrouting-doc' is not installed, so not removed
Package 'postgresql-10-pgrouting-scripts' is not installed, so not removed
Package 'postgresql-10-pgtap' is not installed, so not removed
Package 'postgresql-10-pldebugger' is not installed, so not removed
Package 'postgresql-10-pllua' is not installed, so not removed
Package 'postgresql-10-plproxy' is not installed, so not removed
Package 'postgresql-10-plr' is not installed, so not removed
Package 'postgresql-10-plsh' is not installed, so not removed
Package 'postgresql-10-plv8' is not installed, so not removed
Package 'postgresql-10-postgis-2.4' is not installed, so not removed
Package 'postgresql-10-postgis-2.4-scripts' is not installed, so not removed
Package 'postgresql-10-postgis-scripts' is not installed, so not removed
Package 'postgresql-10-powa' is not installed, so not removed
Package 'postgresql-10-prefix' is not installed, so not removed
Package 'postgresql-10-preprepare' is not installed, so not removed
Package 'postgresql-10-prioritize' is not installed, so not removed
Package 'postgresql-10-python-multicorn' is not installed, so not removed
Package 'postgresql-10-python3-multicorn' is not installed, so not removed
Package 'postgresql-10-repack' is not installed, so not removed
Package 'postgresql-10-repmgr' is not installed, so not removed
Package 'postgresql-10-rum' is not installed, so not removed
Package 'postgresql-10-similarity' is not installed, so not removed
Package 'postgresql-10-slony1-2' is not installed, so not removed
Package 'postgresql-10-unit' is not installed, so not removed
Package 'postgresql-autodoc' is not installed, so not removed
Package 'postgresql-comparator' is not installed, so not removed
Package 'postgresql-filedump' is not installed, so not removed
Package 'postgresql-hll' is not installed, so not removed
Package 'postgresql-pgsphere' is not installed, so not removed
Package 'postgresql-q3c' is not installed, so not removed
Package 'postgresql-contrib' is not installed, so not removed
Package 'postgresql-doc' is not installed, so not removed
Package 'postgresql-doc-10' is not installed, so not removed
Package 'postgresql-plperl-10' is not installed, so not removed
Package 'postgresql-plpython-10' is not installed, so not removed
Package 'postgresql-plpython3-10' is not installed, so not removed
Package 'postgresql-pltcl-10' is not installed, so not removed
Package 'postgresql-10-pgq-node' is not installed, so not removed
Package 'postgresql-10-pgq3' is not installed, so not removed
Package 'postgresql-all' is not installed, so not removed
The following packages were automatically installed and are no longer required:
  cron dctrl-tools distro-info-data iproute2 libatm1 libmnl0 libpq-dev libxslt1.1 libxtables12 logrotate lsb-release ssl-cert sysstat
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
  postgresql* postgresql-10* postgresql-client* postgresql-client-10* postgresql-client-common* postgresql-common*
  postgresql-server-dev-10* postgresql-server-dev-all*
0 upgraded, 0 newly installed, 8 to remove and 169 not upgraded.
After this operation, 26.5 MB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 45376 files and directories currently installed.)
Removing postgresql (10+190ubuntu0.1) ...
Removing postgresql-10 (10.23-0ubuntu0.18.04.2) ...
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of stop.
Removing postgresql-client (10+190ubuntu0.1) ...
Removing postgresql-client-10 (10.23-0ubuntu0.18.04.2) ...
Removing postgresql-server-dev-all (190ubuntu0.1) ...
Removing postgresql-server-dev-10 (10.23-0ubuntu0.18.04.2) ...
Removing postgresql-common (190ubuntu0.1) ...
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of stop.
Removing 'diversion of /usr/bin/pg_config to /usr/bin/pg_config.libpq-dev by postgresql-common'
Removing postgresql-client-common (190ubuntu0.1) ...
(Reading database ... 43895 files and directories currently installed.)
Purging configuration files for postgresql-10 (10.23-0ubuntu0.18.04.2) ...
Dropping cluster main...
Purging configuration files for postgresql-client-common (190ubuntu0.1) ...
dpkg: warning: while removing postgresql-client-common, directory '/etc/postgresql-common' not empty so not removed
Purging configuration files for postgresql-common (190ubuntu0.1) ...
dpkg: warning: while removing postgresql-common, directory '/var/lib/postgresql' not empty so not removed
root@autodl-container-616f40a3b3-41cb82d9:~# 

检查并删除残留文件

卸载后,你可能还想检查并手动删除PostgreSQL可能留下的任何残留文件或目录。

这通常包括/etc/postgresql/(配置文件)和/var/lib/postgresql/(数据文件)目录。

例:

clike 复制代码
root@autodl-container-616f40a3b3-41cb82d9:~# ls -l /etc/postgresql-common
ls: cannot access '/etc/postgresql-common': No such file or directory
root@autodl-container-616f40a3b3-41cb82d9:~# ls -l /var/lib/postgresql
total 31864
-rw------- 1 postgres postgres     2812 Sep 28 08:56 logfile
drwxrwxr-x 7 postgres postgres      111 Sep 26 22:16 pgsql16
drwxrwxr-x 7 postgres postgres     4096 Sep 27 21:46 pgvector
drwxrwxr-x 6 postgres postgres     4096 Sep 26 21:30 postgresql-16.3
-rw-rw-r-- 1 postgres postgres 32616059 May  7 04:31 postgresql-16.3.tar.gz
root@autodl-container-616f40a3b3-41cb82d9:~# 

但是,由于--purge选项已经尝试删除了配置文件,这些目录可能已经被清空或不存在了。

验证卸载

可以使用dpkg -l | grep postgresql命令再次检查,以确保没有留下任何与PostgreSQL相关的包。

如果命令没有返回任何内容,说明PostgreSQL已经被成功卸载。

clike 复制代码
root@autodl-container-616f40a3b3-41cb82d9:~# dpkg -l | grep postgresql
root@autodl-container-616f40a3b3-41cb82d9:~# 

按照上述步骤操作后,你应该已经成功卸载了通过apt-get安装的PostgreSQL 10.23版本。

相关推荐
了一li2 小时前
Qt中的QProcess与Boost.Interprocess:实现多进程编程
服务器·数据库·qt
码农君莫笑3 小时前
信管通低代码信息管理系统应用平台
linux·数据库·windows·低代码·c#·.net·visual studio
别致的影分身3 小时前
使用C语言连接MySQL
数据库·mysql
京东零售技术4 小时前
“慢”增长时代的企业数据体系建设:超越数据中台
数据库
sdaxue.com5 小时前
帝国CMS:如何去掉帝国CMS登录界面的认证码登录
数据库·github·网站·帝国cms·认证码
o(╥﹏╥)5 小时前
linux(ubuntu )卡死怎么强制重启
linux·数据库·ubuntu·系统安全
阿里嘎多学长6 小时前
docker怎么部署高斯数据库
运维·数据库·docker·容器
Yuan_o_6 小时前
Linux 基本使用和程序部署
java·linux·运维·服务器·数据库·后端
Sunyanhui16 小时前
牛客网 SQL36查找后排序
数据库·sql·mysql
老王笔记6 小时前
MHA binlog server
数据库·mysql