cant connect to pg locally

so im trying to connect to my postgres server locally from a python script using asyncpg.create_pool this has always worked for me in the past but its not working this time for some reason.
async with asyncpg.create_pool(database=os.environ.get('PGDATABASE'),
host=os.environ.get('PGHOST'),
user=os.environ.get('PGUSER'),
password=os.environ.get('PGPASSWORD'),
port=os.environ.get('PGPORT')) as psql:
async with asyncpg.create_pool(database=os.environ.get('PGDATABASE'),
host=os.environ.get('PGHOST'),
user=os.environ.get('PGUSER'),
password=os.environ.get('PGPASSWORD'),
port=os.environ.get('PGPORT')) as psql:
the env variables are all present. i get socket.gaierror: [Errno 11001] getaddrinfo failed. if you want me to send full traceback i can do that ig. it works fine on railway idk it just doesnt work on my computer. the env variables for the project on railway are variable references, and ive copied those to the local env file project id: 1dfc4bb8-37ce-4e09-9723-387fa3324724
Solution:
you need to use the public host as the host and the public port as the port
Jump to solution
20 Replies
Percy
Percy4mo ago
Project ID: 1dfc4bb8-37ce-4e09-9723-387fa3324724
deleting.user
deleting.userOP4mo ago
the pghost seems to be railway.internal and not viaduct.railway like ive seen in the past i did go to the pg server settings and find the public networking url which was viaduct.railway but it gives me the same error as i said before, the same script deploys fine on railway the script actually didnt work on railway before using variable references but like im sure i copied them properly What is love i do not understand the problem the pg database came out of sleep when i tried connecting so something must be have clicked but it wont connect the password is correct the user is correct the host is correct ???
Brody
Brody4mo ago
is the port correct?
deleting.user
deleting.userOP4mo ago
well yeah i tried the private one and the public one the private one i got by going to the variables tab and copying PGPORT and PGHOST and then public one i opened the Railway provided variables and copied the RAILWAY_TCP_PROXY_DOMAIN:RAILWAY_TCP_PROXY_PORT for PGHOST and then RAILWAY_TCP_APPLICATION_PORT for PGPORT neither work
Brody
Brody4mo ago
you have it pointing to the wrong port
No description
deleting.user
deleting.userOP4mo ago
should i point it to 5432
Brody
Brody4mo ago
yep thats the port postgres is running on
deleting.user
deleting.userOP4mo ago
i think even the first tcp proxy (which i didnt create) was running on the wrong port cause it was 45117 anyways
Brody
Brody4mo ago
that would have been something you changed at some point
deleting.user
deleting.userOP4mo ago
No description
No description
deleting.user
deleting.userOP4mo ago
still doing a getaddr info fail
Solution
Brody
Brody4mo ago
you need to use the public host as the host and the public port as the port
deleting.user
deleting.userOP4mo ago
yeah
No description
Brody
Brody4mo ago
you arent...
deleting.user
deleting.userOP4mo ago
🙏 its working now
Brody
Brody4mo ago
awsome
deleting.user
deleting.userOP4mo ago
enabling app sleeping on pg and redis should be fine tho right?
Brody
Brody4mo ago
as long as your client can handle retries
deleting.user
deleting.userOP4mo ago
alr i see tysm
Brody
Brody4mo ago
no problem
Want results from more Discord servers?
Add your server