-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_connection.py
More file actions
70 lines (60 loc) · 2.04 KB
/
debug_connection.py
File metadata and controls
70 lines (60 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
"""
Debug database connection issues
"""
import asyncio
import asyncpg
from dotenv import load_dotenv
import os
import sys
# Load environment variables
load_dotenv(".env", override=True)
async def debug_connection():
database_url = os.getenv("DATABASE_URL")
print(f"Database URL: {database_url[:50]}...")
try:
print("Step 1: Attempting basic connection...")
conn = await asyncio.wait_for(
asyncpg.connect(database_url, statement_cache_size=0),
timeout=5.0
)
print("✅ Connected!")
print("Step 2: Testing simple SELECT 1...")
result = await asyncio.wait_for(
conn.fetchval("SELECT 1"),
timeout=3.0
)
print(f"✅ SELECT 1 result: {result}")
print("Step 3: Testing version query...")
try:
version = await asyncio.wait_for(
conn.fetchval("SELECT version()"),
timeout=3.0
)
print(f"✅ Version: {version[:100]}...")
except asyncio.TimeoutError:
print("❌ Version query timed out")
except Exception as e:
print(f"❌ Version query failed: {e}")
print("Step 4: Testing current_database()...")
try:
db_name = await asyncio.wait_for(
conn.fetchval("SELECT current_database()"),
timeout=3.0
)
print(f"✅ Database name: {db_name}")
except asyncio.TimeoutError:
print("❌ Database name query timed out")
except Exception as e:
print(f"❌ Database name query failed: {e}")
print("Step 5: Closing connection...")
await conn.close()
print("✅ Connection closed!")
except asyncio.TimeoutError:
print("❌ Initial connection timed out")
sys.exit(1)
except Exception as e:
print(f"❌ Connection failed: {e}")
sys.exit(1)
if __name__ == "__main__":
asyncio.run(debug_connection())