Createuser:无法连接到数据库postgres:FATAL:角色“ tom”已创建。不存在 [英] Createuser: could not connect to database postgres: FATAL: role "tom" does not exist
问题描述
我正在尝试首次设置Postgres,我需要创建一个具有读取和创建数据库权限的用户。但是,当我在终端中使用 createuser用户名时,得到以下消息:
I'm trying to set up Postgres for the first time, and I need to create a user with permissions to read and create databases. However, when I use "createuser username" in my terminal I get the following message:
createuser:无法连接到数据库postgres:FATAL :角色 tom不存在
createuser: could not connect to database postgres: FATAL: role "tom" does not exist
Tom是我现在登录的Ubuntu用户帐户。我正在尝试创建一个用户名 postgres,然后执行一个 psql -U psql template1,这样我就可以为我的Rails应用创建数据库并为其分配一个所有者。
Tom is my Ubuntu user account that I'm logged into right now. I'm trying to create a username of "postgres" then do a "psql -U psql template1" so I can create a database and assign an owner to it for my Rails app.
有帮助吗?
推荐答案
您提到了Ubuntu,所以我
You mentioned Ubuntu so I'm going to guess you installed the PostgreSQL packages from Ubuntu through apt.
如果是这样,则 postgres
PostgreSQL用户帐户已经安装了存在,并配置为通过 pg_hba.conf
中的unix套接字通过 peer
身份验证可访问。您可以通过以 postgres
Unix用户身份运行命令来进行操作,例如:
If so, the postgres
PostgreSQL user account already exists and is configured to be accessible via peer
authentication for unix sockets in pg_hba.conf
. You get to it by running commands as the postgres
unix user, eg:
sudo -u postgres createuser owning_user
sudo -u postgres createdb -O owning_user dbname
这一切都在 Ubuntu PostgreSQL 文档中,这是Google首次针对 Ubuntu PostgreSQL发行,并且涉及在很多堆栈溢出问题中。
This is all in the Ubuntu PostgreSQL documentation that's the first Google hit for "Ubuntu PostgreSQL" and is covered in numerous Stack Overflow questions.
(通过省略诸如操作系统和版本等详细信息,您已经使这个问题很难回答。您安装了PostgreSQL等)。
这篇关于Createuser:无法连接到数据库postgres:FATAL:角色“ tom”已创建。不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!