import psycopg2
# Connect to the PostgreSQL database
conn = psycopg2.connect(
host="your_host",
port="your_port",
database="your_database",
user="your_user",
password="your_password"
)
# Create a cursor object to interact with the database
cursor = conn.cursor()
# Execute the query to retrieve all schemas from the database
cursor.execute("SELECT schema_name FROM information_schema.schemata")
# Fetch all the results as a list of tuples
schemas = cursor.fetchall()
# Print the list of schemas
for schema in schemas:
print(schema[0])
# Close the cursor and connection
cursor.close()
conn.close()