如何在ubuntu上彻底清除并重新安装postgresql? [英] How to thoroughly purge and reinstall postgresql on ubuntu?
问题描述
以某种方式,我已经设法完全在Ubuntu karmic上破解了postgresql的安装.我想从头开始,但是当我使用apt-get清除"软件包时,它仍然留下痕迹,以致重新安装配置无法正常运行.
Somehow I've managed to completely bugger the install of postgresql on Ubuntu karmic. I want to start over from scratch, but when I "purge" the package with apt-get it still leaves traces behind such that the reinstall configuration doesn't run properly.
完成后:
apt-get purge postgresql
apt-get install postgresql
说
Setting up postgresql-8.4 (8.4.3-0ubuntu9.10.1) ...
Configuring already existing cluster (configuration: /etc/postgresql/8.4/main, data: /var/lib/postgresql/8.4/main, owner: 108:112)
Error: move_conffile: required configuration file /var/lib/postgresql/8.4/main/postgresql.conf does not exist
Error: could not create default cluster. Please create it manually with
pg_createcluster 8.4 main --start
or a similar command (see 'man pg_createcluster').
update-alternatives: using /usr/share/postgresql/8.4/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) in auto mode.
Setting up postgresql (8.4.3-0ubuntu9.10.1) ...
我有一个"/etc/postgresql",里面没有任何内容,"/etc/postgresql-common/"有一个"pg_upgradecluser.d"目录以及root.crt和user_clusters文件.
I have a "/etc/postgresql" with nothing in it and "/etc/postgresql-common/" has a 'pg_upgradecluser.d' directory and root.crt and user_clusters files.
/etc/passwd有一个postgres用户;清除脚本似乎没有碰到它.有很多症状我只能通过暴露来解决.
The /etc/passwd has a postgres user; the purge script doesn't appear to touch it. There's been a bunch of symptoms which I work through only to expose the next.
此刻,当我运行该命令"pg_createcluster ..."时,它抱怨"/var/lib/postgresql/8.4/main/postgresql.conf不存在",因此我将查找其中之一但我相信这不会结束.
Right this second, when I run that command "pg_createcluster..." it complains that '/var/lib/postgresql/8.4/main/postgresql.conf does not exist', so I'll go find one of those but I'm sure that won't be the end of it.
难道没有简单的一线(或两线)将其完全烧掉并让我重新开始吗?
Is there not some easy one-liner (or two) which will burn it completely and let me start over?
推荐答案
选项A
如果安装尚未损坏,则可以使用pg_dropcluster
删除不需要的PostgreSQL服务器(群集").如果您只想使用新的PostgreSQL实例重新启动,则优先使用该选项进行完全清除并重新安装.
Option A
If your install isn't already damaged, you can drop unwanted PostgreSQL servers ("clusters") using pg_dropcluster
. Use that in preference to a full purge and reinstall if you just want to restart with a fresh PostgreSQL instance.
$ pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
11 main 5432 online postgres /var/lib/postgresql/11/main /var/log/postgresql/postgresql-11-main.log
$ sudo systemctl stop postgresql@11-main
$ sudo pg_dropcluster --stop 11 main
$ sudo pg_createcluster --start 11 main
选项B
如果您确实需要进行完全清除并重新安装,请首先确保PostgreSQL未运行. ps -C postgres
应该没有显示结果.
Option B
If you really need to do a full purge and reinstall, first make sure PostgreSQL isn't running. ps -C postgres
should show no results.
现在运行:
apt-get --purge remove postgresql\*
从系统中删除所有PostgreSQL.仅清除postgres
软件包是不够的,因为它只是一个空的meta软件包.
to remove everything PostgreSQL from your system. Just purging the postgres
package isn't enough since it's just an empty meta-package.
一旦所有PostgreSQL软件包都被删除,请运行:
Once all PostgreSQL packages have been removed, run:
rm -r /etc/postgresql/
rm -r /etc/postgresql-common/
rm -r /var/lib/postgresql/
userdel -r postgres
groupdel postgres
您现在应该能够:
apt-get install postgresql
或进行完整安装:
apt-get install postgresql-8.4 postgresql-contrib-8.4 postgresql-doc-8.4
这篇关于如何在ubuntu上彻底清除并重新安装postgresql?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!