How can I specify a custom server port for the mix ecto.create
command in Phoenix framework?
I created a get-started project with the mix phx.new hello
command.
I configured the database as follows in hello\config\dev.exs
path,
config :hello, Hello.Repo,
username: "postgres",
password: "postgres",
hostname: "localhost",
database: "hello_dev",
show_sensitive_data_on_connection_error: true,
pool_size: 10
However, when I try to configure a Postgres database with the mix ecto.create
command, I get the following error.
** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
I use 5433 as the Postgres port (Note: it works with my spring java projects) because the default port of 5432 was not available in my local.
So in hello\deps\ecto_sql\lib\ecto\adapters\postgres\connection.ex
path
I defined the default port in the path as follows,
@default_port 5433
but if I run the command again, it still tries to connect to 5432.
How do I get the command to connect to 5433 instead of 5432?
CodePudding user response:
To run Ecto migrations on a custom port for Postgres, add the port: <port_number>,
to the configuration. The additional options for the connection are in the Ecto docs here. So, to have it set to port 5433
instead of the default port 5432
, your configuration would look like this:
config :hello, Hello.Repo,
username: "postgres",
password: "postgres",
hostname: "localhost",
database: "hello_dev",
port: 5433,
show_sensitive_data_on_connection_error: true,
pool_size: 10