Connection failed/refused when connecting to local PostgreSQL Database
See original GitHub issueI’m trying to connect Superset to my local PostreSQL database via this URI:
postgresql://superset_user:password@localhost/superset
When I test the connection, I get the following error:
ERROR: {"error": "Connection failed!\n\nThe error message returned was:\n(psycopg2.OperationalError) could not connect to server: Connection refused\n\tIs the server running on host \"localhost\" (127.0.0.1) and accepting\n\tTCP/IP connections on port 5432?\ncould not connect to server: Cannot assign requested address\n\tIs the server running on host \"localhost\" (::1) and accepting\n\tTCP/IP connections on port 5432?\n\n(Background on this error at: http://sqlalche.me/e/e3q8)", "stacktrace": "Traceback (most recent call last):\n File \"/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/base.py\", line 2265, in _wrap_pool_connect\n return fn()\n File \"/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/base.py\", line 303, in unique_connection\n return _ConnectionFairy._checkout(self)\n File \"/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/base.py\", line 760, in _checkout\n fairy = _ConnectionRecord.checkout(pool)\n File \"/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/base.py\", line 492, in checkout\n rec = pool._do_get()\n File \"/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/impl.py\", line 238, in _do_get\n return self._create_connection()\n File \"/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/base.py\", line 308, in _create_connection\n return _ConnectionRecord(self)\n File \"/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/base.py\", line 437, in __init__\n self.__connect(first_connect_check=True)\n File \"/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/base.py\", line 639, in __connect\n connection = pool._invoke_creator(self)\n File \"/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/strategies.py\", line 114, in ...
I tried all the variations of host:port
such as 127.0.0.1:5432, but the connection still fails.
The \conninfo
output displays You are connected to database "superset" as user "superset_user" via socket in "/var/run/postgresql" at port "5432".
, so this should theoretically work.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (3 by maintainers)
Top GitHub Comments
There’s your problem. In docker’s overlay network, “localhost” will refer to the superset container only. If you want to access postgres on your machine, you will need to connect to
host.docker.internal
(on Mac). Why not just use the includedpostgres
from the docker-compose stack?Just as a note to anyone who stumbles on this, the address for the superset backend db is
db:5432
in the SQL URI string for sqlalchemy, and not localhost. I’m not sure why that’s the case, and inspecting the docker network for the precise IP address doesn’t resolve when trying to add the database as a Superset data source. Somewhere during the compose process, I guess superset is configured to see it’s own network at the address ofdb
rather than the IP address(es) of the docker network it’s running on.