11

I'm getting an error when trying to create a database. I have postgres installed and I've already made a few test projects successfully. And, I've not seen this error. Any help would be great:

ERROR:

 ~/Desktop/elixir/restore $ mix ecto.create
** (Mix) The database for Restore.Repo couldn't be created: tcp connect: connection refused - :econnrefused

21:52:23.978 [error] GenServer #PID<0.150.0> terminating
** (Postgrex.Error) tcp connect: connection refused - :econnrefused
    (db_connection) lib/db_connection/connection.ex:148: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:623: Connection.enter_connect/5
    (stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
Afshin Moazami
  • 2,092
  • 5
  • 33
  • 55
Bitwise
  • 8,021
  • 22
  • 70
  • 161
  • What ecto's version are you using? – TheAnh Jul 19 '16 at 02:14
  • 2
    Is postgresql running? – Dogbert Jul 19 '16 at 04:08
  • 1
    Debugging postgres is going to be hard via stack overflow because it generally has to do with your specific setup. You need to figure out 2 things really, is postgres running, and what are your credentials which can sometimes depend on the way you installed postgres. Once you've figured out those two out, put the correct credentials in your phoenix config and try again. – greggreg Jul 19 '16 at 04:51
  • 2
    if you have a default user of `postgres` which is common, you can run `psql --username=postgres` from a terminal. If it connects, you have postgres running and know your creds. If it doesn't, there's a good place to start. – greggreg Jul 19 '16 at 05:27

2 Answers2

12

I had same problem today when tried to run mix ecto.create. So first make sure you have postgres. recommend using brew to install it.

brew install postgres

use brew services to start/stop postgresql,

create a database,

create postgres superuser,

probably you will need to give permission on folders.

these links were useful to me :

psql: FATAL: role "postgres" does not exist

psql: FATAL: database "<user>" does not exist

Community
  • 1
  • 1
Alejandro
  • 270
  • 2
  • 12
6

I had the same issue, and the problem was that postgres was not running.

so, to check this, you should run :

brew services list

and then, if you see :

Name Status User Plist postgresql stopped

you should run :

brew services start postgresql

cheers!

Dhia
  • 10,119
  • 11
  • 58
  • 69
Neri Martinez
  • 99
  • 1
  • 5