sql >> データベース >  >> RDS >> PostgreSQL

クラウドベンダーの詳細:Google Cloud Platform(GCP)上のPostgreSQL

    どこから始めますか?

    私が始めるのに最適な場所は、他ならぬ公式ドキュメントでした。マルチメディアを好む人のためのGCPYoutubeチャンネルもあります。 Cloud SQLのドキュメントの世界にたどり着いたら、製品の「深い理解を深める」ことが約束されているConceptsに目を向けました。

    では、始めましょう!

    PostgreSQLGoogleCloudの機能

    Google Cloud SQL for PostgreSQLは、マネージドソリューションに期待されるすべての標準機能を提供します。自動フェイルオーバー、自動バックアップ、保存中および転送中の暗号化、高度なロギングとモニタリングなどの高可用性です。もちろん、すべてのサービスと対話するための豊富なAPIです。

    少し歴史がありますが、PostgreSQLのサポートは2017年3月に開始され、それまでサポートされていたデータベースエンジンはMySQLのみでした。

    Cloud SQLは、Googleの第2世代コンピューティングプラットフォームでPostgreSQLを実行します。機能の完全なリストは、こことここにもあります。前者を検討すると、PostgreSQL用の第1世代のプラットフォームがなかったことは明らかです。

    第2世代プラットフォームで実行されているデータベースは、7倍の速度で実行され、20倍のストレージ容量のメリットが期待されます。第2世代プラットフォームを発表するブログでは、sysbenchテストの実行の詳細について説明し、GoogleCloudSQLを当時の主要な競合他社であるRDSとAuroraの両方でAWSと比較しています。結果は、Cloud SQLのパフォーマンスが優れていることを示しているので、私を驚かせましたが、約1年後にリリースされたAWSベンチマークを使用して実行された最近のテストは反対の結果になりました。これは、PostgreSQLのサポートが利用可能になったのとほぼ同じ時期です。自分でベンチマークを実行することを考えている間、結果に影響を与えた可能性のある2つの潜在的な要因があると推測しています。Googleのsysbenchベンチマークは異なるパラメーターを使用し、AWSはその間に製品を改善した可能性があります。

    GCPPostgreSQLの互換性

    予想どおり、Google Cloud SQL for PostgreSQLは、コミュニティバージョンのほぼドロップインの代替品であり、すべてのPL /pgSQLSQL手続き型言語をサポートしています。

    SUPERUSERアクセスなど、セキュリティ上の理由により一部の機能を使用できません。製品の安定性とパフォーマンスに潜在的なリスクがあるため、他の機能は削除されました。最後に、一部のオプションとパラメーターは変更できませんが、その動作を変更するリクエストはCloudSQLディスカッショングループを介して行うことができます。

    CloudSQLはPostgreSQLプロトコルともワイヤー互換です。

    トランザクション分離に関してはCloudSQLはPostgreSQLのデフォルトの動作に従い、デフォルトでReadCommitted分離レベルになります。

    一部のサーバー構成パラメーターについて、Cloud SQLは、ドキュメントで説明されていない理由でさまざまな範囲を実装していますが、それでも覚えておくべき重要なことです。

    ネットワーキング

    インスタンスがプライベートネットワーク上にあるかパブリックネットワーク上にあるか(GCPの外部から接続するアプリケーション)に応じて、データベースに接続する方法は複数あります。どちらの場合にも共通するのは、すべてのCloudSQLデータベースインスタンスが存在するGoogleによって管理される事前定義されたVPCです。

    プライベートIP

    プライベートIPアドレスに接続するクライアントは、クライアントをホストするVPCとデータベースインスタンスの間のピアリング接続を介してルーティングされます。 PostgreSQLに固有ではありませんが、接続の問題を回避するために、ネットワーク要件を確認することが重要です。 1つの落とし穴:一度有効にすると、プライベートIP機能を削除することはできません。

    外部アプリケーションからの接続

    GCPの外部でホストされているアプリケーションからの接続は暗号化でき、暗号化する必要があります。さらに、さまざまな攻撃を回避するために、クライアント接続とアプリケーションは、提供されたクライアント証明書をインストールする必要があります。証明書を生成および構成する手順はやや複雑であり、証明書が定期的に更新されるようにするためのカスタムツールが必要です。これが、GoogleがCloudSQLプロキシを使用するオプションを提供する理由の1つである可能性があります。

    CloudSQLプロキシを使用した接続

    設定はかなり簡単です。実際、GoogleCloudSQLドキュメントのすべての手順に当てはまることがわかりました。関連するメモとして、ドキュメントのフィードバックを送信するのは非常に簡単で、スクリーンショット機能は私にとって初めてでした。

    プロキシ接続を承認する方法は複数あり、Cloud SQLプロキシのドキュメントで概説されているように、サービスアカウントを構成することを選択しました。

    すべてが整ったら、プロキシを開始します。

    ~/usr/local/google $ ./cloud_sql_proxy -instances=omiday:us-west1:s9s201907141919=tcp:5432 -credential_file=omiday-427c34fce588.json
    
    2019/07/14 21:22:43 failed to setup file descriptor limits: failed to set rlimit {&{8500 4096}} for max file descriptors: invalid argument
    
    2019/07/14 21:22:43 using credential file for authentication; [email protected]
    
    2019/07/14 21:22:43 Listening on 127.0.0.1:5432 for omiday:us-west1:s9s201907141919
    
    2019/07/14 21:22:43 Ready for new connections

    リモートインスタンスに接続するために、インスタンスのパブリックIPアドレスの代わりにlocalhostを指定してプロキシを使用しています:

    ~ $ psql "user=postgres dbname=postgres password=postgres hostaddr=127.0.0.1"
    
    Pager usage is off.
    
    psql (11.4, server 9.6.11)
    
    Type "help" for help.

    ローカルに接続しており、プロキシがクラウドに流入するトラフィックの暗号化を処理するため、暗号化は行われないことに注意してください。

    一般的なDBAタスクは、pg_stat_activityを照会してデータベースへの接続を表示することです。ドキュメントには、プロキシ接続はcloudsqlproxy〜1.2.3.4として表示されると記載されているため、その主張を確認したいと思います。 postgresとして2つのセッションを開始しました。1つはプロキシ経由で、もう1つは自宅の住所からのものなので、次のクエリで実行できます。

    [email protected]:5432 postgres> select * from pg_stat_activity where usename = 'postgres';
    
    -[ RECORD 1 ]----+-----------------------------------------------------------
    
    datid            | 12996
    
    datname          | postgres
    
    pid              | 924
    
    usesysid         | 16389
    
    usename          | postgres
    
    application_name | psql
    
    client_addr      |
    
    client_hostname  |
    
    client_port      | -1
    
    backend_start    | 2019-07-15 04:25:37.614205+00
    
    xact_start       | 2019-07-15 04:28:43.477681+00
    
    query_start      | 2019-07-15 04:28:43.477681+00
    
    state_change     | 2019-07-15 04:28:43.477684+00
    
    wait_event_type  |
    
    wait_event       |
    
    state            | active
    
    backend_xid      |
    
    backend_xmin     | 8229
    
    query            | select * from pg_stat_activity where usename = 'postgres';
    
    -[ RECORD 2 ]----+-----------------------------------------------------------
    
    datid            | 12996
    
    datname          | postgres
    
    pid              | 946
    
    usesysid         | 16389
    
    usename          | postgres
    
    application_name | psql
    
    client_addr      | <MY_HOME_IP_ADDRESS>
    
    client_hostname  |
    
    client_port      | 60796
    
    backend_start    | 2019-07-15 04:27:50.378282+00
    
    xact_start       |
    
    query_start      |
    
    state_change     | 2019-07-15 04:27:50.45613+00
    
    wait_event_type  |
    
    wait_event       |
    
    state            | idle
    
    backend_xid      |
    
    backend_xmin     |
    
    query            |

    代わりに、プロキシ接続はclient_port==-1および空のclient_addrとして識別されているようです。これは、以下のbackend_startとプロキシログのタイムスタンプを比較することでさらに確認できます。

    2019/07/14 21:25:37 New connection for "omiday:us-west1:s9s201907141919"

    GoogleCloudでのPostgreSQLの高可用性

    Google Cloud SQL for PostgreSQLは、リージョンの永続ディスクによる低レベルのストレージデータ同期を使用して高可用性を保証します。フェイルオーバーは自動で、ハートビートチェック間隔は1秒で、フェイルオーバーは約60秒後にトリガーされます。

    パフォーマンスとモニタリング

    ドキュメントのパフォーマンスセクションでは、一般的なクラウドの経験則を示しています。データベース(ライターとリードの両方のレプリカ)をアプリケーションの近くに置き、インスタンスを垂直方向にスケーリングします。目立つのは、パフォーマンスが重要な場合に、少なくとも60GBのRAMを搭載したインスタンスをプロビジョニングすることを推奨することです。

    Stackdriverは、監視とログ記録、およびPostgreSQLログへのアクセスを提供します。

    アクセス制御

    これは、プロジェクト、インスタンス、データベースレベルで実装されます。

    プロジェクトアクセス制御

    プロジェクトアクセス制御は、クラウド固有のアクセス制御です。プロジェクトメンバー(ユーザー、グループ、またはサービスアカウント)がさまざまなCloud SQLリソースにアクセスできるようにするために、IAMロールの概念を使用します。各役割と関連する権限の詳細な説明については、API Explorer、またはサポートされているプログラミング言語の1つについてはCloud SQL AdminAPIを参照してください。

    IAMロールがどのように機能するかを示すために、読み取り専用(ビューア)サービスアカウントを作成しましょう:

    に関連付けられたサービスアカウントを使用して、ポート5433で新しいプロキシインスタンスを開始します。視聴者の役割:

    ~/usr/local/google $ ./cloud_sql_proxy -instances=omiday:us-west1:s9s201907141919=tcp:5433 -credential_file=omiday-4508243deca9.json
    
    2019/07/14 21:49:56 failed to setup file descriptor limits: failed to set rlimit {&{8500 4096}} for max file descriptors: invalid argument
    
    2019/07/14 21:49:56 using credential file for authentication; [email protected]
    
    2019/07/14 21:49:56 Listening on 127.0.0.1:5433 for omiday:us-west1:s9s201907141919
    
    2019/07/14 21:49:56 Ready for new connections

    127.0.0.1:5433へのpsql接続を開きます:

    ~ $ psql "user=postgres dbname=postgres password=postgres hostaddr=127.0.0.1 port=5433"

    コマンドは次のように終了します:

    psql: server closed the connection unexpectedly
    
          This probably means the server terminated abnormally
    
          before or while processing the request.

    おっと!プロキシログを確認しましょう:

    2019/07/14 21:50:33 New connection for "omiday:us-west1:s9s201907141919"
    
    2019/07/14 21:50:33 couldn't connect to "omiday:us-west1:s9s201907141919": ensure that the account has access to "omiday:us-west1:s9s201907141919" (and make sure there's no typo in that name). Error during createEphemeral for omiday:us-west1:s9s201907141919: googleapi: Error 403: The client is not authorized to make this request., notAuthorized
    インスタンスアクセス制御

    インスタンスレベルのアクセスは、接続ソースによって異なります:

    認証方法の組み合わせは、至る所にあるpg_hba.confに取って代わります。

    > バックアップとリカバリ

    デフォルトでは、自動バックアップが有効になっています:

    バックアップはデータベースの読み取りおよび書き込み操作に影響を与えませんが、パフォーマンスに影響を与えますしたがって、アクティビティが少ない期間にバックアップをスケジュールすることをお勧めします。

    冗長性を確保するために、バックアップを2つのリージョンに保存でき(追加料金が適用されます)、カスタムの場所を選択することもできます。

    ストレージスペースを節約するには、圧縮を使用します。 .gz圧縮ファイルは透過的に復元されます。

    CloudSQLはインスタンスのクローン作成もサポートしています。最小のデータセットの場合、操作には約3分かかりました:

    クローン作成開始時刻10:07:10:

    PostgreSQLログは、PostgreSQLが10時にクローンインスタンスで使用可能になったことを示しています。 10:47:

    これは、コピーを作成するために、バックアップと復元よりも簡単な方法です。テスト、開発、またはトラブルシューティングの目的でインスタンスを作成します。

    PostgreSQLのGoogleCloudのベストプラクティス

    • 24時間年中無休で実行する必要のないインスタンスのアクティベーションポリシーを構成します。
    • ネットワークの遅延を回避するために、データベースインスタンスをコンピューティングエンジンインスタンスとAppEngineアプリケーションと同じゾーンまたはリージョンに配置します。
    • ComputeEngineと同じゾーンにデータベースインスタンスを作成します。他の接続タイプを使用する場合は、デフォルトのゾーンを受け入れます。
    • Cloud SQLを使用して作成されたユーザーは、デフォルトでクラウドスーパーユーザーです。 PostgreSQLALTERROLEを使用して権限を変更します。
    • 最新のCloudSQLプロキシバージョンを使用します。
    • インスタンスを削除および再作成するときに名前を再利用できるようにするには、インスタンス名にタイムスタンプを含める必要があります。
    • pg_dumpは、デフォルトでラージオブジェクトを含みます。データベースにBLOBが含まれている場合は、アクティビティが少ない時間帯にダンプを実行して、インスタンスが応答しなくなるのを防ぎます。
    • gcloud sql connectを使用すると、クライアントのIPアドレスをホワイトリストに登録しなくても、外部クライアントからすばやく接続できます。
    • インスタンスの作成時の問題など、製品の更新やアラートに関する通知を受け取るために、アナウンスグループにサブスクライブします。
    • アプリケーションがデータベース接続管理手法を実装していることを確認します。
    • 90日を超えて停止したインスタンスは、一時停止状態でない限り削除されます。
    • アプリケーションの動作とダウンタイムの長さをテストするために、手動フェイルオーバーを実行します。
    • デフォルトのエンジンバージョンを使用します。
    • ストレージを自動的に増やすように構成されたインスタンスのストレージスペースは、25GBずつ増加します。ストレージスペースを再利用できないため、次の予算サイクルでデータベースの推定サイズに上限を設定し、暴走したクエリを監視します。
    • テストインスタンスには「以前の」メンテナンスタイミングを使用します:
    • アプリケーションは、インスタンスの再起動後に迅速に回復するために、有効な接続と指数バックオフを使用する必要があります。
    • リードレプリカに依存するアプリケーションは、両方のレプリカが使用できなくなる原因となるリージョナル永続ディスクの障害によって引き起こされる問題を回避するために、3つのレプリカの使用を検討する必要があります。
    • 読み取りパフォーマンスを向上させるために、読み取りレプリカを構成します。
    • 既存の接続を切断するためにパブリックインスタンスへのアクセスを許可されているIPアドレスのリストを更新する場合は、インスタンスの再起動が必要です。
    • 追加情報については、StackOverflowCloudSQL専用グループを確認してください。
    クラウドSQLの起動チェックリスト

    ドキュメントのチェックリストセクションには、本番環境に対応したCloud SQLforPostgreSQLインスタンスを設定する際の推奨アクティビティの概要が記載されています。特に、アプリケーションはCloudSQLの再起動を処理するように設計する必要があります。また、1秒あたりのクエリ数の制限はありませんが、接続の制限があります。

    PostgreSQLGCP拡張機能のサポート

    Cloud SQLは、ほとんどのPostgreSQL拡張機能をサポートしています。この記事の執筆時点で、52のコミュニティ拡張機能のうち22のサポートされていない拡張機能と2つのサポートされていないPostGIS拡張機能があります。

    postgis_raster
    
    postgis_sfcgal

    PostgreSQL拡張機能の場合、PostgreSQL contribリポジトリを確認するか、pg_available_extensionsの出力を比較することができます。

    アップストリーム:

    ~ $ psql -U postgres -p 54396
    
    Pager usage is off.
    
    psql (11.4, server 9.6.14)
    
    Type "help" for help.
    
    [email protected][local]:54396 postgres# select * from pg_available_extensions order by name;
    
          name        | default_version | installed_version |                               comment
    
    --------------------+-----------------+-------------------+----------------------------------------------------------------------
    
    adminpack          | 1.1 |                   | administrative functions for PostgreSQL
    
    autoinc            | 1.0 |                   | functions for autoincrementing fields
    
    bloom              | 1.0 |                   | bloom access method - signature file based index
    
    btree_gin          | 1.0 |                   | support for indexing common datatypes in GIN
    
    btree_gist         | 1.2 |                   | support for indexing common datatypes in GiST
    
    chkpass            | 1.0 |                   | data type for auto-encrypted passwords
    
    citext             | 1.3 |                   | data type for case-insensitive character strings
    
    cube               | 1.2 |                   | data type for multidimensional cubes
    
    dblink             | 1.2 |                   | connect to other PostgreSQL databases from within a database
    
    dict_int           | 1.0 |                   | text search dictionary template for integers
    
    dict_xsyn          | 1.0 |                   | text search dictionary template for extended synonym processing
    
    earthdistance      | 1.1 |                   | calculate great-circle distances on the surface of the Earth
    
    file_fdw           | 1.0 |                   | foreign-data wrapper for flat file access
    
    fuzzystrmatch      | 1.1 |                   | determine similarities and distance between strings
    
    hstore             | 1.4 |                   | data type for storing sets of (key, value) pairs
    
    hstore_plperl      | 1.0 |                   | transform between hstore and plperl
    
    hstore_plperlu     | 1.0 |                   | transform between hstore and plperlu
    
    hstore_plpython2u  | 1.0 |                   | transform between hstore and plpython2u
    
    hstore_plpythonu   | 1.0 |                   | transform between hstore and plpythonu
    
    insert_username    | 1.0 |                   | functions for tracking who changed a table
    
    intagg             | 1.1 |                   | integer aggregator and enumerator (obsolete)
    
    intarray           | 1.2 |                   | functions, operators, and index support for 1-D arrays of integers
    
    isn                | 1.1 |                   | data types for international product numbering standards
    
    lo                 | 1.1 |                   | Large Object maintenance
    
    ltree              | 1.1 |                   | data type for hierarchical tree-like structures
    
    ltree_plpython2u   | 1.0 |                   | transform between ltree and plpython2u
    
    ltree_plpythonu    | 1.0 |                   | transform between ltree and plpythonu
    
    moddatetime        | 1.0 |                   | functions for tracking last modification time
    
    pageinspect        | 1.5 |                   | inspect the contents of database pages at a low level
    
    pg_buffercache     | 1.2 |                   | examine the shared buffer cache
    
    pg_freespacemap    | 1.1 |                   | examine the free space map (FSM)
    
    pg_prewarm         | 1.1 |                   | prewarm relation data
    
    pg_stat_statements | 1.4             | | track execution statistics of all SQL statements executed
    
    pg_trgm            | 1.3 |                   | text similarity measurement and index searching based on trigrams
    
    pg_visibility      | 1.1 |                   | examine the visibility map (VM) and page-level visibility info
    
    pgcrypto           | 1.3 |                   | cryptographic functions
    
    pgrowlocks         | 1.2 |                   | show row-level locking information
    
    pgstattuple        | 1.4 |                   | show tuple-level statistics
    
    plpgsql            | 1.0 | 1.0               | PL/pgSQL procedural language
    
    postgres_fdw       | 1.0 |                   | foreign-data wrapper for remote PostgreSQL servers
    
    refint             | 1.0 |                   | functions for implementing referential integrity (obsolete)
    
    seg                | 1.1 |                   | data type for representing line segments or floating-point intervals
    
    sslinfo            | 1.2 |                   | information about SSL certificates
    
    tablefunc          | 1.0 |                   | functions that manipulate whole tables, including crosstab
    
    tcn                | 1.0 |                   | Triggered change notifications
    
    timetravel         | 1.0 |                   | functions for implementing time travel
    
    tsearch2           | 1.0 |                   | compatibility package for pre-8.3 text search functions
    
    tsm_system_rows    | 1.0 |                   | TABLESAMPLE method which accepts number of rows as a limit
    
    tsm_system_time    | 1.0 |                   | TABLESAMPLE method which accepts time in milliseconds as a limit
    
    unaccent           | 1.1 |                   | text search dictionary that removes accents
    
    uuid-ossp          | 1.1 |                   | generate universally unique identifiers (UUIDs)
    
    xml2               | 1.1 |                   | XPath querying and XSLT
    クラウドSQL:

    [email protected]:5432 postgres> select * from pg_available_extensions where name !~ '^postgis' order by name;
    
          name        | default_version | installed_version |                              comment
    
    --------------------+-----------------+-------------------+--------------------------------------------------------------------
    
    bloom              | 1.0 |                   | bloom access method - signature file based index
    
    btree_gin          | 1.0 |                   | support for indexing common datatypes in GIN
    
    btree_gist         | 1.2 |                   | support for indexing common datatypes in GiST
    
    chkpass            | 1.0 |                   | data type for auto-encrypted passwords
    
    citext             | 1.3 |                   | data type for case-insensitive character strings
    
    cube               | 1.2 |                   | data type for multidimensional cubes
    
    dict_int           | 1.0 |                   | text search dictionary template for integers
    
    dict_xsyn          | 1.0 |                   | text search dictionary template for extended synonym processing
    
    earthdistance      | 1.1 |                   | calculate great-circle distances on the surface of the Earth
    
    fuzzystrmatch      | 1.1 |                   | determine similarities and distance between strings
    
    hstore             | 1.4 |                   | data type for storing sets of (key, value) pairs
    
    intagg             | 1.1 |                   | integer aggregator and enumerator (obsolete)
    
    intarray           | 1.2 |                   | functions, operators, and index support for 1-D arrays of integers
    
    isn                | 1.1 |                   | data types for international product numbering standards
    
    lo                 | 1.1 |                   | Large Object maintenance
    
    ltree              | 1.1 |                   | data type for hierarchical tree-like structures
    
    pg_buffercache     | 1.2 |                   | examine the shared buffer cache
    
    pg_prewarm         | 1.1 |                   | prewarm relation data
    
    pg_stat_statements | 1.4             | | track execution statistics of all SQL statements executed
    
    pg_trgm            | 1.3 |                   | text similarity measurement and index searching based on trigrams
    
    pgcrypto           | 1.3 |                   | cryptographic functions
    
    pgrowlocks         | 1.2 |                   | show row-level locking information
    
    pgstattuple        | 1.4 |                   | show tuple-level statistics
    
    plpgsql            | 1.0 | 1.0               | PL/pgSQL procedural language
    
    sslinfo            | 1.2 |                   | information about SSL certificates
    
    tablefunc          | 1.0 |                   | functions that manipulate whole tables, including crosstab
    
    tsm_system_rows    | 1.0 |                   | TABLESAMPLE method which accepts number of rows as a limit
    
    tsm_system_time    | 1.0 |                   | TABLESAMPLE method which accepts time in milliseconds as a limit
    
    unaccent           | 1.1 |                   | text search dictionary that removes accents
    
    uuid-ossp          | 1.1 |                   | generate universally unique identifiers (UUIDs)

    Cloud SQLでサポートされていない拡張機能:

    adminpack          1.1 administrative functions for PostgreSQL
    
    autoinc            1.0 functions for autoincrementing fields
    
    dblink             1.2 connect to other PostgreSQL databases from within a database
    
    file_fdw           1.0 foreign-data wrapper for flat file access
    
    hstore_plperl      1.0 transform between hstore and plperl
    
    hstore_plperlu     1.0 transform between hstore and plperlu
    
    hstore_plpython2u  1.0 transform between hstore and plpython2u
    
    hstore_plpythonu   1.0 transform between hstore and plpythonu
    
    insert_username    1.0 functions for tracking who changed a table
    
    ltree_plpython2u   1.0 transform between ltree and plpython2u
    
    ltree_plpythonu    1.0 transform between ltree and plpythonu
    
    moddatetime        1.0 functions for tracking last modification time
    
    pageinspect        1.5 inspect the contents of database pages at a low level
    
    pg_freespacemap    1.1 examine the free space map (FSM)
    
    pg_visibility      1.1 examine the visibility map (VM) and page-level visibility info
    
    postgres_fdw       1.0 foreign-data wrapper for remote PostgreSQL servers
    
    refint             1.0 functions for implementing referential integrity (obsolete)
    
    seg                1.1 data type for representing line segments or floating-point intervals
    
    tcn                1.0 Triggered change notifications
    
    timetravel         1.0 functions for implementing time travel
    
    tsearch2           1.0 compatibility package for pre-8.3 text search functions
    
    xml2               1.1 XPath querying and XSLT
    ロギング

    Cloud SQL内で実行された操作は、すべての詳細とともに[アクティビティ]タブに記録されます。インスタンスを作成し、すべてのインスタンスの詳細を表示する例:

    PostgreSQLからGCPへの移行

    オンプレミスのPostgreSQLインストールの移行を提供するために、GoogleはpgBouncerを利用します。

    PostgreSQL移行用のGCPコンソールウィザードがないことに注意してください。

    >

    DBA注意!

    高可用性とレプリケーション マスターノードはリードレプリカにフェイルオーバーできません。同じセクションで、リードレプリカのその他の重要な側面について概説します。

    • パッチを適用するためにいつでもオフラインにすることができます
    • フェイルオーバー後に別のゾーンのマスターノードを追跡しないでください—レプリケーションは同期的であるため、レプリケーションの遅延に影響を与える可能性があります
    • レプリカ間に負荷分散はありません。つまり、単一のエンドポイントアプリケーションを指すことはできません。
    • レプリカインスタンスのサイズは、少なくともマスターノードのサイズである必要があります
    • クロスリージョンレプリケーションなし
    • レプリカはバックアップできません
    • マスターインスタンスをバックアップから復元または削除する前に、すべてのレプリカを削除する必要があります
    • カスケードレプリケーションは利用できません
    ユーザー

    デフォルトでは、「cloudsuperuser」はcloudsqlsuperuserロールのメンバーであるpostgresです。次に、cloudsqlsuperuserはデフォルトのPostgreSQLロールを継承します:

    [email protected]:5432 postgres> \du+ postgres
    
                               List of roles
    
    Role name  | Attributes       | Member of | Description
    
    -----------+------------------------+---------------------+-------------
    
    postgres   | Create role, Create DB | {cloudsqlsuperuser} |
    
    
    
    [email protected]:5432 postgres> \du+ cloudsqlsuperuser
    
                                  List of roles
    
       Role name       | Attributes       | Member of | Description
    
    -------------------+------------------------+--------------+-------------
    
    cloudsqlsuperuser  | Create role, Create DB | {pg_monitor} |
    ロールSUPERUSERおよびREPLICATIONは使用できないことに注意してください。

    バックアップとリカバリ バックアップはエクスポートできません。

    バックアップは、インスタンスのアップグレード、つまり別のPostgreSQLエンジンへの復元には使用できません。

    PITR、論理レプリケーション、JITコンパイルなどの機能は使用できません。機能のリクエストは、GoogleのIssueTrackerに提出できます。

    暗号化 インスタンスの作成時にSSL/TLSは有効になっていますが、強制されていません:

    このモードでは、暗号化を要求できますが、証明書の検証は利用できません。

    ~ $ psql "sslmode=verify-ca user=postgres dbname=postgres password=postgres hostaddr=35.233.149.65"
    
    psql: root certificate file "/home/lelu/.postgresql/root.crt" does not exist
    
    Either provide the file or change sslmode to disable server certificate verification.
    
    ~ $ psql "sslmode=require user=postgres dbname=postgres password=postgres hostaddr=35.233.149.65"
    
    Pager usage is off.
    
    psql (11.4, server 9.6.11)
    
    SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES128-GCM-SHA256, bits: 128, compression: off)
    
    Type "help" for help.

    psqlを使用してSSL強制インスタンスに接続しようとすると、自明のエラーが返されます:

    ~ $ psql "sslmode=require user=postgres dbname=postgres password=postgres hostaddr=35.233.149.65"
    
    psql: FATAL:  connection requires a valid client certificate
    ストレージ
    • ストレージはインスタンスの作成後に増やすことができますが、減らすことはできないため、ストレージスペースの増加に関連するコストに注意するか、増加制限を設定してください。
    • ストレージは30TBに制限されています。

    CPU

    インスタンスは1つ未満のコアで作成できますが、サンプルのマシンタイプの1つを指定してインスタンスを作成する必要があるため、このオプションはCloud SQL Consoleでは使用できません。この場合は–ティア:

    Cloud Shell内でgcloudを使用して共有コードインスタンスを作成する例:

    CPUの数は64に制限されており、大規模な場合は比較的低い制限です。 9.2がベンチマークされたとき、ハイエンドサーバーが32コアで開始されたことを考慮すると、インストール。

    インスタンスの場所 マルチリージョンの場所はバックアップでのみ使用できます。

    パブリックIPを介したアクセス

    デフォルトでは、GCPコンソールウィザードはパブリックIPアドレスアクセスのみを有効にしますが、クライアントのネットワークが設定されるまでアクセスは拒否されます:

    メンテナンス

    更新はメンテナンスウィンドウを超える可能性があり、リードレプリカはいつでも更新されます。

    ドキュメントには、メンテナンスウィンドウの期間が指定されていません。インスタンスの作成時に情報が提供されます:

    CPUカウント、メモリサイズ、またはインスタンスが存在するゾーンの変更位置を特定するには、データベースを数分間オフラインにする必要があります。

    ユーザー

    Cloud SQLでは、「ロール」と「ユーザー」という用語を同じ意味で使用しています。

    高可用性

    高可用性構成のコストは、スタンドアロンインスタンスの2倍であり、ストレージが含まれます。

    自動フェイルオーバーは、プライマリノードが使用できなくなってから約60秒後に開始されます。 Oracle MAAのレポートによると、これは1分あたり5,800ドルの損失に相当します。アプリケーションが停止を2倍から3倍に再接続できるようになるまで、2〜3分かかることを考慮してください。さらに、60秒のハートビート間隔は構成可能なオプションではないようです。

    レプリケーション

    単一のエンドポイントを使用してリードレプリカにアクセスすることはできません。各エンドポイントは新しいIPアドレスを受け取ります:

    リージョナル永続ディスクは、書き込みパフォーマンスを犠牲にしてデータの冗長性を提供します。

    Cloud SQLはフェイルオーバーしてレプリカを読み取ることはないため、リーダーを高可用性ソリューションと見なすことはできません

    External replicas and external masters are currently not supported.

    Connecting to Instance

    Google does not automatically renew the instance SSL certificates, however, both the initiation and rotation procedures can be automated.

    If the application is built on the App Engine platform additional limits apply, such as 60 seconds for a database request to complete, 60 concurrent connections for PHP applications. The “App Engine Limits” section in Quotas and limits provides more details:

    IP addresses in the range 172.17.0.0/16 are reserved.

    Administration

    Once started, operations cannot be canceled. Runaway queries can still be stopped by using the pg_terminate_backend and pg_cancel_backend PostgreSQL built-in functions.

    A short demonstration using two psql sessions and starting a long running query in the second session:

    [email protected]:5432 postgres> select now(); select pg_sleep(3600); select now();
    
                now
    
    -------------------------------
    
    2019-07-16 02:08:18.739177+00
    
    (1 row)

    In the first session, cancel the long running query:

    [email protected]:5432 postgres> select pid, client_addr, client_port, query, backend_start from pg_stat_activity where usename = 'postgres';
    
    -[ RECORD 1 ]-+-------------------------------------------------------------------------------------------------------------
    
    pid           | 2182
    
    client_addr   | 173.180.222.170
    
    client_port   | 56208
    
    query         | select pid, client_addr, client_port, query, backend_start from pg_stat_activity where usename = 'postgres';
    
    backend_start | 2019-07-16 01:57:34.99011+00
    
    -[ RECORD 2 ]-+-------------------------------------------------------------------------------------------------------------
    
    pid           | 2263
    
    client_addr   | 173.180.222.170
    
    client_port   | 56276
    
    query         | select pg_sleep(3600);
    
    backend_start | 2019-07-16 02:07:43.860829+00
    
    
    
    [email protected]:5432 postgres> select pg_cancel_backend(2263); select now();
    
    -[ RECORD 1 ]-----+--
    
    pg_cancel_backend | t
    
    
    
    -[ RECORD 1 ]----------------------
    
    now | 2019-07-16 02:09:09.600399+00

    Comparing the timestamps between the two sessions:

    ERROR:  canceling statement due to user request
    
                now
    
    -------------------------------
    
    2019-07-16 02:09:09.602573+00
    
    (1 row)

    It’s a match!

    While restarting an instance is a recommended method when attempting to resolve database instance issues, avoid restarting before the first restart completed.

    Data Import and Export

    CSV import/export is limited to one database.

    Exporting data as an SQL dump that can be imported later, requires a custom pg_dump command.

    To quote from the documentation:

    pg_dump -U [USERNAME] --format=plain --no-owner --no-acl [DATABASE_NAME] \
    
        | sed -E 's/(DROP|CREATE|COMMENT ON) EXTENSION/-- \1 EXTENSION/g' > [SQL_FILE].sql

    Pricing

    Charge Type

    Instance ON

    Instance OFF

    Storage

    Yes

    Yes

    Instance

    No

    Yes

    トラブルシューティング

    Logging

    All actions are recorded and can be viewed under the Activity tab.

    Resources

    Review the Diagnosing Issues with Cloud SQL instances and Known issues sections in the documentation.

    結論

    Although missing some important features the PostgreSQL DBA is used to, namely PITR and Logical Replication, Google Cloud SQL provides out of the box high-availability, replication, encryption, and automatic storage increase, just to name a few, making manage PostgreSQL an appealing solution for organizations looking to quickly deploy their PostgreSQL workloads or even migrating from Oracle.

    Developers can take advantage of cheap instances such as shared CPU (less than one CPU).

    Google approaches the PostgreSQL engine adoption in a conservative manner, the stable offering lagging behind current upstream by 3 versions.

    Just as with any solution provider consider getting support which can come in handy during edge scenarios such as when instances are suspended.

    For professional support, Google maintains a list of partners which currently includes one of the PostgreSQL professional services , namely EDB.


    1. SQLServer2005のデータをExcelに転送またはエクスポートするにはどうすればよいですか

    2. PostgreSQLでこの時間の操作クエリを実行します

    3. Androidでカーソルデータを使用してリスト配列を作成するにはどうすればよいですか?

    4. 交差するタイムスパンの平坦化