Skill 2.2.1
Connect and query Azure Database for PostgreSQL by using SDKs
Key Concepts
A connection names the server host (SERVER.postgres.database.azure.com), port 5432, a database, a user and a password, and requires TLS (sslmode=require). With Microsoft Entra authentication, the application obtains an access token for the scope https://ossrdbms-aad.database.windows.net/.default with DefaultAzureCredential and passes it as the password; the token expires after about an hour, so long-lived pools must obtain new tokens for new connections.
Queries run through a cursor, and values are always passed as parameters (cur.execute("SELECT ... WHERE id = %s", (item_id,))) rather than by string formatting, which prevents SQL injection and lets the server reuse plans. A connection runs statements in a transaction until it commits; using the connection as a context manager commits on success and rolls back on an exception.