Azure RDBMS Management
The `azure-mgmt-rdbms` library provides Python client APIs for managing Azure Relational Database services (PostgreSQL, MySQL, MariaDB). It allows for programmatic creation, configuration, and deletion of database servers, databases, and related resources. The current version is `10.1.1` and it follows the Azure SDK release cadence, with frequent updates to align with new Azure API features and bug fixes.
Warnings
- gotcha The `azure-mgmt-rdbms` package acts as a meta-package. You cannot instantiate a generic `RdbmsManagementClient` directly from `azure.mgmt.rdbms`. Instead, you must import and use specific clients for each RDBMS type (e.g., `PostgreSQLManagementClient`, `MySQLManagementClient`, `MariaDBManagementClient`) from their respective sub-packages (e.g., `azure.mgmt.rdbms.postgresql`).
- breaking Major version updates of `azure-mgmt-rdbms` (e.g., from 9.x to 10.x) typically align with updates to the underlying Azure REST API versions. These updates can introduce breaking changes in client constructors, method signatures, parameter names, or resource model schemas. Always review the official migration guides or changelogs when upgrading to a new major version.
- gotcha Authentication issues are common. `DefaultAzureCredential` relies on a cascade of authentication methods (environment variables, managed identity, Azure CLI, etc.). If not configured correctly, you'll encounter `ClientAuthenticationError` or similar credential errors.
Install
-
pip install azure-mgmt-rdbms azure-identity
Imports
- PostgreSQLManagementClient
from azure.mgmt.rdbms.postgresql import PostgreSQLManagementClient
- MySQLManagementClient
from azure.mgmt.rdbms.mysql import MySQLManagementClient
- MariaDBManagementClient
from azure.mgmt.rdbms.mariadb import MariaDBManagementClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Quickstart
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.rdbms.postgresql import PostgreSQLManagementClient
# Set your Azure Subscription ID and Resource Group name as environment variables
# or replace with actual values. Ensure AZURE_TENANT_ID, AZURE_CLIENT_ID,
# AZURE_CLIENT_SECRET are also set for service principal authentication,
# or be logged in via 'az login' for user authentication.
SUBSCRIPTION_ID = os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_SUBSCRIPTION_ID')
if SUBSCRIPTION_ID == 'YOUR_SUBSCRIPTION_ID':
print("Warning: Please set the AZURE_SUBSCRIPTION_ID environment variable or replace 'YOUR_SUBSCRIPTION_ID'.")
exit()
def list_postgresql_servers():
try:
# Authenticate with Azure
credential = DefaultAzureCredential()
# Create a PostgreSQL management client
pg_client = PostgreSQLManagementClient(credential, SUBSCRIPTION_ID)
print(f"Listing PostgreSQL servers in subscription {SUBSCRIPTION_ID}:")
for server in pg_client.servers.list():
print(f" - Name: {server.name}, Resource Group: {server.id.split('/resourceGroups/')[1].split('/')[0]}, Location: {server.location}, State: {server.user_visible_state}")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
list_postgresql_servers()