xxxxxxxxxx
import psycopg2
# Connect to the PostgreSQL database
conn = psycopg2.connect(
host="your_host",
port=5432,
database="your_database",
user="your_username",
password="your_password"
)
# Perform some database operations...
# For example, executing a query to fetch all rows from a table
cur = conn.cursor()
cur.execute("SELECT * FROM your_table")
rows = cur.fetchall()
# Print the result
for row in rows:
print(row)
# Close the cursor and connection
cur.close()
conn.close()