postgresql PG::ConnectionBad 致命:角色“Myname”不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23338356/
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
PG::ConnectionBad FATAL: role "Myname" does not exist
提问by user3408293
I am trying to use PostgreSQL so that I can deploy to Heroku. However I cannot run localhost anymore why? I get the following message:
我正在尝试使用 PostgreSQL,以便可以部署到 Heroku。但是我不能再运行 localhost 为什么了?我收到以下消息:
PG::ConnectionBad
FATAL: role "Myname" does not exist
Here is my databse.yml
这是我的databse.yml
development:
adapter: postgresql
database: my_database_development
pool: 5
timeout: 5000
test:
adapter: postgresql
database: my_database_test
pool: 5
timeout: 5000
production:
adapter: postgresql
database: my_database_production
pool: 5
timeout: 5000
Here is my gemfile:
这是我的 gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.3'
# Use pg as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
gem 'rails_12factor', group: :production
It seems that pg needs me to create a user or databse however I am unable to or don't know how. Couldn't find any commands that worked for me(I'm on a windows btw)
似乎 pg 需要我创建用户或数据库,但是我无法或不知道如何创建。找不到任何对我有用的命令(顺便说一句,我在 Windows 上)
What can I do?
我能做什么?
采纳答案by user3408293
I had to go into my PG admin dashboard and create a db/user there. Unfrotunately it was in a subdirectory different from what the tutorials online said(probably updated directory destination last update). Fortunately I was able to find it and create the table/user there, update my database.yml file and then my app was able to work!
我必须进入我的 PG 管理仪表板并在那里创建一个 db/user。不幸的是,它位于与在线教程所说的不同的子目录中(可能是上次更新的目录目标更新)。幸运的是,我能够找到它并在那里创建表/用户,更新我的 database.yml 文件,然后我的应用程序就可以工作了!
回答by errakeshpd
The error is "role "Myname" does not exist",
错误是“角色“我的名字”不存在”,
create the user "Myname" for Postgresql
为 Postgresql 创建用户“Myname”
sudo -u postgres createuser --superuser Myname
sudo -u postgres createuser --superuser 我的名字
it will solve this issue.
它将解决这个问题。
回答by Meekohi
What worked for me was: createuser -P -d -e Myname
.
什么工作对我来说是:createuser -P -d -e Myname
。
-P If given, createuser will issue a prompt for the password of the new user.
This is not necessary if you do not plan on using password authentication.
-d The new user will be allowed to create databases.
-e Echo the commands that createuser generates and sends to the server.
If you install Postgresql with homebrew on OSX, there is no default postgres
user, and you won't be able to use psql
directly without setting up a user first.
如果你在 OSX 上用 homebrew 安装 Postgresql,没有默认postgres
用户,如果不先设置用户,你将无法psql
直接使用。
回答by manu29.d
On Windows, I believe it is a little easier.
在 Windows 上,我相信它更容易一些。
Install postgresql and PGAdmin for your system. See this
为您的系统安装 postgresql 和 PGAdmin。看到这个
Create a user named postgres and give it a password. You will be nicely prompted to do this.
创建一个名为 postgres 的用户并为其提供密码。系统会很好地提示您执行此操作。
Then, when you want to create databases, just right click on your connection and choose New Database. The names of these databases should correspond to what is written in your database.yml
然后,当您想要创建数据库时,只需右键单击您的连接并选择新建数据库。这些数据库的名称应与您的database.yml
Run rake db:migrate RAILS_ENV=development
(development| test| production).
运行rake db:migrate RAILS_ENV=development
(开发|测试|生产)。
These steps worked for me.
这些步骤对我有用。
回答by Pavan
You should create a username
and password
for your Postgresql
你应该创建一个username
和password
你Postgresql
Try creating a user with password in psql
尝试使用密码创建用户 psql
CREATE USER Myname WITH PASSWORD 'your_password';
And your should add those to your database.yml
as
你应该将这些添加到你的database.yml
as
username: Myname
password: your_password
回答by Addicted
@user3408293
@用户3408293
After the installation create a user for postgresql
sudo -u postgres createuser --superuser $USER
sudo -u postgres createuser pgs_root
Set user password for the postgresql user
sudo -u postgres psql postgres
( For psql prompt) postgres=# \passsword for ex.- postgres=# \passsword pgs_root
安装后为 postgresql 创建一个用户
sudo -u postgres createuser --superuser $USER
sudo -u postgres createuser pgs_root
为 postgresql 用户设置用户密码
sudo -u postgres psql postgres
(对于 psql 提示) postgres=# \passsword 例如- postgres=# \passsword pgs_root
N.B You should also add username and password to different environments in database.yml file.
注意您还应该在 database.yml 文件中将用户名和密码添加到不同的环境中。
You can also refer this link: Rails: Error installing pg gem
您也可以参考此链接:Rails:安装 pg gem 时出错