postgresql 耙子中止!错误:必须是数据库的所有者
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7210563/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
rake aborted! ERROR: must be owner of database
提问by rixter
I am working through Michael Hartl's excellent tutorialbut when trying to prepare the test database with the command: bundle exec rake db:test:prepare I get this error message:
我正在阅读 Michael Hartl 的优秀教程,但是在尝试使用以下命令准备测试数据库时:bundle exec rake db:test:prepare 我收到此错误消息:
ERROR: must be owner of database sample_app_test...
错误:必须是数据库 sample_app_test 的所有者...
which I never got when using the development database, because I had created the following database role for my Rails app:
我在使用开发数据库时从未得到过,因为我为 Rails 应用程序创建了以下数据库角色:
CREATE ROLE demo_app WITH CREATEDB LOGIN
使用 CREATEDB 登录创建角色 demo_app
(this is using Postgresql)
(这是使用 Postgresql)
Does anyone understand why this is failing in the test environment? TIA...
有谁明白为什么这在测试环境中失败?蒂亚...
回答by Seth Malaki
Did you ensure the ownership of the test DB? try running the \l
command on Postgres console client and check the ownerships. you can also try the following query:
您是否确保了测试数据库的所有权?尝试\l
在 Postgres 控制台客户端上运行命令并检查所有权。您还可以尝试以下查询:
ALTER DATABASE sample_app_test OWNER TO demo_app;
ALTER DATABASE sample_app_test OWNER TO demo_app;
回答by LearningRuby
First post, writing this down for posterity. I was having the same problem but was able to fix it. You just have to make sure you were/are signed in as a superuser when you create your databases (or the one that is throwing the error).
第一篇文章,写下来供后人使用。我遇到了同样的问题,但能够解决它。您只需要确保在创建数据库(或引发错误的数据库)时以超级用户身份登录。
I was logging into psql with this code:
我正在使用以下代码登录 psql:
sudo sudo -u postgres psql
And created my databases. This is bad. You want to log in with these superuser credentials:
并创建了我的数据库。这很糟糕。您想使用这些超级用户凭据登录:
sudo su - postgres
And then after you're logged in to postgres:
然后在您登录到 postgres 之后:
psql
Then create your databases. You can kill your old databases with the command
然后创建您的数据库。您可以使用以下命令终止旧数据库
DROP DATABASE "database_to_drop";
Recreate them and you should be good to go!
重新创建它们,你应该很高兴!