The problem was simple enough that my computer was already running an instance of Postgres that I was not aware was still running (not inside Docker) on :5432
, checked with:
$ lsof -n -i:5432 | grep LISTEN
So I remembered I installed it via https://gist.github.com/sgnl/609557ebacd3378f3b72, I ran
$ pg-stop
And then I had no problem connecting to the Docker instance.
Edit (2019/07/02)
This question recently passed 10,000 views, so I thought I should elaborate more on why this happened.
Usually running through docker, using python and connecting to a postgres database requires you to install psycopg2
, via pip3 install psycopg2
, but if you run this command you will get:
Error: pg_config executable not found.
This is because psycopg2 requires an operating system install of the postgres libraries:
yum install postgresql-devel
apt-get install postgresql-client
Now, on a Mac, you will need to do the same with brew:
brew install postgresql
One thing that I didn't realise, is that on Mac, doing the above will not only install required libraries, but also start a database on :5432
. Because this was all done in the background, it didn't occur to me that this was the problem as none of the usual errors popped up to inform that the port was being used, etc...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…