import psycopg2 conn = psycopg2.connect( host="hgprecn-cn-2r42t31q3003-cn-zhangjiakou-vpc.hologres.aliyuncs.com", database="mydatabase", user="LTAI5t73cdL5i2ioJVyVmUur", password="7jj3y8mMi2aKzvDfxsANo9jYZ7gcxk" ) # 创建一个游标对象 cur = conn.cursor() # 执行SQL查询语句 #cur.execute("show databases") cur.execute("SELECT datname FROM pg_database WHERE datistemplate = false") # 获取所有查询结果 rows = cur.fetchall() # 打印结果 for row in rows: print(row) # 关闭游标和数据库连接 cur.close() conn.close()