Connection failed/refused when connecting to local PostgreSQL Database
I'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 Label Bot is not confident enough to auto-label this issue. See dashboard for more details.
Try postgresql://superset_user:[email protected]:5432/superset (This will force IPv4). Otherwise, are you certain that you can connect to it? psql -h 127.0.0.1 -U superset_user superset
@craig-rueda hi, I mention in the end of the question that I tried that host:port. I can also connect to it via psql
What command are you using to start superset? Is this in docker?
@craig-rueda hi, yes I start superset via docker-compose up
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 included postgres from the docker-compose stack?
@craig-rueda Unfortunately that didn't work for me (Ubuntu 18.04). I haven't used the postgres from the docker-compose stack because I haven't found out if/how it's possible to add a new table to that database programmatically.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue .pinned to prevent stale bot from closing the issue.
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 of db rather than the IP address(es) of the docker network it's running on.