sqitchers / docker-sqitch

Docker Image packaging for Sqitch
MIT License
35 stars 39 forks source link

Connection refused? #14

Closed k3n closed 5 years ago

k3n commented 5 years ago

Greetings! First, I'm ecstatic to find this project, if I can only get it to work it'd be the best thing since....Sqitch itself :)

Just got a new dev machine, running Mac Mojave, and installed pg@9.6. I can connect to it via my data tool (DataGrip), see schemas, users, etc. So I know it's up & running.

I pulled the docker-sqitch image and ran the docker-sqitch.sh script, but it's complaining:

$ ./sqitch status local
# On database local
could not connect to server: Connection refused
    Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 5432?
could not connect to server: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?

Even though I believe it should have worked (since my other tool can connect fine), based on some StackOverflow suggestions I went and updated my postgresql.conf with:

listen_addresses = '*'

And my pg_hba.conf with:

host  all  all 0.0.0.0/0 md5 # also tried "trust"

Restarted postgres, but I'm still getting the same error.

Log file only shows:

LOG:  database system was shut down at 2019-06-26 11:55:39 CDT
LOG:  MultiXact member wraparound protections are now enabled
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started

Again confirmed postgres is listening:

$ sudo lsof -PiTCP -sTCP:LISTEN | grep postgres
Password:
postgres   2990 k3n    5u  IPv6 0x5a94e66853463a37      0t0  TCP localhost:5432 (LISTEN)
postgres   2990 k3n    6u  IPv4 0x5a94e66855c49d37      0t0  TCP localhost:5432 (LISTEN)

My sqitch.conf:

[core]
    engine = pg
[engine "pg"]
    client = /usr/local/bin/psql
[deploy]
    verify = true
[target "local"]
    uri = db:pg://my_db_user:my_password@localhost/my_db
[target "dev"]
    uri = db:pg://my_db_user:my_password@localhost/my_db_dev
[engine "pg"]
    target = local
[deploy.variables]
    TESTDB = FALSE
[target "qa"]
    uri = db:pg://my_db_user:my_password@some-host-1/my_db
[target "ci"]
    uri = db:pg://my_db_user:my_password@some-host-2/my_db
[target "prod"]
    client = psql
    uri = db:pg://my_db_user:my_password@some-host-3:5432/my_db

At this point I'm out of ideas, and the search results are turning redundant with their suggestions. Any ideas?

(edited to add sqitch.conf)

ssoriche commented 5 years ago

In this instance, it looks like you're trying to connect to a database on localhost from within the sqitch docker container, which does not include a running database. You need to use an IP address that docker can connect to. Usually this is a 172.x address that docker uses.

k3n commented 5 years ago

Excellent, from your suggestion I was able to solve it by via the Docker docs:

I updated this section of my config with host.docker.internal, and it's finding my DB now:

[target "local"]
    uri = db:pg://my_db_user:my_password@host.docker.internal/my_db

I am having another issue, but I'll start a new ticket for that. Thank you!