接続エンドポイントを取得し、Azure Arc 対応 PostgreSQL サーバーの接続文字列を作成する

この記事では、サーバー グループの接続エンドポイントを取得する方法と、アプリケーションまたはツール (あるいはその両方) で使用する接続文字列を作成する方法について説明します。

Note

この記事で紹介しているテクノロジはプレビュー機能であり、「Microsoft Azure プレビューの追加利用規約」に従うことを条件として提供されます。

最新の更新プログラムについては、リリース ノートを参照してください。

接続エンドポイントを取得する:

次のコマンドを実行します。

az postgres server-arc endpoint list -n <server name> --k8s-namespace <namespace> --use-k8s

次に例を示します。

az postgres server-arc endpoint list -n postgres01 --k8s-namespace arc --use-k8s

エンドポイントの一覧 (PostgreSQL エンドポイント、ログ検索ダッシュボード (Kibana)、およびメトリック ダッシュボード (Grafana)) が返されます。 次に例を示します。

{
  "instances": [
    {
      "endpoints": [
        {
          "description": "PostgreSQL Instance",
          "endpoint": "postgresql://postgres:<replace with password>@12.345.567.89:5432"
        },
        {
          "description": "Log Search Dashboard",
          "endpoint": "https://23.456.78.99:5601/app/kibana#/discover?_a=(query:(language:kuery,query:'custom_resource_name:postgres01'))"
        },
        {
          "description": "Metrics Dashboard",
          "endpoint": "https://34.567.890.12:3000/d/postgres-metrics?var-Namespace=arc&var-Name=postgres01"
        }
      ],
      "engine": "PostgreSql",
      "name": "postgres01"
    }
  ],
  "namespace": "arc"
}

これらのエンドポイントは次の目的で使用します。

  • 接続文字列を作成し、クライアント ツールまたはアプリケーションに接続する
  • ブラウザーから Grafana ダッシュボードと Kibana ダッシュボードにアクセスする

たとえば、PostgreSQL インスタンスという名前のエンドポイントを使用して、psql でサーバー グループに接続できます。

psql postgresql://postgres:MyPassworkd@12.345.567.89:5432
psql (10.14 (Ubuntu 10.14-0ubuntu0.18.04.1), server 12.4 (Ubuntu 12.4-1.pgdg16.04+1))
WARNING: psql major version 10, server major version 12.
         Some psql features might not work.
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.

postgres=#

Note

  • "PostgreSQL インスタンス" という名前のエンドポイントで指定された postgres ユーザーのパスワードは、サーバー グループのデプロイ時に選択したパスワードです。

CLI から kubectl を使用する

kubectl get postgresqls/<server name> -n <namespace name>

次に例を示します。

kubectl get postgresqls/postgres01 -n arc

これらのコマンドでは、次のような出力が生成されます。 この情報を使用して、接続文字列を作成できます。

NAME         STATE   READY-PODS   PRIMARY-ENDPOINT     AGE
postgres01   Ready   3/3          12.345.567.89:5432   9d

接続文字列を作成する

サーバー グループには、以下の接続文字列の例を使用します。 必要に応じて、コピー、貼り付け、カスタマイズします。

重要

クライアント接続には SSL が必要です。 接続文字列では、SSL モード パラメーターを無効にしないでください。 詳細については、https://www.postgresql.org/docs/14/runtime-config-connection.html を参照してください。

ADO.NET

Server=192.168.1.121;Database=postgres;Port=24276;User Id=postgres;Password={your_password_here};Ssl Mode=Require;`

C++ (libpq)

host=192.168.1.121 port=24276 dbname=postgres user=postgres password={your_password_here} sslmode=require

JDBC

jdbc:postgresql://192.168.1.121:24276/postgres?user=postgres&password={your_password_here}&sslmode=require

Node.js

host=192.168.1.121 port=24276 dbname=postgres user=postgres password={your_password_here} sslmode=require

PHP

host=192.168.1.121 port=24276 dbname=postgres user=postgres password={your_password_here} sslmode=require

psql

psql "host=192.168.1.121 port=24276 dbname=postgres user=postgres password={your_password_here} sslmode=require"

Python

dbname='postgres' user='postgres' host='192.168.1.121' password='{your_password_here}' port='24276' sslmode='true'

Ruby

host=192.168.1.121; dbname=postgres user=postgres password={your_password_here} port=24276 sslmode=require