Can't connect to Postgres -- installing app on new machine

Hi, I am having trouble installing a phoenix umbrella app on a new machine.

I’ve run mix deps.get and also mix ecto.migrate (I had previously created
the database but have not populated it.) . I have also logged into the database
using psql -d koko_dev -U postgres. However, when I run
iex -S mix phx.server, I get the error message below. What to do???.

=ERROR REPORT==== 9-Jul-2017::00:48:43 ===
** Generic server <0.364.0> terminating 
** Last message in was nil
** When Server state == 'Elixir.Postgrex.Protocol'
** Reason for termination == 
** {{noproc,
        {'Elixir.GenServer',call,
            ['Elixir.Postgrex.TypeManager',
             {get,'Elixir.Ecto.Adapters.Postgres.TypeModule',
                 {"localhost",5432,<<"koko_dev">>}},
             5000]}},
    [{'Elixir.GenServer',call,3,[{file,"lib/gen_server.ex"},{line,596}]},
     {'Elixir.Postgrex.Protocol',bootstrap,3,
         [{file,"lib/postgrex/protocol.ex"},{line,621}]},
     {'Elixir.Postgrex.Protocol',handshake,2,
         [{file,"lib/postgrex/protocol.ex"},{line,475}]},
     {'Elixir.DBConnection.Connection',connect,2,
         [{file,"lib/db_connection/connection.ex"},{line,134}]},
     {'Elixir.Connection',enter_connect,5,
         [{file,"lib/connection.ex"},{line,622}]},
     {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]}
** (Mix) Could not start application koko_web: Koko.Web.Application.start(:normal, []) returned an error: shutdown: failed to start child: Koko.Web.Endpoint
    ** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Handler
        ** (EXIT) shutdown: failed to start child: {:ranch_listener_sup, Koko.Web.Endpoint.HTTP}

I don’t know if it is a typo, but You use kok_dev at psql, but the name is koko_dev at the adapter

Sorry! that was my typo … correcting it now.

If You do not have any data, maybe You can start checking with mix ecto.drop, and then mix ecto.create, mix ecto.migrate

Thanks, I will give that a try.

I tried mix.ecto.drop koko_dev, mix ecto.create koko_dev, and then mix.ecto.migrate. When I run iex -S mix phx.server, I get the same results as before:

** (Mix) Could not start application koko_web: Koko.Web.Application.start(:normal, []) returned an error: shutdown: failed to start child: Koko.Web.Endpoint
    ** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Handler
        ** (EXIT) shutdown: failed to start child: {:ranch_listener_sup, Koko.Web.Endpoint.HTTP}
            ** (EXIT) exited in: :gen_server.call(:ranch_server, {:set_new_listener_opts, Koko.Web.Endpoint.HTTP, 16384, [env: [dispatch: [{:_, [], [{["socket", "websocket"], [], Phoenix.Endpoint.CowboyWebSocket, {Phoenix.Transports.WebSocket, {Koko.Web.Endpoint, Koko.Web.UserSocket, :websocket}}}, {:_, [], Plug.Adapters.Cowboy.Handler, {Koko.Web.Endpoint, []}}]}]]]})
                ** (EXIT) no process

mix ecto.create, drop, migrate was just for testing postgresql access.

If it is working, then I am afraid I do not have enough information to help You.

OK, thanks though

My immediate thought is port in use? That is not a postgresql error…

I’ll look into that … yes, I am using ports and channels.

I do think that @OvermindDL1 isn’t talking about erlang/elixir ports, but rather TCP ports. Please make sure that you do not have any other application running which already bound to the port that your application tries to bind, also make sure you have the appropriate rights to actually use that port.

If you are unsure, please show us the configuration of your Endpoint and the output of netstat -lnpt (displays all programs which have an TCP port open for listening)

1 Like

The first error occurs because the :postgrex application isn’t started and the second error because :ranch isn’t started.

1 Like

Hi, I am back on this issue since my main machine just crashed again.
The netstat - lnpt command gives lots of output if I wait long enough.
Should I just grep for port 4000?

It should not be when you wait long enough, it should just show you a list of ports opened in “LISTEN” mode. Once. Also there shouldn’t be a space inbetween the hyphen and the lnpt. It wan’t there in my original post, but at least my fathers chrome did break the line between hyphen and lnpt, perhaps did yours as well?

And do not grep for anything. Just show us the output of that command netstat -lnpt (only space between netstat and -lnpt).

Also please give your HTTP AND Database configuration.

I am running the app from a freshly rebooted machine, so not too much should be running.

Here is the netstat output:

netstat -lnpt
netstat: t: unknown or uninstrumented protocol

The app is an umbrella app. In /apps there is koko and koko_web. Here are the contents of

koko/config.dev.exs

use Mix.Config

# Configure your database
config :koko, Koko.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: "postgres",
  password: "postgres",
  #url: "ecto://postgres:postgres@localhost/ecto_simple",
  database: "koko_dev",
  hostname: "localhost",
  pool_size: 10

koko/config/config.ex

use Mix.Config

config :koko, ecto_repos: [Koko.Repo]

import_config "#{Mix.env}.exs"

koko_web/config/config.exs

# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
#
# This configuration file is loaded before any dependency and
# is restricted to this project.
use Mix.Config

# General application configuration
config :koko_web,
  namespace: Koko.Web,
  ecto_repos: [Koko.Repo]

# Configures the endpoint
config :koko_web, Koko.Web.Endpoint,
  url: [host: "localhost"],
  secret_key_base: "xxxx",
  render_errors: [view: Koko.Web.ErrorView, accepts: ~w(json)],
  pubsub: [name: Koko.Web.PubSub,
           adapter: Phoenix.PubSub.PG2]

# Configures Elixir's Logger
config :logger, :console,
  format: "$time $metadata[$level] $message\n",
  metadata: [:request_id]

config :koko_web, :generators,
  context_app: :koko

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env}.exs"

