xxxxxxxxxx
import psycopg2
# Connect to the PostgreSQL server
conn = psycopg2.connect(
host="localhost",
database="your_database",
user="your_username",
password="your_password"
)
# Create a cursor object to interact with the database
cur = conn.cursor()
# Use the cursor to execute SQL commands
cur.execute("CREATE DATABASE test_database;")
# Commit the changes
conn.commit()
# Close the cursor and the connection
cur.close()
conn.close()