次の方法で共有


クイック スタート: ARM テンプレートを使用して Azure Database for PostgreSQL でエラスティック クラスターを作成する

エラスティック クラスターを備えた Azure Database for PostgreSQL は、水平方向のスケールアウト機能を使用して、クラウドで高可用性 PostgreSQL データベースを実行、管理、およびスケーリングするために使用するマネージド サービスです。 Azure Resource Manager テンプレート (ARM テンプレート) を使用して、エラスティック クラスター インスタンスを作成できます。

Azure Resource Manager テンプレートは JavaScript Object Notation (JSON) ファイルであり、プロジェクトのインフラストラクチャと構成が定義されています。 このテンプレートでは、宣言型の構文が使用されています。 デプロイしようとしているものを、デプロイを作成する一連のプログラミング コマンドを記述しなくても記述できます。

Azure Resource Manager は、Azure のデプロイおよび管理サービスです。 お使いの Azure アカウント内のリソースを作成、更新、および削除できる管理レイヤーを提供します。 アクセス制御、ロック、タグなどの管理機能を使用して、デプロイ後にリソースを保護および整理します。 Azure Resource Manager テンプレートについては、テンプレートのデプロイの概要に関するページを参照してください。

前提条件

アクティブなサブスクリプションが含まれる Azure アカウント。 無料で作成できます

テンプレートを確認する

Azure Database for PostgreSQL フレキシブル サーバー インスタンスは、リージョン内の分散型データベースのための親リソースです。 それは、クラスターに適用される管理ポリシーのスコープ (ファイアウォール、ユーザー、ロール、構成) を提供します。

elastic-cluster-template.json ファイルを作成し、次の JSON スクリプトをコピーします。

{
  "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "administratorLogin": {
      "type": "string"
    },
    "administratorLoginPassword": {
      "type": "securestring"
    },
    "location": {
      "type": "string",
      "defaultValue": "canadacentral"
    },
    "clusterName": {
      "type": "string"
    },
    "serverEdition": {
      "type": "string",
      "defaultValue": "GeneralPurpose"
    },
    "storageSizeGB": {
      "type": "int",
      "defaultValue": 64
    },
    "haEnabled": {
      "type": "string",
      "defaultValue": "Disabled"
    },
    "availabilityZone": {
      "type": "string",
      "defaultValue": "1"
    },
    "backupRetentionDays": {
      "type": "int",
      "defaultValue": 7
    },
    "skuName": {
      "type": "string",
      "defaultValue": "Standard_D4ds_v5"
    },
    "clusterSize": {
      "type": "int",
      "defaultValue": 2
    },
    "guid": {
      "type": "string",
      "defaultValue": "[newGuid()]"
    },
    "firewallRules": {
      "type": "object",
      "defaultValue": {
        "rules": [
          {
            "name": "AllowAll",
            "startIPAddress": "0.0.0.0",
            "endIPAddress": "255.255.255.255"
          }
        ]
      }
    },
    "network": {
      "type": "object",
      "defaultValue": { "publicNetworkAccess": "Enabled" }
    }
  },
  "variables": {
    "firewallRules": "[parameters('firewallRules').rules]"
  },
  "resources": [
    {
      "apiVersion": "2025-08-01",
      "location": "[parameters('location')]",
      "name": "[parameters('clusterName')]",
      "properties": {
        "createMode": "Default",
        "version": "16",
        "administratorLogin": "[parameters('administratorLogin')]",
        "administratorLoginPassword": "[parameters('administratorLoginPassword')]",
        "availabilityZone": "[parameters('availabilityZone')]",
        "Storage": {
          "StorageSizeGB": "[parameters('storageSizeGB')]",
          "Autogrow": "Disabled"
        },
        "Network": "[if(empty(parameters('network')), json('null'), parameters('network'))]",
        "Backup": {
          "backupRetentionDays": "[parameters('backupRetentionDays')]",
          "geoRedundantBackup": "Disabled"
        },
        "highAvailability": {
          "mode": "[parameters('haEnabled')]"
        },
        "cluster": {
          "clusterSize": "[parameters('clusterSize')]"
        }
      },
      "sku": {
        "name": "[parameters('skuName')]",
        "tier": "[parameters('serverEdition')]"
      },
      "type": "Microsoft.DBforPostgreSQL/flexibleServers"
    },
    {
      "condition": "[greater(length(variables('firewallRules')), 0)]",
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2019-08-01",
      "name": "[concat('firewallRules-', parameters('guid'), '-', copyIndex())]",
      "copy": {
        "count": "[if(greater(length(variables('firewallRules')), 0), length(variables('firewallRules')), 1)]",
        "mode": "Serial",
        "name": "firewallRulesIterator"
      },
      "dependsOn": [
        "[concat('Microsoft.DBforPostgreSQL/flexibleServers/', parameters('clusterName'))]"
      ],
      "properties": {
        "mode": "Incremental",
        "template": {
          "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "resources": [
            {
              "type": "Microsoft.DBforPostgreSQL/flexibleServers/firewallRules",
              "name": "[concat(parameters('clusterName'),'/',variables('firewallRules')[copyIndex()].name)]",
              "apiVersion": "2025-08-01",
              "properties": {
                "StartIpAddress": "[variables('firewallRules')[copyIndex()].startIPAddress]",
                "EndIpAddress": "[variables('firewallRules')[copyIndex()].endIPAddress]"
              }
            }
          ]
        }
      }
    }
  ]
}

テンプレートでは、次のリソースが定義されています。

テンプレートのデプロイ

次の PowerShell コード ブロックから [使ってみる] を選択して Azure Cloud Shell を開きます。

$clusterName = Read-Host -Prompt "Enter a name for the new Azure Database for PostgreSQL flexible server elastic cluster instance"
$resourceGroupName = Read-Host -Prompt "Enter a name for the new resource group where the elastic cluster will exist"
$adminUser = Read-Host -Prompt "Enter the Azure Database for PostgreSQL flexible server elastic cluster instance's administrator account name"
$adminPassword = Read-Host -Prompt "Enter the administrator password" -AsSecureString
# New-AzResourceGroup -Name $resourceGroupName -Location <AZURE_LOCATION>  Use this command when you need to create a new resource group for your deployment
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName `
    -TemplateFile "elastic-cluster-template.json" `
    -clusterName $clusterName `
    -administratorLogin $adminUser `
    -administratorLoginPassword $adminPassword

Read-Host -Prompt "Press [ENTER] to continue ..."

デプロイされているリソースを確認する

Azure Database for PostgreSQL フレキシブル サーバーエラスティック クラスターが作成されたかどうかを確認するには、次の手順に従います。

  1. Azure portal で、Azure Database for PostgreSQL フレキシブル サーバーを検索して選択します。
  2. データベースの一覧で新しいサーバーを選択し、[ 概要 ] ページを表示してエラスティック クラスターを管理します。

次のステップ

このリソース グループとエラスティック クラスターを使用して、[ 関連コンテンツ ] セクションに記載されている次の推奨手順を続行する場合は、このリソース グループとエラスティック クラスターを保持します。 次の手順では、さまざまなアプリケーション シャーディング モデルと設計でエラスティック クラスターを使用する方法を示します。

リソースをクリーンアップする

エラスティック クラスター環境が完了したら、エラスティック クラスター リソースを削除できます。

エラスティック クラスターを削除するには:

ポータルで、削除するリソース グループを選択します。

  1. [リソース グループの削除] を選択します。
  2. 削除を確認するには、リソース グループの名前を入力します。