postgresql psql:致命:角色“流浪者”不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21801837/
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
psql: FATAL: role "vagrant" does not exist
提问by LogicLooking
I created a vagrant instance and I am getting this error every time I try and do psql
in the terminal How would Fix it. the error is as states:
我创建了一个 vagrant 实例,每次我尝试psql
在终端中执行时都会收到此错误如何修复它。错误如下:
psql: FATAL: role "vagrant" does not exist
psql:致命:角色“流浪者”不存在
I thought vagrant takes care of this? This is my vagrant file:
我以为流浪汉会照顾这个?这是我的流浪文件:
Vagrant.require_plugin "vagrant-omnibus"
Vagrant.require_plugin "vagrant-berkshelf"
Vagrant.configure(2) do |config|
# Box config
config.vm.box = 'precise64'
config.vm.box_url = 'http://files.vagrantup.com/precise64.box'
# Plugin config
config.omnibus.chef_version = :latest
config.berkshelf.enabled = true
# Network config
config.vm.network :forwarded_port, guest: 3000, host: 3000
# Virtual config
config.vm.provider(:virtualbox) do |vb|
vb.customize [
"modifyvm", :id,
"--memory", "1024",
"--cpus", "4"
]
end
# Provisioner config
config.vm.provision :chef_solo do |chef|
chef.add_recipe 'apt'
chef.add_recipe 'postgresql::client'
chef.add_recipe 'postgresql::server'
chef.add_recipe 'build-essential'
chef.add_recipe 'rvm::system'
chef.add_recipe 'git'
chef.json = {
:postgresql => {
:version => '9.3'
},
"postgresql" => {
"password" => {
"postgres" => "kshgfi3ret3hihjfbkivtbo3ity835"
}
},
"database" => {
"create" => ["aisisplatform"]
},
:git => {
:prefix => "/usr/local"
},
:rvm => {
'rubies' => [ 'ruby-2.1.0' ],
'default_ruby' => 'ruby-2.1.0',
'vagrant' => {
:system_chef_solo => '/usr/bin/chef-solo'
}
},
}
end
end
回答by ivalkeen
You don't have vagrant
user in postgres, and when you run psql
, it tries to login as vagrant
user (the same name as OS user). You may try something like:
你vagrant
在 postgres 中没有用户,当你运行时psql
,它尝试以vagrant
用户身份登录(与操作系统用户同名)。您可以尝试以下操作:
psql -U postgres -h localhost
to login as postgres
user, with password specified in your Vagrantfile for postgresq
user.
以postgres
用户身份登录,并在您的 Vagrantfile 中为postgresq
用户指定密码。
Then, you have several options:
然后,您有几个选择:
Export
PGUSER
andPGHOST
environment variablesto set user and host (psql
without parameters will use these values). You may also want to use .pgpassfile to avoid entering password on eachpsql
execute.Modify Vagrantfile to create
vagrant
user in postgres with password