Azure Resource Manager Postgresql Dotnet
MicrosoftOfficialCreated by Microsoft
- Skill
- Tool integration
- Cloud and DevOps
- MIT
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
The Azure.ResourceManager.PostgreSql SDK for .NET provides a comprehensive interface for managing PostgreSQL Flexible Server deployments on Azure. It enables developers to automate the entire lifecycle of database infrastructure, including server provisioning, database creation, firewall configuration, scaling, and backup management. Designed for integration into .NET applications, it supports secure authentication via DefaultAzureCredential and provides granular control over server parameters, high availability settings, and Entra ID integration.
What it does
- Provision and scale PostgreSQL Flexible Server instances.
- Manage databases, firewall rules, and server configurations.
- Configure high availability and zone redundancy settings.
- Handle automated backups and point-in-time restoration.
- Integrate Entra ID for secure administrative access.
- Perform operational tasks like starting, stopping, and restarting servers.
When to use it
- When automating infrastructure deployment for PostgreSQL on Azure.
- When building custom management tools or dashboards for database administration.
- When implementing infrastructure-as-code patterns within .NET applications.
- When managing database lifecycle events such as scaling or backup scheduling programmatically.
Advantages
- Native .NET integration for seamless infrastructure management.
- Supports secure, modern authentication via Azure Identity.
- Enables programmatic scaling and cost management (e.g., stopping servers).
- Comprehensive coverage of Flexible Server features and configurations.
Usage examples
- “How do I create a new PostgreSQL Flexible Server using the .NET SDK?”
- The SDK provides the PostgreSqlFlexibleServerCollection class, allowing you to define server properties like SKU, storage, and high availability in a PostgreSqlFlexibleServerData object before calling CreateOrUpdateAsync.
- “Can I update my PostgreSQL server configuration parameters programmatically?”
- Yes, you can use the PostgreSqlFlexibleServerConfigurationCollection to retrieve and update specific server parameters like max_connections by providing new values in a PostgreSqlFlexibleServerConfigurationData object.
- “How do I perform a point-in-time restore for a PostgreSQL database?”
- You can initiate a restore by creating a new server instance with the CreateMode set to PointInTimeRestore, specifying the source server ID and the desired PointInTimeUtc timestamp.
- “How do I secure my PostgreSQL server using the SDK?”
- You can manage firewall rules via the PostgreSqlFlexibleServerFirewallRuleCollection and configure Entra ID administrators using the PostgreSqlFlexibleServerActiveDirectoryAdministratorCollection.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/microsoft/azure-resource-manager-postgresql-dotnet/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip azure-resource-manager-postgresql-dotnet.zip -d .agents/skills
Documentation by Microsoft
Azure.ResourceManager.PostgreSql (.NET)
Azure Resource Manager SDK for managing PostgreSQL Flexible Server deployments.
Installation
dotnet add package Azure.ResourceManager.PostgreSql
dotnet add package Azure.IdentityCurrent Version: v1.2.0 (GA)
API Version: 2023-12-01-preview
Note: This skill focuses on PostgreSQL Flexible Server. Single Server is deprecated and scheduled for retirement.
Environment Variables
AZURE_SUBSCRIPTION_ID=<your-subscription-id> # Required: Azure subscription ID
AZURE_RESOURCE_GROUP=<your-resource-group> # Required: resource group name
AZURE_POSTGRESQL_SERVER_NAME=<your-postgresql-server> # Required: PostgreSQL Flexible Server name
AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in productionAuthentication
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.PostgreSql;
using Azure.ResourceManager.PostgreSql.FlexibleServers;
// Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
var credential = new DefaultAzureCredential(
DefaultAzureCredential.DefaultEnvironmentVariableName
);
// Or use a specific credential directly in production:
// See https://learn.microsoft.com/dotnet/api/overview/azure/identity-readme?view=azure-dotnet#credential-classes
// var credential = new ManagedIdentityCredential();
ArmClient client = new ArmClient(credential);Resource Hierarchy
Subscription
└── ResourceGroup
└── PostgreSqlFlexibleServer # PostgreSQL Flexible Server instance
├── PostgreSqlFlexibleServerDatabase # Database within the server
├── PostgreSqlFlexibleServerFirewallRule # IP firewall rules
├── PostgreSqlFlexibleServerConfiguration # Server parameters
├── PostgreSqlFlexibleServerBackup # Backup information
├── PostgreSqlFlexibleServerActiveDirectoryAdministrator # Entra ID admin
└── PostgreSqlFlexibleServerVirtualEndpoint # Read replica endpointsCore Workflows
1. Create PostgreSQL Flexible Server
using Azure.ResourceManager.PostgreSql.FlexibleServers;
using Azure.ResourceManager.PostgreSql.FlexibleServers.Models;
ResourceGroupResource resourceGroup = await client
.GetDefaultSubscriptionAsync()
.Result
.GetResourceGroupAsync("my-resource-group");
PostgreSqlFlexibleServerCollection servers = resourceGroup.GetPostgreSqlFlexibleServers();
PostgreSqlFlexibleServerData data = new PostgreSqlFlexibleServerData(AzureLocation.EastUS)
{
Sku = new PostgreSqlFlexibleServerSku("Standard_D2ds_v4", PostgreSqlFlexibleServerSkuTier.GeneralPurpose),
AdministratorLogin = "pgadmin",
AdministratorLoginPassword = "YourSecurePassword123!",
Version = PostgreSqlFlexibleServerVersion.Ver16,
Storage = new PostgreSqlFlexibleServerStorage
{
StorageSizeInGB = 128,
AutoGrow = StorageAutoGrow.Enabled,
Tier = PostgreSqlStorageTierName.P30
},
Backup = new PostgreSqlFlexibleServerBackupProperties
{
BackupRetentionDays = 7,
GeoRedundantBackup = PostgreSqlFlexibleServerGeoRedundantBackupEnum.Disabled
},
HighAvailability = new PostgreSqlFlexibleServerHighAvailability
{
Mode = PostgreSqlFlexibleServerHighAvailabilityMode.ZoneRedundant,
StandbyAvailabilityZone = "2"
},
AvailabilityZone = "1",
AuthConfig = new PostgreSqlFlexibleServerAuthConfig
{
ActiveDirectoryAuth = PostgreSqlFlexibleServerActiveDirectoryAuthEnum.Enabled,
PasswordAuth = PostgreSqlFlexibleServerPasswordAuthEnum.Enabled
}
};
ArmOperation<PostgreSqlFlexibleServerResource> operation = await servers
.CreateOrUpdateAsync(WaitUntil.Completed, "my-postgresql-server", data);
PostgreSqlFlexibleServerResource server = operation.Value;
Console.WriteLine($"Server created: {server.Data.FullyQualifiedDomainName}");2. Create Database
PostgreSqlFlexibleServerResource server = await resourceGroup
.GetPostgreSqlFlexibleServerAsync("my-postgresql-server");
PostgreSqlFlexibleServerDatabaseCollection databases = server.GetPostgreSqlFlexibleServerDatabases();
PostgreSqlFlexibleServerDatabaseData dbData = new PostgreSqlFlexibleServerDatabaseData
{
Charset = "UTF8",
Collation = "en_US.utf8"
};
ArmOperation<PostgreSqlFlexibleServerDatabaseResource> operation = await databases
.CreateOrUpdateAsync(WaitUntil.Completed, "myappdb", dbData);
PostgreSqlFlexibleServerDatabaseResource database = operation.Value;
Console.WriteLine($"Database created: {database.Data.Name}");3. Configure Firewall Rules
PostgreSqlFlexibleServerFirewallRuleCollection firewallRules = server.GetPostgreSqlFlexibleServerFirewallRules();
// Allow specific IP range
PostgreSqlFlexibleServerFirewallRuleData ruleData = new PostgreSqlFlexibleServerFirewallRuleData
{
StartIPAddress = System.Net.IPAddress.Parse("10.0.0.1"),
EndIPAddress = System.Net.IPAddress.Parse("10.0.0.255")
};
ArmOperation<PostgreSqlFlexibleServerFirewallRuleResource> operation = await firewallRules
.CreateOrUpdateAsync(WaitUntil.Completed, "allow-internal", ruleData);
// Allow Azure services
PostgreSqlFlexibleServerFirewallRuleData azureServicesRule = new PostgreSqlFlexibleServerFirewallRuleData
{
StartIPAddress = System.Net.IPAddress.Parse("0.0.0.0"),
EndIPAddress = System.Net.IPAddress.Parse("0.0.0.0")
};
await firewallRules.CreateOrUpdateAsync(WaitUntil.Completed, "AllowAllAzureServicesAndResourcesWithinAzureIps", azureServicesRule);4. Update Server Configuration
PostgreSqlFlexibleServerConfigurationCollection configurations = server.GetPostgreSqlFlexibleServerConfigurations();
// Get current configuration
PostgreSqlFlexibleServerConfigurationResource config = await configurations
.GetAsync("max_connections");
// Update configuration
PostgreSqlFlexibleServerConfigurationData configData = new PostgreSqlFlexibleServerConfigurationData
{
Value = "500",
Source = "user-override"
};
ArmOperation<PostgreSqlFlexibleServerConfigurationResource> operation = await configurations
.CreateOrUpdateAsync(WaitUntil.Completed, "max_connections", configData);
// Common PostgreSQL configurations to tune
string[] commonParams = {
"max_connections",
"shared_buffers",
"work_mem",
"maintenance_work_mem",
"effective_cache_size",
"log_min_duration_statement"
};5. Configure Entra ID Administrator
PostgreSqlFlexibleServerActiveDirectoryAdministratorCollection admins =
server.GetPostgreSqlFlexibleServerActiveDirectoryAdministrators();
PostgreSqlFlexibleServerActiveDirectoryAdministratorData adminData =
new PostgreSqlFlexibleServerActiveDirectoryAdministratorData
{
PrincipalType = PostgreSqlFlexibleServerPrincipalType.User,
PrincipalName = "[email protected]",
TenantId = Guid.Parse("<tenant-id>")
};
ArmOperation<PostgreSqlFlexibleServerActiveDirectoryAdministratorResource> operation = await admins
.CreateOrUpdateAsync(WaitUntil.Completed, "<entra-object-id>", adminData);6. List and Manage Servers
// List servers in resource group
await foreach (PostgreSqlFlexibleServerResource server in resourceGroup.GetPostgreSqlFlexibleServers())
{
Console.WriteLine($"Server: {server.Data.Name}");
Console.WriteLine($" FQDN: {server.Data.FullyQualifiedDomainName}");
Console.WriteLine($" Version: {server.Data.Version}");
Console.WriteLine($" State: {server.Data.State}");
Console.WriteLine($" SKU: {server.Data.Sku.Name} ({server.Data.Sku.Tier})");
Console.WriteLine($" HA: {server.Data.HighAvailability?.Mode}");
}
// List databases in server
await foreach (PostgreSqlFlexibleServerDatabaseResource db in server.GetPostgreSqlFlexibleServerDatabases())
{
Console.WriteLine($"Database: {db.Data.Name}");
}7. Backup and Point-in-Time Restore
// List available backups
await foreach (PostgreSqlFlexibleServerBackupResource backup in server.GetPostgreSqlFlexibleServerBackups())
{
Console.WriteLine($"Backup: {backup.Data.Name}");
Console.WriteLine($" Type: {backup.Data.BackupType}");
Console.WriteLine($" Completed: {backup.Data.CompletedOn}");
}
// Point-in-time restore
PostgreSqlFlexibleServerData restoreData = new PostgreSqlFlexibleServerData(AzureLocation.EastUS)
{
CreateMode = PostgreSqlFlexibleServerCreateMode.PointInTimeRestore,
SourceServerResourceId = server.Id,
PointInTimeUtc = DateTimeOffset.UtcNow.AddHours(-2)
};
ArmOperation<PostgreSqlFlexibleServerResource> operation = await servers
.CreateOrUpdateAsync(WaitUntil.Completed, "my-postgresql-restored", restoreData);8. Create Read Replica
PostgreSqlFlexibleServerData replicaData = new PostgreSqlFlexibleServerData(AzureLocation.WestUS)
{
CreateMode = PostgreSqlFlexibleServerCreateMode.Replica,
SourceServerResourceId = server.Id,
Sku = new PostgreSqlFlexibleServerSku("Standard_D2ds_v4", PostgreSqlFlexibleServerSkuTier.GeneralPurpose)
};
ArmOperation<PostgreSqlFlexibleServerResource> operation = await servers
.CreateOrUpdateAsync(WaitUntil.Completed, "my-postgresql-replica", replicaData);9. Stop and Start Server
PostgreSqlFlexibleServerResource server = await resourceGroup
.GetPostgreSqlFlexibleServerAsync("my-postgresql-server");
// Stop server (saves costs when not in use)
await server.StopAsync(WaitUntil.Completed);
// Start server
await server.StartAsync(WaitUntil.Completed);
// Restart server
await server.RestartAsync(WaitUntil.Completed, new PostgreSqlFlexibleServerRestartParameter
{
RestartWithFailover = true,
FailoverMode = PostgreSqlFlexibleServerFailoverMode.PlannedFailover
});10. Update Server (Scale)
PostgreSqlFlexibleServerResource server = await resourceGroup
.GetPostgreSqlFlexibleServerAsync("my-postgresql-server");
PostgreSqlFlexibleServerPatch patch = new PostgreSqlFlexibleServerPatch
{
Sku = new PostgreSqlFlexibleServerSku("Standard_D4ds_v4", PostgreSqlFlexibleServerSkuTier.GeneralPurpose),
Storage = new PostgreSqlFlexibleServerStorage
{
StorageSizeInGB = 256,
Tier = PostgreSqlStorageTierName.P40
}
};
ArmOperation<PostgreSqlFlexibleServerResource> operation = await server
.UpdateAsync(WaitUntil.Completed, patch);11. Delete Server
PostgreSqlFlexibleServerResource server = await resourceGroup
.GetPostgreSqlFlexibleServerAsync("my-postgresql-server");
await server.DeleteAsync(WaitUntil.Completed);Key Types Reference
| Type | Purpose |
|---|---|
PostgreSqlFlexibleServerResource | Flexible Server instance |
PostgreSqlFlexibleServerData | Server configuration data |
PostgreSqlFlexibleServerCollection | Collection of servers |
PostgreSqlFlexibleServerDatabaseResource | Database within server |
PostgreSqlFlexibleServerFirewallRuleResource | IP firewall rule |
PostgreSqlFlexibleServerConfigurationResource | Server parameter |
PostgreSqlFlexibleServerBackupResource | Backup metadata |
PostgreSqlFlexibleServerActiveDirectoryAdministratorResource | Entra ID admin |
PostgreSqlFlexibleServerSku | SKU (compute tier + size) |
PostgreSqlFlexibleServerStorage | Storage configuration |
PostgreSqlFlexibleServerHighAvailability | HA configuration |
PostgreSqlFlexibleServerBackupProperties | Backup settings |
PostgreSqlFlexibleServerAuthConfig | Authentication settings |
SKU Tiers
| Tier | Use Case | SKU Examples |
|---|---|---|
Burstable | Dev/test, light workloads | Standard_B1ms, Standard_B2s |
GeneralPurpose | Production workloads | Standard_D2ds_v4, Standard_D4ds_v4 |
MemoryOptimized | High memory requirements | Standard_E2ds_v4, Standard_E4ds_v4 |
PostgreSQL Versions
| Version | Enum Value |
|---|---|
| PostgreSQL 11 | Ver11 |
| PostgreSQL 12 | Ver12 |
| PostgreSQL 13 | Ver13 |
| PostgreSQL 14 | Ver14 |
| PostgreSQL 15 | Ver15 |
| PostgreSQL 16 | Ver16 |
High Availability Modes
| Mode | Description |
|---|---|
Disabled | No HA (single server) |
SameZone | HA within same availability zone |
ZoneRedundant | HA across availability zones |
Best Practices
Use Flexible Server — Single Server is deprecated
Enable zone-redundant HA — For production workloads
Use DefaultAzureCredential — Prefer over connection strings
Configure Entra ID authentication — More secure than SQL auth alone
Enable both auth methods — Entra ID + password for flexibility
Set appropriate backup retention — 7-35 days based on compliance
Use private endpoints — For secure network access
Tune server parameters — Based on workload characteristics
Use read replicas — For read-heavy workloads
Stop dev/test servers — Save costs when not in use
Error Handling
using Azure;
try
{
ArmOperation<PostgreSqlFlexibleServerResource> operation = await servers
.CreateOrUpdateAsync(WaitUntil.Completed, "my-postgresql", data);
}
catch (RequestFailedException ex) when (ex.Status == 409)
{
Console.WriteLine("Server already exists");
}
catch (RequestFailedException ex) when (ex.Status == 400)
{
Console.WriteLine($"Invalid configuration: {ex.Message}");
}
catch (RequestFailedException ex)
{
Console.WriteLine($"Azure error: {ex.Status} - {ex.Message}");
}Connection String
After creating the server, connect using:
// Npgsql connection string
string connectionString = $"Host={server.Data.FullyQualifiedDomainName};" +
"Database=myappdb;" +
"Username=pgadmin;" +
"Password=YourSecurePassword123!;" +
"SSL Mode=Require;Trust Server Certificate=true;";
// With Entra ID token (recommended)
var credential = new DefaultAzureCredential();
var token = await credential.GetTokenAsync(
new TokenRequestContext(new[] { "https://ossrdbms-aad.database.windows.net/.default" }));
string connectionString = $"Host={server.Data.FullyQualifiedDomainName};" +
"Database=myappdb;" +
$"[email protected];" +
$"Password={token.Token};" +
"SSL Mode=Require;";Related SDKs
| SDK | Purpose | Install |
|---|---|---|
Azure.ResourceManager.PostgreSql | PostgreSQL management (this SDK) | dotnet add package Azure.ResourceManager.PostgreSql |
Azure.ResourceManager.MySql | MySQL management | dotnet add package Azure.ResourceManager.MySql |
Npgsql | PostgreSQL data access | dotnet add package Npgsql |
Npgsql.EntityFrameworkCore.PostgreSQL | EF Core provider | dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL |
Reference Links
Files
- ATTRIBUTION.mdAdded by AutoGineer1.0 KiB
- LICENSELicence file added by AutoGineer1.1 KiB
- SKILL.md15.6 KiB
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- Microsoft
- Publisher
- Microsoft (Official)
- Source
- microsoft/skills · .github/plugins/azure-sdk-dotnet/skills/azure-resource-manager-postgresql-dotnet · commit 0696600
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Microsoft.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download azure-resource-manager-postgresql-dotnet.zip