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: 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
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
to login as postgres
user, with password specified in your Vagrantfile for postgresq
user.
Then, you have several options:
Export PGUSER
and PGHOST
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 each psql
execute.
Modify Vagrantfile to create vagrant
user in postgres with password