psql:致命:角色“无用”不存在
我创建了一个无所事事的实例,每次尝试在终端中执行 psql
时都会遇到此错误。错误状态如下:
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:
psql:致命:角色 vagrant不存在
psql: FATAL: role "vagrant" does not exist
我以为无所事事照顾这个?这是我的流浪者文件:
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
您在postgres中没有 vagrant
用户,以及何时您运行 psql
时,它将尝试以 vagrant
用户(与OS用户相同的名称)登录。您可以尝试以下操作:
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:
psql -U postgres -h localhost
以 postgres
用户身份登录,并在您的Vagrantfile中为 postgresq
用户。
to login as postgres
user, with password specified in your Vagrantfile for postgresq
user.
然后,您有几种选择:
Export
PGUSER
andPGHOST
environment variables to set user and host (psql
without parameters will use these values). You may also want to use .pgpass file to avoid entering password on eachpsql
execute.
修改Vagrantfile以创建 vagrant
用户在带密码的postgres中
Modify Vagrantfile to create vagrant
user in postgres with password