2013-03-23 159 views
11

我在Ubuntu 12.04服务器上,我试图安装postgresql。截至目前,我已成功安装它,但无法配置它。我需要创建一个角色,向前迈进,我跑在终端命令:无法创建用户postgres:角色“postgres”不存在

[email protected]: createuser -s -r postgres

,它说:

createuser: could not connect to database postgres: FATAL: role "root" does not exist

很好,所以我所做的:

su - postgres

然后再试一次

[email protected]: createuser -s -r postgres

,我得到了错误

createuser: could not connect to database postgres: FATAL: role "postgres" does not exist

,我也得到了同样的错误,当我做

psql -d dbname

它像一个循环,我无法创建角色postgres,因为角色postgres尚不存在。

我该如何解决这个问题?

Postgres的版本似乎是9.1.x和Ubuntu的版本是12.10

+0

'sudo pg_lsclusters'的输出是什么? – 2013-03-24 10:00:10

+0

@ A.H。未找到命令'pg_lsclusters'。它要求我安装'postgresql-common'软件包。我尝试以root用户身份执行操作,但出现错误。它尝试删除'postgres-xc'和'dpkg:error处理postgres-xc(--remove):'然后退出。 – ktkaushik 2013-03-24 12:11:46

回答

9

原来我在我的机器上安装了postgres-xcpostgresql。我不得不彻底关闭postgres-xc。这样做有点困难,因为总是出现错误--purge remove postgres-xc,卸载无法继续。

似乎有某种包装错误。 (details on launchpad)。

最后,我最终做了this使它工作。

之后,我卸载postgresql并安装回它使其工作。

+0

我有类似的问题。卸载postgresql时,确保停止所有postgres进程,删除unix用户'postgres',并删除'/ var/run/postgresql'中的锁定文件。 – osa 2014-05-29 23:21:13

+0

@SergeyOrshanskiy谢谢你。我记得我最终通过做你说的很多东西来解决问题。 :) – ktkaushik 2014-05-30 13:06:10

+1

postgres-xc显然搞砸了我的postgres设置。同样的解决方案为我工作! – 2014-09-20 20:20:21

1

postgresql tutorial如果是Ubuntu或者其它Linux也没关系。

编辑 在创建角色或全新安装之前,您需要创建数据库集群:是否创建了它?

initdb -D /usr/local/pgsql/data 

您需要在linux机器上以用户postgres的身份登录。 Here是更多信息。

+0

是的。我正在执行这些步骤,但我无法创建用户。 “postgres”角色不存在以创建“postgres”角色。多数民众赞成在混淆我。任何想法 ? – ktkaushik 2013-03-24 05:49:53

+0

@Ladislav:Debian(也就是Ubuntu)具有用于管理PostgreSQL数据库和集群的自定义脚本和约定。使用普通的PG命令会造成更多的伤害。特别是对于非专家。 – 2013-03-24 09:58:16

+0

@ A.H。不知道debian和ubuntu,我使用slackware。 'initdb'你不会损害你的安装,它是用来创建数据库集群的。它会在'/ usr/local/pgsql/data'中创建文件,如果出现问题,您可以将其删除并从头开始。 – 1ac0 2013-03-24 10:09:31