当前位置: 代码网 > it编程>数据库>MsSqlserver > 卸载apt-get安装的PostgreSQL版本实现

卸载apt-get安装的PostgreSQL版本实现

2026年05月07日 MsSqlserver 我要评论
卸载通过apt-get安装的postgresql 就版本,可以按照以下步骤进行。查找已安装的postgresql包在卸载之前,建议先查找并确认已安装的postgresql包及其版本。可以使用以下命令来

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

查找已安装的postgresql包

在卸载之前,建议先查找并确认已安装的postgresql包及其版本。
可以使用以下命令来查找与postgresql相关的所有已安装包:

dpkg -l | grep postgresql

例:

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

sudo apt-get --purge remove postgresql*

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

例:

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/(数据文件)目录。

例:

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已经被成功卸载。

root@autodl-container-616f40a3b3-41cb82d9:~# dpkg -l | grep postgresql
root@autodl-container-616f40a3b3-41cb82d9:~# 

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

到此这篇关于卸载apt-get安装的postgresql版本实现的文章就介绍到这了,更多相关postgresql apt-get卸载内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2026  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com