如何在 ubuntu 上彻底清除并重新安装 postgresql?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2748607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 22:29:37  来源:igfitidea点击:

How to thoroughly purge and reinstall postgresql on ubuntu?

postgresqlubuntuuninstallapt-get

提问by John Mee

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.

不知何故,我设法在 Ubuntu karmic 上完全破坏了 postgresql 的安装。我想从头开始,但是当我使用 apt-get “清除”软件包时,它仍然会留下痕迹,从而导致重新安装配置无法正常运行。

After I've done:

我完成后:

apt-get purge postgresql
apt-get install postgresql

It said

它说

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) ...

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/postgresql”,里面什么都没有,“/etc/postgresql-common/”有一个“pg_upgradecluser.d”目录和root.crt 和user_clusters 文件。

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.

/etc/passwd 有一个 postgres 用户;清除脚本似乎没有触及它。有一堆症状我解决了,只是为了暴露下一个。

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.

就在这一秒,当我运行该命令“pg_createcluster...”时,它抱怨“/var/lib/postgresql/8.4/main/postgresql.conf 不存在”,所以我会去找其中一个,但我会我相信这不会是它的结束。

Is there not some easy one-liner (or two) which will burn it completely and let me start over?

难道没有一些简单的单线(或两线)可以完全燃烧它并让我重新开始吗?

回答by John Mee

Option A

选项 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_dropcluster. 如果您只想使用新的 PostgreSQL 实例重新启动,请优先使用它而不是完全清除并重新安装。

$ 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

Option B

选项 B

If you really need to do a full purge and reinstall, first make sure PostgreSQL isn't running. ps -C postgresshould show no results.

如果你真的需要彻底清除并重新安装,首先确保 PostgreSQL 没有运行。ps -C postgres应该没有结果。

Now run:

现在运行:

apt-get --purge remove postgresql\*

to remove everything PostgreSQL from your system. Just purging the postgrespackage isn't enough since it's just an empty meta-package.

从您的系统中删除所有 PostgreSQL。仅仅清除postgres包是不够的,因为它只是一个空的元包。

Once all PostgreSQL packages have been removed, run:

删除所有 PostgreSQL 包后,运行:

rm -r /etc/postgresql/
rm -r /etc/postgresql-common/
rm -r /var/lib/postgresql/
userdel -r postgres
groupdel postgres

You should now be able to:

您现在应该能够:

apt-get install postgresql

or for a complete install:

或完整安装:

apt-get install postgresql-8.4 postgresql-contrib-8.4 postgresql-doc-8.4

回答by user9869932

I had a similar situation: I needed to purge postgresql 9.1 on a debian wheezy ( I had previously migrated from 8.4 and I was getting errors ).

我遇到了类似的情况:我需要在 debian wheezy 上清除 postgresql 9.1(我之前从 8.4 迁移并且出现错误)。

What I did:

我做了什么:

First, I deleted config and database

首先,我删除了配置和数据库

$ sudo pg_dropcluster --stop 9.1 main

Then removed postgresql

然后删除了postgresql

$ sudo apt-get remove --purge postgresql postgresql-9.1 

and then reinstalled

然后重新安装

$ sudo apt-get install postgresql postgresql-9.1

In my case I noticed /etc/postgresql/9.1 was empty, and running service postgresql startreturned nothing

就我而言,我注意到 /etc/postgresql/9.1 是空的,并且运行service postgresql start没有返回任何内容

So, after more googling I got to this command:

所以,经过更多的谷歌搜索后,我得到了这个命令:

$ sudo pg_createcluster 9.1 main

With that I could start the server, but now I was getting log-related errors. After more searching, I ended up changing permissions to the /var/log/postgresql directory

这样我就可以启动服务器,但现在我收到了与日志相关的错误。经过更多搜索,我最终更改了 /var/log/postgresql 目录的权限

$ sudo chown root.postgres /var/log/postgresql
$ sudo chmod g+wx /var/log/postgresql

That fixed the issue, Hope this helps

解决了这个问题,希望这有帮助

回答by Mithun Sreedharan

Steps that worked for me on Ubuntu 8.04.2to remove postgres 8.3

