11

I have been trying to set up vagrant but I am getting this error. I will list out my installation method. Please suggest changes where you feel they are needed.

-Installed virtual box
sudo apt-get install virtual box

-Downloaded .deb package from vagrant website

-Installed it using
sudo dpkg -i (package_name)

-then I selected the vagrant folder in the fullstack folder and
vagrant up
vagrant ssh

then I did :
vagrant@vagrant-ubuntu-trusty-32: cd /vagrant/forum vagrant@vagrant-ubuntu-trusty-32:/vagrant/forum$ sudo apt-get install postgresql-client-common vagrant@vagrant-ubuntu-trusty-32:/vagrant/forum$ sudo apt-get install postgres-xc-client

Then finally:
vagrant@vagrant-ubuntu-trusty-32:/vagrant/forum$ psql psql: FATAL: role "vagrant" does not exist

Rob
  • 14,746
  • 28
  • 47
  • 65
Siddhant Loya
  • 121
  • 1
  • 1
  • 5
  • Sure, you haven't set up a Postgres role that corresponds to your current user (which is `vagrant`). http://www.postgresql.org/docs/9.3/static/user-manag.html – Oliver Charlesworth May 24 '15 at 13:09
  • Possible duplicate of [PostgreSQL error: Fatal: role "username" does not exist](https://stackoverflow.com/questions/11919391/postgresql-error-fatal-role-username-does-not-exist) – arkhi Sep 21 '18 at 19:17
  • VAGRANT SUPPORT IS OFF-TOPIC. Support questions may be asked on https://superuser.com – Rob Nov 04 '22 at 11:03

4 Answers4

23

You need to change to the postgres user and give vagrant superuser access.

sudo su - postgres
createuser vagrant -s
exit  # exit from postgres user back into vagrant

You can do everything with with vagrant now.

Sam Eaton
  • 1,795
  • 1
  • 14
  • 19
  • 3
    If provisioning a bash file script for installing the host, the following seems to work better when used inside the script: `sudo -u postgres createuser vagrant -s && sudo -u postgres createdb vagrant` – sveilleux2 Mar 11 '17 at 19:51
  • Thanks a lot. It worked perfectly for me. For a novice like me, maybe it will help to mention that the above commands need to be entered after you have ssh (ed) into your Linux/ubuntu terminal – Donzoby May 16 '22 at 12:15
8

This is happening because there is no role specified in postgres. When there is no role specified, it tries to use the username of the account as the default role and hence your error. So, now, you could either create a role in postgres for the vagrant user or just use the postgres user itself. So, first, login with the postgres user:

psql -U postgres

then, create a role for the user vagrant

CREATE ROLE vagrant LOGIN;

In case, if you want it with a password, use:

CREATE USER vagrant WITH PASSWORD 'password';

or

CREATE ROLE vagrant WITH LOGIN PASSWORD 'password';

CREATE USER is the same as CREATE ROLE with the exception that USER implies LOGIN.

Source

Sid Shukla
  • 990
  • 1
  • 8
  • 33
  • `vagrant@vagrant-ubuntu-trusty-32:/$ psql -U postgres psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"? vagrant@vagrant-ubuntu-trusty-32:/$ ` – Siddhant Loya May 24 '15 at 13:32
  • try 'sudo service postgres restart' – Sid Shukla May 24 '15 at 13:41
  • `postgres: unrecognized service` – Siddhant Loya May 24 '15 at 13:48
  • sudo apt-get update; sudo apt-get install postgresql postgresql-contrib; and then repeat the steps in the answer. Looks like a postgres installation issue. – Sid Shukla May 24 '15 at 13:59
  • After I run `psql -U postgres` it gives this error: `psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?` – Siddhant Loya May 25 '15 at 04:51
0

You are trying to connect to postgresql using vagrant user. In this case, postgresql y looking for the corresponding vagrant role (if not specified, the default role for a user is it's username). However, looks like there is no such role created.

You can create the role, or try for example a login using the postgres user:

vagrant@vagrant-ubuntu-trusty-32:/vagrant/forum$ psql -U postgres

You can also specify the databasename you want to connect to:

vagrant@vagrant-ubuntu-trusty-32:/vagrant/forum$ psql -U postgres -d DATABASENAME
Federico Cristina
  • 2,203
  • 1
  • 19
  • 37
0

1)First exit the vagrant prompt

exit

2) Halt the vagrant instance

vagrant halt

3)Destroy the vagrant instance

vagrant destroy

4)Create a new instance

vagrant up

This might solve it. It atleast did for me.(Tried it)

  • 1
    This feels a bit too much like "turn it off and turn it back on again" . I get that that often works, but a useful answer really should help with understanding the problem – Mark Weston Jan 13 '20 at 11:29