psql:致命:角色“postgres";不存在 [英] psql: FATAL: role "postgres" does not exist

查看:60
本文介绍了psql:致命:角色“postgres";不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 postgres 新手.

I'm a postgres novice.

我为 Mac 安装了 postgres.app.我在玩 psql 命令时不小心删除了 postgres 数据库.我不知道里面有什么.

I installed the postgres.app for mac. I was playing around with the psql commands and I accidentally dropped the postgres database. I don't know what was in it.

我目前正在编写教程:http://www.rosslaird.com/blog/building-a-project-with-mezzanine/

我被困在 sudo -u postgres psql postgres

错误消息:psql:致命:角色postgres"不存在

$ 哪个 psql

/Applications/Postgres.app/Contents/MacOS/bin/psql

这是psql -l

                                List of databases
    Name    |   Owner    | Encoding | Collate | Ctype |     Access privileges     
------------+------------+----------+---------+-------+---------------------------
 user       | user       | UTF8     | en_US   | en_US | 
 template0  | user       | UTF8     | en_US   | en_US | =c/user                  +
            |            |          |         |       | user      =CTc/user      
 template1  | user       | UTF8     | en_US   | en_US | =c/user                  +
            |            |          |         |       | user      =CTc/user      
(3 rows)

那么我应该采取哪些步骤?删除与 psql 相关的所有内容并重新安装所有内容?

So what are the steps I should take? Delete an everything related to psql and reinstall everything?

感谢大家的帮助!

推荐答案

注意:如果您使用自制软件安装了 postgres,请参阅下面来自 @user3402754 的评论.

NOTE: If you installed postgres using homebrew, see the comment from @user3402754 below.

请注意,错误消息不是谈论缺少的数据库,而是谈论缺少的角色.在登录过程的后期,它也可能会偶然发现丢失的数据库.

Note that the error message does NOT talk about a missing database, it talks about a missing role. Later in the login process it might also stumble over the missing database.

但第一步是检查缺少的角色:命令 dupsql 内的输出是什么?在我的 Ubuntu 系统上,相关行如下所示:

But the first step is to check the missing role: What is the output within psql of the command du ? On my Ubuntu system the relevant line looks like this:

                              List of roles
 Role name |            Attributes             | Member of 
-----------+-----------------------------------+-----------
 postgres  | Superuser, Create role, Create DB | {}        

如果superuser 没有至少一个角色,那么你就有问题了:-)

If there is not at least one role with superuser, then you have a problem :-)

如果有的话,你可以用它来登录.并查看 l 命令的输出: usertemplate0template1 数据库的权限是与我的 Ubuntu 系统上的超级用户 postgres 相同.所以我认为您的设置简单使用 user 作为超级用户.所以你可以试试这个命令登录:

If there is one, you can use that to login. And looking at the output of your l command: The permissions for user on the template0 and template1 databases are the same as on my Ubuntu system for the superuser postgres. So I think your setup simple uses user as the superuser. So you could try this command to login:

sudo -u user psql user

如果 user 确实是数据库超级用户,您可以为他创建另一个数据库超级用户和一个私有的空数据库:

If user is really the DB superuser you can create another DB superuser and a private, empty database for him:

CREATE USER postgres SUPERUSER;
CREATE DATABASE postgres WITH OWNER postgres;

但是由于您的 postgres.app 设置似乎没有这样做,您也不应该这样做.简单改编教程.

But since your postgres.app setup does not seem to do this, you also should not. Simple adapt the tutorial.

这篇关于psql:致命:角色“postgres";不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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