{"id":1933,"library":"azure-mgmt-postgresqlflexibleservers","title":"Azure PostgreSQL Flexible Servers Management Client Library","description":"The `azure-mgmt-postgresqlflexibleservers` library is the Microsoft Azure Postgresqlflexibleservers Management Client Library for Python. It enables developers to programmatically create, configure, manage, and scale Azure Database for PostgreSQL flexible server instances. This includes operations like managing databases, configuring firewall rules, performing scaling, and handling backup and restore. The library is currently at version 2.0.0 and is actively maintained, receiving regular updates often in conjunction with Azure service updates.","status":"active","version":"2.0.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/postgresqlflexibleservers/azure-mgmt-postgresqlflexibleservers","tags":["azure","postgresql","cloud","management","sdk","database"],"install":[{"cmd":"pip install azure-mgmt-postgresqlflexibleservers azure-identity","lang":"bash","label":"Install with authentication dependency"}],"dependencies":[{"reason":"Required for Azure Active Directory token authentication with DefaultAzureCredential, a common and recommended authentication method for Azure SDKs.","package":"azure-identity","optional":false}],"imports":[{"symbol":"PostgreSQLManagementClient","correct":"from azure.mgmt.postgresqlflexibleservers import PostgreSQLManagementClient"},{"note":"Used for authenticating with Azure services through a variety of credential types.","symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"}],"quickstart":{"code":"import os\nfrom azure.identity import DefaultAzureCredential\nfrom azure.mgmt.postgresqlflexibleservers import PostgreSQLManagementClient\n\n# Set environment variables or ensure Azure CLI is logged in\n# AZURE_SUBSCRIPTION_ID\n# AZURE_RESOURCE_GROUP\n# AZURE_LOCATION\n# AZURE_SERVER_NAME\n# AZURE_ADMIN_USERNAME\n# AZURE_ADMIN_PASSWORD\n\nsubscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_SUBSCRIPTION_ID')\nresource_group_name = os.environ.get('AZURE_RESOURCE_GROUP', 'my-postgresql-rg')\nserver_name = os.environ.get('AZURE_SERVER_NAME', 'my-flex-server-123')\nlocation = os.environ.get('AZURE_LOCATION', 'eastus') # e.g., 'eastus'\nadmin_username = os.environ.get('AZURE_ADMIN_USERNAME', 'psqladmin')\nadmin_password = os.environ.get('AZURE_ADMIN_PASSWORD', 'ComplexP@ssw0rd')\n\n# Authenticate using DefaultAzureCredential\ncredential = DefaultAzureCredential()\n\n# Create a PostgreSQLManagementClient\nclient = PostgreSQLManagementClient(credential, subscription_id)\n\nprint(f\"Creating PostgreSQL flexible server '{server_name}' in resource group '{resource_group_name}'...\")\n\n# Create a flexible server\n# This is an asynchronous operation, use .begin_create() and wait() for completion\nserver_poller = client.servers.begin_create(\n    resource_group_name,\n    server_name,\n    {\n        \"location\": location,\n        \"sku\": {\n            \"name\": \"Standard_D2ds_v4\",\n            \"tier\": \"GeneralPurpose\"\n        },\n        \"properties\": {\n            \"version\": \"14\", # or \"12\", \"13\", \"15\", etc.\n            \"administratorLogin\": admin_username,\n            \"administratorLoginPassword\": admin_password,\n            \"storage\": {\n                \"storageSizeGB\": 32\n            },\n            \"network\": {\n                \"publicNetworkAccess\": \"Enabled\"\n            }\n        }\n    }\n)\n\nserver = server_poller.result() # Wait for the creation to complete\nprint(f\"Server '{server.name}' created successfully in {server.location}.\")\nprint(f\"Provisioning state: {server.provisioning_state}\")\n\n# Example: List all servers in the resource group\nprint(f\"\\nListing servers in resource group '{resource_group_name}':\")\nfor s in client.servers.list_by_resource_group(resource_group_name):\n    print(f\"- {s.name} ({s.location}) - State: {s.state}\")\n\n# Note: This quickstart creates a resource. Remember to delete it after use\n# client.servers.begin_delete(resource_group_name, server_name).wait()\n# print(f\"Server '{server_name}' deleted.\")","lang":"python","description":"This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and create a `PostgreSQLManagementClient` instance. It then proceeds to create a new Azure Database for PostgreSQL flexible server instance, waits for its provisioning, and lists existing servers. Ensure you have the necessary environment variables set (AZURE_SUBSCRIPTION_ID, AZURE_RESOURCE_GROUP, AZURE_LOCATION, AZURE_SERVER_NAME, AZURE_ADMIN_USERNAME, AZURE_ADMIN_PASSWORD) or are logged in via Azure CLI for authentication to work."},"warnings":[{"fix":"Ensure relevant environment variables are set or run `az login` to authenticate via Azure CLI. Refer to Azure SDK for Python authentication documentation for more details.","message":"Authentication with `DefaultAzureCredential` relies on specific environment variables (e.g., AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET, AZURE_SUBSCRIPTION_ID) or an active Azure CLI login. Incorrect or missing configuration is a frequent source of authentication errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Check your subscription's quotas and region access in the Azure portal. Submit a quota increase request if necessary, or choose a different region. Refer to Azure documentation on resolving capacity errors.","message":"Deployment of new Azure Database for PostgreSQL Flexible Servers can fail due to subscription-level quotas being exceeded or the selected region not having capacity or access enabled for your subscription. This often results in 'Exceeded quota' or 'Enable region' errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For public access, use `client.firewall_rules.begin_create_or_update()` to add client IP. For private access, ensure your client is deployed within the configured VNet or peered VNet.","message":"Network access must be properly configured for your PostgreSQL flexible server. If using public access, you must add your client workstation's IP address to the server's firewall rules. If using private access, your client must be within the same virtual network as the server.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For synchronous operations, import from `azure.mgmt.postgresqlflexibleservers`. For asynchronous operations, import from `azure.mgmt.postgresqlflexibleservers.aio` and use `async/await` syntax.","message":"The library provides both synchronous (`azure.mgmt.postgresqlflexibleservers`) and asynchronous (`azure.mgmt.postgresqlflexibleservers.aio`) clients. Mixing them without proper `await`/`async` handling in Python can lead to runtime errors or unexpected behavior. Ensure consistency in your usage.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Plan major version upgrades carefully. Consider performing a point-in-time recovery backup before initiating the upgrade if a rollback capability is critical for your scenario.","message":"In-place major version upgrades of PostgreSQL instances performed via the management plane (exposed by this library) are irreversible. While they simplify the upgrade process, there is no automated rollback to the previous major version. Point-in-time recovery to before the upgrade is the only way to revert.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}