def initialize_postgres():
    """Initialize the PostgreSQL database by creating the necessary tables."""

    try:
        import psycopg2

    except ImportError:
        raise ImportError("Please install psycopg2 library to use PostgreSQL.")

    conn = psycopg2.connect(
        dbname=os.getenv("POSTGRES_DB", "postgres"),
        user=os.getenv("POSTGRES_USER", "postgres"),
        password=os.getenv("POSTGRES_PASSWORD", "postgres"),
        host=os.getenv("POSTGRES_HOST", "localhost"),
        port=os.getenv("POSTGRES_PORT", "5432"),
    )
    cursor = conn.cursor()

    try:
        cursor.execute(CREATE_SESSIONS_TABLE)
        cursor.execute(CREATE_CONVERSATIONS_TABLE)
        cursor.execute(CREATE_CONTEXT_MESSAGES_TABLE)
        conn.commit()
        logger.info("PostgreSQL tables created successfully")
    except Exception as e:
        logger.exception(f"Error creating PostgreSQL tables: {e}")
        conn.rollback()
    finally:
        cursor.close()
        conn.close()
Initialize the PostgreSQL database by creating the necessary tables.
backend/director/db/postgres/initialize.py