All checks were successful
Build and Deploy Log Center / build-and-deploy (push) Successful in 1m30s
53 lines
1.2 KiB
Python
53 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Quick script to test PostgreSQL connection"""
|
|
import os
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
DB_USER = os.getenv("DB_USER")
|
|
DB_PASSWORD = os.getenv("DB_PASSWORD")
|
|
DB_HOST = os.getenv("DB_HOST")
|
|
DB_PORT = os.getenv("DB_PORT", "5432")
|
|
DB_NAME = os.getenv("DB_NAME")
|
|
|
|
print("=" * 50)
|
|
print("Testing PostgreSQL Connection")
|
|
print("=" * 50)
|
|
print(f"Host: {DB_HOST}")
|
|
print(f"Port: {DB_PORT}")
|
|
print(f"Database: {DB_NAME}")
|
|
print(f"User: {DB_USER}")
|
|
print("=" * 50)
|
|
|
|
try:
|
|
import psycopg2
|
|
|
|
conn = psycopg2.connect(
|
|
host=DB_HOST,
|
|
port=DB_PORT,
|
|
database=DB_NAME,
|
|
user=DB_USER,
|
|
password=DB_PASSWORD,
|
|
connect_timeout=10
|
|
)
|
|
|
|
cursor = conn.cursor()
|
|
cursor.execute("SELECT version();")
|
|
version = cursor.fetchone()
|
|
|
|
print(f"✅ Connection Successful!")
|
|
print(f"PostgreSQL Version: {version[0]}")
|
|
|
|
cursor.close()
|
|
conn.close()
|
|
|
|
except Exception as e:
|
|
print(f"❌ Connection Failed!")
|
|
print(f"Error: {e}")
|
|
print()
|
|
print("Possible fixes:")
|
|
print("1. Check if your IP is whitelisted in Aliyun RDS console")
|
|
print("2. Verify DB_HOST is correct (use external/public endpoint)")
|
|
print("3. Ensure the database 'log_center' exists")
|