#!/usr/bin/env python3
import os
import psycopg2
from dotenv import load_dotenv

load_dotenv()

conn = psycopg2.connect(
    host=os.getenv('KNOWHUB_DB'),
    port=int(os.getenv('KNOWHUB_PORT', 5432)),
    user=os.getenv('KNOWHUB_USER'),
    password=os.getenv('KNOWHUB_PASSWORD'),
    database='postgres'  # 连接到默认数据库
)
conn.autocommit = True
cursor = conn.cursor()

cursor.execute("SELECT datname FROM pg_database WHERE datistemplate = false;")
print("主机上的所有数据库:")
for row in cursor.fetchall():
    print(f"  - {row[0]}")

cursor.close()
conn.close()
