수정본
This commit is contained in:
69
tests/test_db_connection.py
Normal file
69
tests/test_db_connection.py
Normal file
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
DB 연결 테스트 스크립트
|
||||
실행: python test_db_connection.py
|
||||
"""
|
||||
import asyncio
|
||||
import asyncpg
|
||||
|
||||
|
||||
async def test_connection():
|
||||
print("🔵 Testing PostgreSQL connection...")
|
||||
print("Host: shium.net")
|
||||
print("Port: 55432")
|
||||
print("Database: stock")
|
||||
print("User: stock")
|
||||
print()
|
||||
|
||||
try:
|
||||
# 직접 asyncpg로 연결 시도
|
||||
conn = await asyncpg.connect(
|
||||
host='shium.net',
|
||||
port=55432,
|
||||
database='stock',
|
||||
user='stock',
|
||||
password='Tjduddn!!12',
|
||||
timeout=10,
|
||||
ssl=False,
|
||||
)
|
||||
|
||||
print("✅ Connection successful!")
|
||||
|
||||
# 간단한 쿼리 테스트
|
||||
version = await conn.fetchval('SELECT version()')
|
||||
print(f"PostgreSQL version: {version}")
|
||||
|
||||
# 테이블 목록 조회
|
||||
tables = await conn.fetch("""
|
||||
SELECT table_name
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = 'public'
|
||||
""")
|
||||
|
||||
print(f"\nTables in database:")
|
||||
for table in tables:
|
||||
print(f" - {table['table_name']}")
|
||||
|
||||
await conn.close()
|
||||
print("\n✅ Connection test completed successfully!")
|
||||
|
||||
except asyncpg.PostgresConnectionError as e:
|
||||
print(f"❌ PostgreSQL connection error: {e}")
|
||||
except ConnectionRefusedError as e:
|
||||
print(f"❌ Connection refused: {e}")
|
||||
print("Possible causes:")
|
||||
print(" 1. PostgreSQL server is not running")
|
||||
print(" 2. Firewall blocking port 55432")
|
||||
print(" 3. PostgreSQL not configured to accept external connections")
|
||||
print(" 4. Need SSH tunnel or VPN to access the server")
|
||||
except TimeoutError as e:
|
||||
print(f"❌ Connection timeout: {e}")
|
||||
print("The server is not responding. Check network connectivity.")
|
||||
except Exception as e:
|
||||
print(f"❌ Unexpected error: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(test_connection())
|
||||
Reference in New Issue
Block a user