#Postgrex error when mix ecto.create in Windows

27 messages · Page 1 of 1 (latest)

wide socket
#

Hello, does anyone how to fix this?

[error] Postgrex.Protocol (#PID<0.211.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"

little locust
#

the error is very clear: you're using the wrong password to conenct to your postgres server. The password is defined in config/dev.exs when running in local dev mode.

wide socket
#

this is what I have inside dev.exs

import Config

# Configure your database
config :test_app, TestApp.Repo,
  username: "postgres",
  password: "postgres",
  hostname: "localhost",
  database: "test_app_dev",
  stacktrace: true,
  show_sensitive_data_on_connection_error: true,
  pool_size: 10```
topaz stratus
#

That's the default, you have to configure it depending on your postgres server setup.

wide socket
#

I faces another problem where I am able git clone a project (using docker) and mix ecto.create on macOS but unable to do it for windows

same issue as above (with exact same docker file and dev.exs) but can only run it on mac

little locust
#

the difference is how you installed and set up postgres on each machine. postgres is an external dependency to your project and it's up to you to install it and set it up correctly

wide socket
little locust
#

it depends on a lot of factors, are you running postgres through docker or did you install postgres through some other means? e.g. on macOS maybe you used homebrew? e.g. brew install postgres

wide socket
#

on macOS i don't have postgres installed locally, im running through docker

on windows tho I do have postgres installed locally, but i'm thinking if I do docker compose up I will be running through docker? Or am I misunderstanding here?

hmm it may seems that my local postgres installed on windows could be the issue..

little locust
#

try uninstalling it then and see if that helps

#

I don't know what your docker-compose file looks like, does it contain a postgres instance?

topaz stratus
#

If it did then the hostname would be "db" or "postgres" not "localhost"

#

What project did you clone? Is it public?

little locust
#

yeah that's my thoughts too; the fact your dev.exs says hostname: "localhost" implies it's meant to connect to your local host not a docker container

wide socket
wide socket
little locust
#

that's the same thing though, localhost == 127.0.0.1

wide socket
topaz stratus
#

That's non-standard... usually postgres is started as it's own docker container and linked to the dev server

#

If you have a Dockerfile that's starting postgres in the same docker container as the elixir code, that's weird.

little locust
#

can you show your docker-compose.yml?

#

and/or your dockerfile?

topaz stratus
#

And as long as you're doing docker compose up on both hosts... they both run linux vms underneath so there should be no difference.

wide socket
#
version: "3.8"

services:
    database:
        container_name: db-postgre
        image: postgres:14.4-alpine
        ports:
            - 5432:5432
        environment:
            - POSTGRES_DB=db_dev
            - POSTGRES_USER=postgres
            - POSTGRES_PASSWORD=postgres
            - PGDATA=/var/lib/postgresql/data/pgdata
        volumes:
            - ./.postgres-data:/var/lib/postgresql/data


topaz stratus
#

I'm confused how that worked at all on macos. That says that you should configured elixir to connect to hostname: "database"

little locust
#

it's exposing port 5432 to localhost, I wonder if that's why

#

this would explain why on windows it doesn't work, because the locally installed postgres is already listening on that port so the docker-compose port doesn't get exposed