对我Ubuntu 8.04.2有用的删除步骤postgres 8.3

  1. List All Postgres related packages

    dpkg -l | grep postgres
    
    ii  postgresql                            8.3.17-0ubuntu0.8.04.1           object-relational SQL database (latest versi
    ii  postgresql-8.3                        8.3.9-0ubuntu8.04                object-relational SQL database, version 8.3
    ii  postgresql-client                     8.3.9-0ubuntu8.04                front-end programs for PostgreSQL (latest ve
    ii  postgresql-client-8.3                 8.3.9-0ubuntu8.04                front-end programs for PostgreSQL 8.3
    ii  postgresql-client-common              87ubuntu2                        manager for multiple PostgreSQL client versi
    ii  postgresql-common                     87ubuntu2                        PostgreSQL database-cluster manager
    ii  postgresql-contrib                    8.3.9-0ubuntu8.04                additional facilities for PostgreSQL (latest
    ii  postgresql-contrib-8.3                8.3.9-0ubuntu8.04                additional facilities for PostgreSQL
    
  2. Remove all above listed

    sudo apt-get --purge remove postgresql postgresql-8.3  postgresql-client  postgresql-client-8.3 postgresql-client-common postgresql-common  postgresql-contrib postgresql-contrib-8.3
    
  3. Remove the following folders

    sudo rm -rf /var/lib/postgresql/
    sudo rm -rf /var/log/postgresql/
    sudo rm -rf /etc/postgresql/
    
  1. 列出所有与 Postgres 相关的包

    dpkg -l | grep postgres
    
    ii  postgresql                            8.3.17-0ubuntu0.8.04.1           object-relational SQL database (latest versi
    ii  postgresql-8.3                        8.3.9-0ubuntu8.04                object-relational SQL database, version 8.3
    ii  postgresql-client                     8.3.9-0ubuntu8.04                front-end programs for PostgreSQL (latest ve
    ii  postgresql-client-8.3                 8.3.9-0ubuntu8.04                front-end programs for PostgreSQL 8.3
    ii  postgresql-client-common              87ubuntu2                        manager for multiple PostgreSQL client versi
    ii  postgresql-common                     87ubuntu2                        PostgreSQL database-cluster manager
    ii  postgresql-contrib                    8.3.9-0ubuntu8.04                additional facilities for PostgreSQL (latest
    ii  postgresql-contrib-8.3                8.3.9-0ubuntu8.04                additional facilities for PostgreSQL
    
  2. 删除上面列出的所有内容

    sudo apt-get --purge remove postgresql postgresql-8.3  postgresql-client  postgresql-client-8.3 postgresql-client-common postgresql-common  postgresql-contrib postgresql-contrib-8.3
    
  3. 删除以下文件夹

    sudo rm -rf /var/lib/postgresql/
    sudo rm -rf /var/log/postgresql/
    sudo rm -rf /etc/postgresql/
    

回答by Anish Menon

apt-get purge postgresql*

is enough.

足够。

回答by Klaas van Schelven

I know an answer has already been provided, but dselect didn't work for me. Here is what worked to find the packages to remove:

我知道已经提供了答案,但是 dselect 对我不起作用。以下是找到要删除的软件包的方法:

# search postgr  | grep ^i
i   postgresql                      - object-relational SQL database (supported 
i A postgresql-8.4                  - object-relational SQL database, version 8.
i A postgresql-client-8.4           - front-end programs for PostgreSQL 8.4     
i A postgresql-client-common        - manager for multiple PostgreSQL client ver
i A postgresql-common               - PostgreSQL database-cluster manager       

# aptitude purge postgresql-8.4 postgresql-client-8.4 postgresql-client-common postgresql-common postgresql

rm -r /etc/postgresql/
rm -r /etc/postgresql-common/
rm -r /var/lib/postgresql/

Finally, editing /etc/passwd and /etc/group

最后,编辑 /etc/passwd 和 /etc/group

回答by Gurudath BN

Following ae the steps i followed to uninstall and reinstall. Which worked for me.

按照ae卸载并重新安装所遵循的步骤。这对我有用。

First remove the installed postgres :-

首先删除已安装的 postgres :-

sudo apt-get purge postgr*

sudo apt-get autoremove

sudo apt-get purge postgr*

sudo apt-get autoremove

Then install 'synaptic':

然后安装“突触”:

sudo apt-get install synaptic

sudo apt-get update

sudo apt-get 安装突触

sudo apt-get 更新

Then install postgres

然后安装postgres

sudo apt-get install postgresql postgresql-contrib

sudo apt-get 安装 postgresql postgresql-contrib

回答by Jeromy French

I just ran into the same issue for Ubuntu 13.04. These commands removed Postgres 9.1:

我刚刚在 Ubuntu 13.04 上遇到了同样的问题。这些命令删除了 Postgres 9.1:

sudo apt-get purge postgresql
sudo apt-get autoremove postgresql

It occurs to me that perhaps only the second command is necessary, but from there I was able to install Postgres 9.2(sudo apt-get install postgresql-9.2).

我突然想到也许只有第二个命令是必要的,但是从那里我能够安装 Postgres 9.2(sudo apt-get install postgresql-9.2)。

回答by nivniv

I was following the replies, When editing /etc/group I also deleted this line:

我正在关注回复,在编辑 /etc/group 时我也删除了这一行:

ssl-cert:x:112:postgres

then, when trying to install postgresql, I got this error

然后,在尝试安装 postgresql 时,出现此错误

Preconfiguring packages ...
dpkg: unrecoverable fatal error, aborting:
 syntax error: unknown group 'ssl-cert' in statoverride file
E: Sub-process /usr/bin/dpkg returned an error code (2)

Putting the "ssl-cert:x:112:postgres" line back in /etc/group seems to fix it (so I was able to install postgresql)

将“ssl-cert:x:112:postgres”行放回 /etc/group 似乎可以解决它(所以我能够安装 postgresql)

回答by John Toppo

I was facing same problem in my ubuntu 16.04

我在 ubuntu 16.04 中遇到了同样的问题

but i fixed that problem and it's very simple just follow these step and you will be able to install postgresql 10 in your system :

但我解决了这个问题,很简单,只需按照以下步骤操作,您就可以在系统中安装 postgresql 10:

Add this to your sources.list:

将此添加到您的 sources.list:

sudo vim /etc/apt/sources.list

deb http://ftp.de.debian.org/debian/ wheezy main non-free contrib

deb-src http://ftp.de.debian.org/debian/ wheezy main non-free contrib

after that add these link to your pgdg.list file if it's not there you have to create && add link && save it.

之后,将这些链接添加到您的 pgdg.list 文件中,如果它不在那里,您必须创建 && 添加链接 && 保存它。

sudo vim /etc/apt/sources.list.d/pgdg.list

deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main

deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main

then update your system

然后更新你的系统

sudo apt-get update

sudo apt-get upgrade

and install that unmet dependencies :

并安装未满足的依赖项:

apt-get install ssl-cert

that's it. now Install postgresql using these command

就是这样。现在使用这些命令安装 postgresql

sudo apt-get install postgresql-10