1

How do I find out what is my database's username in my local machine? I'm updating my database.yml file in my rails application, but anything I try isn't working.

When trying to use postgres (or other options such as mymacusername) I'm getting the following error:

FATAL:  role "postgres" does not exist

Do I need to create it? How? Or can I use an existing username on my computer?

Update: I am trying to create a user (this is soon after installation so the issue may be that it doesn't exist yet) I ran createuser -s -U $USER Name of role to add: postgres

But am getting the following error:

createuser: could not connect to database postgres: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

So this is the problem - How do I make it listen to the correct socket?

Lucy Weatherford
  • 5,452
  • 16
  • 50
  • 76

2 Answers2

1

if you have root access:

sudo -u postgres psql DATABASENAME

inside it type

\l

to show all databases and its users

Alive Developer
  • 1,022
  • 1
  • 13
  • 25
  • I have admin access. I tried that and got `sudo: unknown user: postgres` – Lucy Weatherford Apr 24 '13 at 07:59
  • try to look at [here](http://stackoverflow.com/questions/7863770/rails-and-postgresql-role-postgres-does-not-exist) – Alive Developer Apr 24 '13 at 08:23
  • Thanks, that seems to be the problem, but the solution isn't there - how can I find that socket and get it to listen to it? I am trying `sudo find / -name .s.PGSQL.5432 -ls` but not sure how to get postgres to talk to it – Lucy Weatherford Apr 24 '13 at 08:37
  • `netstat -nlp | grep postgre` . The listening port should be the last number. There should be more than 1 entries in the result – Alive Developer Apr 24 '13 at 08:44
  • `netstat: option requires an argument -- p` – Lucy Weatherford Apr 24 '13 at 08:56
  • `Usage: netstat [-AaLlnW] [-f address_family | -p protocol] netstat [-gilns] [-f address_family] netstat -i | -I interface [-w wait] [-abdgRt] netstat -s [-s] [-f address_family | -p protocol] [-w wait] netstat -i | -I interface -s [-f address_family | -p protocol] netstat -m [-m] netstat -r [-Aaln] [-f address_family] netstat -rs [-s]` – Lucy Weatherford Apr 24 '13 at 09:04
  • mmm because you're on osx and i'm on linux. try `netstat -l | grep PGSQL` – Alive Developer Apr 24 '13 at 09:12
  • Okay yes, I get the listening port - /tmp/.s.PGSQL.5432 but how do I get the database to talk to it? – Lucy Weatherford Apr 24 '13 at 09:18
  • Btw I just posted this as a new question regarding the socket here: http://dba.stackexchange.com/questions/40770/postgresql-socket-not-listening-on-the-right-one – Lucy Weatherford Apr 24 '13 at 09:19
  • @LucyWeatherford, you can set the host to the absolute path to the directory of the socket (in this case host = /tmp). Not very intuitive but it works. – Chris Travers May 21 '13 at 01:55
0

We simply need to create postgres role. Commands to create a role name postgres: 1.sudo -u postgres psql 2.CREATE ROLE postgres WITH SUPERUSER CREATEDB CREATEROLE LOGIN ENCRYPTED PASSWORD 'password'