如何在 ubuntu 上彻底清除并重新安装 postgresql? [英] How to thoroughly purge and reinstall postgresql on ubuntu?

查看:47
本文介绍了如何在 ubuntu 上彻底清除并重新安装 postgresql?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知何故,我已经成功地在 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?

推荐答案

Option 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 包是不够的,因为它只是一个空的元包.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