# -*- coding: UTF-8 -*- ''' @Project :domainScanDemo @File :check_db_structure.py @IDE :PyCharm @Author :梦伴 @Date :2026/4/9 21:50 @explain : 检查数据库表结构和索引 ''' import psycopg2 from app.config import config def check_db_structure(): """ 检查数据库表结构和索引 """ try: # 连接数据库 conn = psycopg2.connect( host=config.DB_HOST, port=config.DB_PORT, database=config.DB_DATABASE, user=config.DB_USER, password=config.DB_PASSWORD ) cur = conn.cursor() print("数据库连接成功") # 检查domains表结构 print("\n=== domains表结构 ===") cur.execute("SELECT column_name, data_type, is_nullable, column_default FROM information_schema.columns WHERE table_name = 'domains.txt'") for row in cur.fetchall(): print(row) # 检查domains表索引 print("\n=== domains表索引 ===") cur.execute("SELECT indexname, indexdef FROM pg_indexes WHERE tablename = 'domains.txt'") for row in cur.fetchall(): print(row) # 检查其他表结构 print("\n=== detect_tasks表结构 ===") cur.execute("SELECT column_name, data_type, is_nullable, column_default FROM information_schema.columns WHERE table_name = 'detect_tasks'") for row in cur.fetchall(): print(row) print("\n=== domain_blacklist表结构 ===") cur.execute("SELECT column_name, data_type, is_nullable, column_default FROM information_schema.columns WHERE table_name = 'domain_blacklist'") for row in cur.fetchall(): print(row) print("\n=== domain_detections表结构 ===") cur.execute("SELECT column_name, data_type, is_nullable, column_default FROM information_schema.columns WHERE table_name = 'domain_detections'") for row in cur.fetchall(): print(row) except Exception as e: print(f"检查数据库失败: {e}") finally: if cur: cur.close() if conn: conn.close() if __name__ == "__main__": check_db_structure()