shahryarjb

shahryarjb

Hello, I want to create an action for my elixir project, but I can not connect to PSQL database

Error: 9.650 [error] GenServer #PID<0.755.0> terminating
** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
    (db_connection 2.4.1) lib/db_connection/connection.ex:100: DBConnection.Connection.connect/2
    (connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 3.17) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol

Error: 9.668 [error] GenServer #PID<0.761.0> terminating
** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
    (db_connection 2.4.1) lib/db_connection/connection.ex:100: DBConnection.Connection.connect/2
    (connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 3.17) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
** (Mix) The database for MishkaDatabase.Repo couldn't be created: killed
Error: Process completed with exit code 1.

As you see I have this error connection refused - :econnrefused

This is my CI yml

https://github.com/shahryarjb/mishka-cms/blob/master/.github/workflows/ci.yml

And this is my test config file:

https://github.com/shahryarjb/mishka-cms/blob/master/config/test.exs

And you can see the last failed action in this repository, thank you, and please help me to fix it

Showing Posts 1 to 6

shahryarjb

shahryarjb OP

I changed my port and it works, but I got this error instead of pervious error in my tests, I don’t have this error in my docker

Error: 7.031 [error] GenServer #PID<0.2681.0> terminating
** (ArgumentError) expected :hostname, endpoints, :socket_dir, or :socket to be given
    (postgrex 0.15.13) lib/postgrex/protocol.ex:139: Postgrex.Protocol.endpoints/1
    (postgrex 0.15.13) lib/postgrex/protocol.ex:66: Postgrex.Protocol.connect/1
    (db_connection 2.4.1) lib/db_connection/connection.ex:82: DBConnection.Connection.connect/2
    (connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 3.17) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

I add it socket_dir: "/var/run/postgres", to my Ecto config, but I have this error, I think it is nor current path

Error: 6.167 [error] GenServer #PID<0.755.0> terminating
** (DBConnection.ConnectionError) tcp connect (/var/run/postgres/.s.PGSQL.5432): no such file or directory - :enoent

I changed my yml and made it like GitHub document, but I have this error

Error: 4.396 [error] GenServer #PID<0.755.0> terminating
** (DBConnection.ConnectionError) tcp connect (postgres:5432): non-existing domain - :nxdomain
    (db_connection 2.4.1) lib/db_connection/connection.ex:100: DBConnection.Connection.connect/2
    (connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 3.17) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
al2o3cr

al2o3cr

You’d only use the socket option if you were running the code on the same machine as the database, which isn’t the case here.

The example on that linked Github doc that uses ports like the ci.yml in your repo does is the “running jobs directly on the worker machine” which sets POSTGRES_HOST to localhost and relies on Docker’s port forwarding to connect the containers.

shahryarjb

shahryarjb OP

Hello Dear @al2o3cr,
I tried everything I thought might it work.

For example

This is how I introduced Elixir

jobs:
  test:
    name: Run tests
    runs-on: ubuntu-latest
    env:
      MIX_ENV: test
    strategy:
      matrix:
        otp: ['24.x']
        elixir: ['1.13.2']
        postgres: ['14.1-alpine']

and for my elixir source, I want to connect it to a Postgres database, so I added a 14.1-alpine

services:
      postgres:
        image: postgres
        env:
          POSTGRES_PASSWORD: postgres
          
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

Then I did like GitHub sample without port after preparing database as a service

Then I have this error:

Error: 1.218 [error] GenServer #PID<0.280.0> terminating
** (DBConnection.ConnectionError) tcp connect (postgres:5432): non-existing domain - :nxdomain
    (db_connection 2.4.1) lib/db_connection/connection.ex:100: DBConnection.Connection.connect/2
    (connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 3.17) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol

but if I do like the other part, I mean the link you sheared: Creating PostgreSQL service containers - GitHub Docs

I edited like this and added port :

    services:
      postgres:
        image: postgres
        env:
          POSTGRES_PASSWORD: postgres
          
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          # Maps tcp port 5432 on service container to the host
          - 5432:5432

and added these lines:

POSTGRES_HOST: localhost
# The default PostgreSQL port
POSTGRES_PORT: 5432

With these changes, I could pass the migration part, but in the test section I got error from database

Error: 2.017 [error] GenServer #PID<0.246.0> terminating
** (RuntimeError) connect raised ArgumentError exception. The exception details are hidden, as they may contain sensitive data such as database credentials. You may set :show_sensitive_data_on_connection_error to true when starting your connection if you wish to see all of the details
    (postgrex 0.15.13) lib/postgrex/protocol.ex:139: Postgrex.Protocol.endpoints/1
    (postgrex 0.15.13) lib/postgrex/protocol.ex:66: Postgrex.Protocol.connect/1
    (db_connection 2.4.1) lib/db_connection/connection.ex:82: DBConnection.Connection.connect/2
    (connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 3.17) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol

I added show_sensitive_data_on_connection_error: true to see more information

