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

查看:278
本文介绍了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/

I'm currently working on a tutorial: http://www.rosslaird.com/blog/building-a-project-with-mezzanine/

我被困在sudo -u postgres psql postgres

错误消息:psql: FATAL: role "postgres" does not exist

$其中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命令的输出:template0template1数据库上的user权限与我的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天全站免登陆