koko_web/config/dev.exs

use Mix.Config

# For development, we disable any cache and enable
# debugging and code reloading.
#
# The watchers configuration can be used to run external
# watchers to your application. For example, we use it
# with brunch.io to recompile .js and .css sources.
config :koko_web, Koko.Web.Endpoint,
  http: [port: 4000],
  debug_errors: true,
  code_reloader: true,
  check_origin: false,
  watchers: []

Is the above what you need?
Thanks so much!

So you are on Mac? Dunno if there is an equivalent of my command given…

Http config should be in the config of your web sub app.

When you know the port used for http please try lsof -i :$PORT (substituting $PORT and keeping the colon).

From koko_web/config/dev.exs I see that the phoenix app is using port 4000.
I believe that on Mac OS, the lsof command you mentioned does the job:

$ lsof -n -i4TCP:4000
 $ lsof -n -i4TCP:3000
COMMAND   PID    USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
node    16957 carlson   15u  IPv4 0x872b0c97869ea4d1      0t0  TCP 127.0.0.1:hbci (LISTEN)

I have the client to phoenix app running on port 3000, and the output of the second command
confirms this. The output of the first command must mean that there is nothing running on port
4000.

A Further Test

I ran the following to create a small phoenix test app:

  259  mix phoenix.new web
  260  cd web
  261  mix ecto.create
  262  iex -S mix phoenix.server

The last command brought up the app with no problems. The test app is a regular phoenix app,
not an umbrella project.

Problem solved at last. Poking around, I realized that I had a version < 1.3
of Phoenix installed. I did this:

  272  mix archive.install https://github.com/phoenixframework/archives/raw/master/phoenix_new.ez
  273  pwd
  274  git clone git@github.com:jxxcarlson/koko.git
  275  ls
  276  cd koko
  277  mix deps.get
  278  mix ecto.migrate
  279  iex -S mix phx.server
/=> RUNNING OK

So sorry for the wild goose chase. I really appreciate your help.

1 Like