Error: 0.104 [error] GenServer #PID<0.247.0> terminating
** (ArgumentError) expected :hostname, endpoints, :socket_dir, or :socket to be given
    (postgrex 0.15.13) lib/postgrex/protocol.ex:139: Postgrex.Protocol.endpoints/1
    (postgrex 0.15.13) lib/postgrex/protocol.ex:66: Postgrex.Protocol.connect/1
    (db_connection 2.4.1) lib/db_connection/connection.ex:82: DBConnection.Connection.connect/2
    (connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 3.17) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol

All lines of my CI:

I created a simple elixir application you can access to it (click please) and see all the CI code

name: MishkaCms CI

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
jobs:
  test:
    name: Run tests
    runs-on: ubuntu-latest
    env:
      MIX_ENV: test

    strategy:
      matrix:
        otp: ['24.x']
        elixir: ['1.13.2']
        postgres: ['14.1-alpine']

    services:
      postgres:
        image: postgres
        env:
          POSTGRES_PASSWORD: postgres
          
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          # Maps tcp port 5432 on service container to the host
          - 5432:5432

    steps:
      - uses: actions/checkout@v2
      - uses: erlef/setup-beam@v1.10.0
        with:
          otp-version: ${{matrix.otp}}
          elixir-version: ${{matrix.elixir}}
      - name: Elixir and Erlang Dependencies
        run: | 
          mix local.hex --force
          mix local.rebar --force
          mix archive.install hex phx_new --force
      - name: Source Compiling
        run: | 
          mix deps.get
          mix deps.compile
      - name: Database Dependencies
        env:
          POSTGRES_HOST: localhost
          # The default PostgreSQL port
          POSTGRES_PORT: 5432
          DATABASE_USER: postgres
          DATABASE_PASSWORD: postgres
          DATABASE_HOST: localhost

        run: | 
          mix ecto.create
          mix ecto.migrate
      - name: Run tests
        run: mix test

I do not know how to fix this, I tried many ways :pensive: please help me to figure out

shahryarjb

shahryarjb OP

If I create it like this, it works for me, but I can’t check multi version of elixir and Erlang in a job

name: Elixir CI

on: push

jobs:
  build:

    runs-on: ubuntu-latest

    container:
      image: elixir:1.13.1-slim
      env:
        MIX_ENV: test
      
    services:
      postgres:
        image: postgres
        ports:
          - 5432:5432
        env:
          POSTGRES_PASSWORD: postgres
          POSTGRES_USER: postgres
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

    steps:
    - uses: actions/checkout@v2
    - name: Install Dependencies
      run: |
        mix local.rebar --force
        mix local.hex --force
        mix deps.get
    - name: Run Tests
      run: |
        mix ecto.create
        mix ecto.migrate
        mix test
      env:
        DB_HOST: postgres
        DATABASE_USER: postgres
        DATABASE_PASSWORD: postgres
        DATABASE_HOST: postgres
shahryarjb

shahryarjb OP

Hello, I fixed all the pervious errors, In testing I have a problem that it shows me undefined_table, but this table exists and I have no problem in my local and server with these packages.
Hence, I tried to drop and migrate again, but it always shows me

09:36:35.700 [info]  Migrations already up
09:36:35.779 [info]  Migrations already up

I have written these line before, and I have dropped the dB before migration

https://github.com/shahryarjb/mishka-cms/blob/master/.github/workflows/ci.yml#L91-L94

Please help me to fix this
Thank you


Update

I fixed it with some changes in my config and deleting MIX_ENV=test

shahryarjb

shahryarjb OP

Hello Friends,
I have postgress error in my new project’s GitHub ci again.

Error

Error: 7.902 [error] GenServer #PID<0.521.0> terminating
##[debug]Dropping file value '/home/runner/work/ChatFCoin/ChatFCoin/14'. Path does not exist
Warning: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
    (db_connection 2.4.2) lib/db_connection/connection.ex:100: DBConnection.Connection.connect/2
** (Mix) The database for ChatFCoin.Repo couldn't be dropped: killed
##[debug]Dropping file value '/home/runner/work/ChatFCoin/ChatFCoin/    (db_connection 2.4.2) lib/db_connection/connection.ex'. Path does not exist
Warning:     (connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 3.17) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
##[debug]Dropping file value '/home/runner/work/ChatFCoin/ChatFCoin/    (stdlib 3.17) proc_lib.erl'. Path does not exist
Warning: Last message: nil
State: Postgrex.Protocol
Error: Process completed with exit code 1.
##[debug]Finishing: Source Compiling

error ref: https://github.com/shahryarjb/ChatFCoin/runs/6079339322?check_suite_focus=true

My GitHub CI:

https://github.com/shahryarjb/ChatFCoin/blob/master/.github/workflows/ci.yml

Do you have any idea why it is dropped?

Update

I forgot to put ENV=test in ci

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
widianto
I think I’ve found a small improvement I could contribute to &lt;%= web_namespace %&gt;.CoreComponents (installer/templates/phx_web/compo...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews