Reputation: 170
So I'm new to PostgreSQL and I made my server and database and the table and stuff then I do back to repl.it discord.py and I tried running this:
async def create_db_pool():
client.pg_con = await asyncpg.create_pool(database= "mainbank", user = "postgres", password = password)
client.loop.run_until_complete(create_db_pool())
Error:
Traceback (most recent call last):
File "main.py", line 204, in <module>
client.loop.run_until_complete(create_db_pool())
File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "main.py", line 39, in create_db_pool
client.pg_con = await asyncpg.create_pool(database= "mainbank", user = "postgres", password = password)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/asyncpg/pool.py", line 407, in _async__init__
await self._initialize()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/asyncpg/pool.py", line 435, in _initialize
await first_ch.connect()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/asyncpg/pool.py", line 127, in connect
self._con = await self._pool._get_new_connection()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/asyncpg/pool.py", line 477, in _get_new_connection
con = await connection.connect(
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/asyncpg/connection.py", line 1980, in connect
return await connect_utils._connect(
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/asyncpg/connect_utils.py", line 677, in _connect
raise last_error
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/asyncpg/connect_utils.py", line 661, in _connect
con = await _connect_addr(
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/asyncpg/connect_utils.py", line 634, in _connect_addr
tr, pr = await compat.wait_for(connector, timeout=timeout)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/asyncpg/compat.py", line 103, in wait_for
return await asyncio.wait_for(fut, timeout)
File "/usr/lib/python3.8/asyncio/tasks.py", line 494, in wait_for
return fut.result()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/asyncpg/connect_utils.py", line 544, in _create_ssl_connection
tr, pr = await loop.create_connection(
File "/usr/lib/python3.8/asyncio/base_events.py", line 1033, in create_connection
raise OSError('Multiple exceptions: {}'.format(
OSError: Multiple exceptions: [Errno 111] Connect call failed ('127.0.0.1', 5432), [Errno 99] Cannot assign requested address
What is wrong? It is my side or is it PostgreSQL? I have the Host as localhost and the port as 5432 (all default)
Upvotes: 5
Views: 17224
Reputation: 2553
I had the same exact error running a Python FastAPI app in a Docker container trying to connect to another container with http3.AsyncClient
(looks in both cases asyncio
library is used) to GET a response from another app. The answer above by @Laurenz Albe directed me to
docker system prune -a
The app ran after that. I also can reproduce this error if trying to connect to 127.0.0.1
but container not on the host
network.
Upvotes: 3
Reputation: 247485
It looks like you have too many TCP connections on that machine. Whenever you connect(2)
to establish a TCP connections (and you didn't bind(2)
the socket to a port), the network socket is assigned an ephemeral port by the operating system. If there is no free ephemeral port on the machine, you get the error EADDRNOTAVAIL
:
EADDRNOTAVAIL
(Internet domain sockets) The socket referred to by
sockfd
had not previously been bound to an address and, upon attempting to bind it to an ephemeral port, it was determined that all port numbers in the ephemeral port range are currently in use. See the discussion of/proc/sys/net/ipv4/ip_local_port_range
inip(7)
.
Either open fewer TCP connections or increase the range for ephemeral ports.
Upvotes: 4