我正在设置我的 PostgreSQL 9.1。我不能用 PostgreSQL 做任何事情:不能 createdb
,不能 createuser
;所有操作都返回错误信息
Fatal: role h9uest does not exist
h9uest
是我的帐户名,我在此帐户下使用 sudo apt-get install
PostgreSQL 9.1。
root
帐户仍然存在类似错误。
FATAL: role "user" is not permitted to log in
,请检查 dba.stackexchange.com/questions/57723/…。
role doesn't exist
和错误 can't create role, it already exists
,请查看此答案:stackoverflow.com/a/56658832/1689770
使用 操作系统用户 postgres
创建您的数据库 - 只要您没有设置具有与您的操作系统用户对应的必要权限的 数据库 角色同名(在您的情况下为 h9uest
):
sudo -u postgres -i
然后再试一次。以系统用户 postgres
完成操作后,键入 exit
。
或执行单个命令 createuser
作为带有 sudo
的 postgres
,就像另一个答案中的 demonstrated by drees。
关键是使用与同名数据库角色匹配的操作系统用户通过 ident
authentication 授予访问权限。 postgres
是初始化数据库集群的默认操作系统用户。 The manual:
为了引导数据库系统,一个新初始化的系统总是包含一个预定义的角色。此角色始终是“超级用户”,默认情况下(除非在运行 initdb 时更改),它将与初始化数据库集群的操作系统用户同名。通常,这个角色将被命名为 postgres。为了创建更多角色,您首先必须作为这个初始角色进行连接。
我听说过使用非标准用户名或操作系统用户不存在的奇怪设置。你需要在那里调整你的策略。
阅读手册中的 database roles 和 client authentication。
在尝试了许多其他人的解决方案后,没有成功,这个答案终于帮助了我。
https://stackoverflow.com/a/16974197/2433309
简而言之,跑步
sudo -u postgres createuser owning_user
创建一个名为 owning_user 的角色(在本例中为 h9uest)。之后,您可以从终端以您设置的任何帐户名运行 rake db:create
,而无需进入 Postgres 环境。
-s
,并且不需要使用 sudo -u postgres
(只是 createuser new_user
工作正常)
psql: FATAL: role "jonny" does not exist
好吧sudo -u postgres -s createuser jonny
那么为什么createuser: creation of new role failed: ERROR: role "jonny" already exists
sudo su - postgres
psql template1
在 pgsql 上创建具有“超级用户”权限的角色
CREATE ROLE username superuser;
eg. CREATE ROLE demo superuser;
然后创建用户
CREATE USER username;
eg. CREATE USER demo;
为用户分配权限
GRANT ROOT TO username;
然后启用该用户的登录,这样您就可以从普通的 $
终端运行例如:psql template1
:
ALTER ROLE username WITH LOGIN;
CREATE ROLE username superuser createdb login;
,它结合了所有三个步骤......
sudo -u postgres createuser --superuser $USER; sudo -u postgres createdb $USER
#GRANT postgres TO username
这对我有用:
psql -h localhost -U postgres
postgres
(在 Linux 和 Windows 上测试)。
role postgres does not exist
psql -h hostname -U username -d database_name
使用 apt-get
安装 postgres 不会创建用户角色或数据库。
要为您的个人用户帐户创建超级用户角色和数据库:
sudo -u postgres createuser -s $(whoami); createdb $(whoami)
sudo -u postgres createdb $(whoami)
-s
标志),您可以自己创建数据库。您不需要将 createdb
作为 postgres
运行。
psql postgres
postgres=# CREATE ROLE username superuser;
postgres=# ALTER ROLE username WITH LOGIN;
psql postgres
个结果:psql: FATAL: role "root" does not exist
psql postgres -U postgres
?取决于您拥有的用户 (-U)。
对于 Postgres 9.5 版本,使用以下命令:
psql -h localhost -U postgres
希望这会有所帮助。
工作方法,
vi /etc/postgresql/9.3/main/pg_hba.conf local all postgres peer here change peer to trust restart, sudo service postgresql restart now try, psql -U postgres
trust
方法仅适用于完全安全的环境。虽然可以从不受信任的连接进行访问,但永远像这样公开您的数据库集群。
pg_hba.conf
有错误
对于 Windows 用户:psql -U postgres
您应该会看到 PostgreSQL 的命令行界面:postgres=#
在本地用户提示符下,而不是 root 用户提示符下,键入
sudo -u postgres createuser <local username>
然后输入本地用户的密码。
然后输入上一条生成“角色'用户名'不存在”的命令。
以上步骤为我解决了问题。如果没有,请发送上述步骤的终端消息。
我将它安装在 macOS 上,并且必须:
cd /Applications/Postgres.app/Contents/Versions/9.5/bin
createuser -U postgres -s YOURUSERNAME
createdb YOURUSERNAME
以下是来源:https://github.com/PostgresApp/PostgresApp/issues/313#issuecomment-192461641
我使用 docker-compose 进行了健康检查。
healthcheck:
test: ['CMD-SHELL', 'pg_isready']
interval: 5s
timeout: 5s
retries: 5
如果您也有更改用户:
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U postgres'] # <<<---
interval: 5s
timeout: 5s
retries: 5
在我的情况下,手动创建数据库集群解决了它。
出于某种原因,当我安装 postgres 时,没有创建“初始数据库”。执行 initdb
对我有用。
the PostgreSQL Wiki - First steps 中提供了此解决方案:
initdb 通常将 postgres 安装到您的操作系统会创建一个“初始数据库”并启动 postgres 服务器守护程序运行。如果没有,那么您需要运行 initdb
使用 --no-owner --no-privileges
标志转储和恢复
例如
转储 - pg_dump --no-owner --no-privileges --format=c --dbname=postgres://userpass:username@postgres:5432/schemaname > /tmp/full.dump
恢复 - pg_restore --no-owner --no-privileges --format=c --dbname=postgres://userpass:username@postgres:5432/schemaname /tmp/full.dump
对于那些使用 docker 并正确遵循官方文档说明的人,如果您仍然遇到此问题,请重新启动 windows 并重试。
请按照以下步骤操作,它将为您工作:
运行 msfconsole type db_console 一些信息会显示给你 选择告诉你做的信息: db_connect user:pass@host:port.../database 对不起我不记得了,但是就像这个然后替换用户和密码和主机和数据库以及包含在 emplacement 中 database.yml 中的信息:/usr/share/metasploit-framework/config 您将看到。在后台重建模型缓存。更新后键入 apt-get update && apt-get upgrade 重新启动终端并午餐 msfconsole 并且它可以通过键入 msfconsole: msf>db_status 来检查它是否已连接。
请按照以下步骤使 postgres 正常工作。
在您的终端中,使用以下命令找到 Application Support 文件夹。 /Users/[用户名]/library/application support 删除应用程序,Postgres。重新安装应用程序,它应该可以正常工作。
像将端口从 5432 更改为 5433 这样简单的事情对我有用。
不定期副业成功案例分享
sudo etc
... 如何安装程序?请参阅this S2geometry installation problem。su postgres
。sudo -u postgres
不起作用,而sudo -u postgres -i
起作用!-i
标志有什么作用?su
,但基于 sudo 权限。见man sudo
。-u
更改为-U
,我得到“无效选项 - 'i'”。