2013年11月16日

RDS for PostgreSQLの中を覗いてみた(追記あり)

皆さんお待ちかねの、RDS for PostgreSQLが昨日リリースされました。
既にインスタンスを立ち上げてみた方もいるようです。
というわけで、デプロイまでの手順は上記を参照いただくとして、今回のエントリでは、実際に「PostgreSQLとして使う」という観点でいくつか見てみたいと思います。


■ログインと通信

まず、PostgreSQLへのログインの方法ですが、通常のpsqlコマンドでログインでき、SSLによる通信の暗号化がサポートされているようです。
[snaga@devsv03 ~]$ psql -U testuser -h testdbinstance.XXXXX.ap-northeast-1.rds.amazonaws.com testdb
Password for user testuser:
psql (9.3.0, server 9.3.1)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.

testdb=>
PostgreSQLのSSLサポートは、認証のセッション(ユーザ名とパスワードを送るところ)だけではなく、SQLのやり取りなど全体が暗号化されますので、これによって通信が保護されることになります。

■バージョン


次にPostgreSQLのバージョンを見てみます。
testdb=> select version();
                                                   version
--------------------------------------------------------------------------------------------------------------
 PostgreSQL 9.3.1 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.6.3 20120306 (Red Hat 4.6.3-2), 64-bit
(1 行)

testdb=> 
Red Hatの環境でビルドしたPostgreSQLのようです。最新版の9.3.1がデプロイされています。

■ユーザとユーザ権限


次にユーザ(ロール)と権限を見てみます。
testdb=> \du+
                                         List of roles
   Role name   |                   Attributes                   |    Member of    | Description
---------------+------------------------------------------------+-----------------+-------------
 rds_superuser | Cannot login                                   | {}              |
 rdsadmin      | Superuser, Create role, Create DB, Replication | {}              |
 testuser      | Create role, Create DB                         | {rds_superuser} |

testdb=>
ここでは、インスタンス作成時に指定した「testuser」というユーザで接続していますが、このユーザにはデータベースとユーザの作成権限があるようです。このユーザはスーパーユーザーではありません。

このユーザとは別に、「rdsadmin」というユーザがあり、このユーザが管理者権限を持っているようです。但し、我々AWSユーザはこのrdsadminというユーザは使えません。

■データベースのエンコーディングとロケール


次に、データベースのエンコーディングとロケールを見てみます。
testdb=> \l+
                                                                     List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   |   Size    | Tablespace |                Description
-----------+----------+----------+-------------+-------------+-----------------------+-----------+------------+--------------------------------------------
 postgres  | testuser | UTF8     | en_US.UTF-8 | en_US.UTF-8 |                       | 6570 kB   | pg_default | default administrative connection database
 rdsadmin  | rdsadmin | UTF8     | en_US.UTF-8 | en_US.UTF-8 | rdsadmin=CTc/rdsadmin | No Access | pg_default |
 template0 | rdsadmin | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/rdsadmin          +| 6457 kB   | pg_default | unmodifiable empty database
           |          |          |             |             | rdsadmin=CTc/rdsadmin |           |            |
 template1 | testuser | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/testuser          +| 6570 kB   | pg_default | default template for new databases
           |          |          |             |             | testuser=CTc/testuser |           |            |
 testdb    | testuser | UTF8     | en_US.UTF-8 | en_US.UTF-8 |                       | 6570 kB   | pg_default |
(5 rows)

testdb=>
デフォルトではデータベースのロケールは「en_US」となっているようです。

PostgreSQLを日常的に使っている方は、特に日本語を扱う場合にはロケールを「使用しない」または「C」に設定していると思います。そのため、デフォルトのままでは、日本語(というか、en_US以外を扱う時)に問題が生じる可能性があります。

PostgreSQLのロケールの詳細については、以下の記事を参照してください。
ロケールを「C」に設定したデータベースを使いたい場合、少しトリッキーなことをする必要があります。

ロケールを「C」にしたデータベースを新規に作成し、前のRDSで作成した最初のデータベースと入れ替えることで実現することができます。以下では、「testdb2」というデータベースを作成し、「testdb」と入れ替えています。
testdb=> CREATE DATABASE testdb2 WITH template template0 encoding 'utf8' lc_collate 'C' lc_ctype 'C';
CREATE DATABASE
testdb=> \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | testuser | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 rdsadmin  | rdsadmin | UTF8     | en_US.UTF-8 | en_US.UTF-8 | rdsadmin=CTc/rdsadmin
 template0 | rdsadmin | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/rdsadmin          +
           |          |          |             |             | rdsadmin=CTc/rdsadmin
 template1 | testuser | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/testuser          +
           |          |          |             |             | testuser=CTc/testuser
 testdb    | testuser | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
(5 rows)

testdb=> \c postgres
psql (9.3.0, server 9.3.1)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
You are now connected to database "postgres" as user "testuser".
postgres=> DROP DATABASE testdb;
DROP DATABASE
postgres=> ALTER DATABASE testdb2 RENAME TO testdb;
ALTER DATABASE
postgres=> \c testdb
psql (9.3.0, server 9.3.1)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
You are now connected to database "testdb" as user "testuser".
testdb=> \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | testuser | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 rdsadmin  | rdsadmin | UTF8     | en_US.UTF-8 | en_US.UTF-8 | rdsadmin=CTc/rdsadmin
 template0 | rdsadmin | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/rdsadmin          +
           |          |          |             |             | rdsadmin=CTc/rdsadmin
 template1 | testuser | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/testuser          +
           |          |          |             |             | testuser=CTc/testuser
 testdb    | testuser | UTF8     | C           | C           |
(5 rows)

testdb=>
これで、ロケールを「C」にしたtestdbを準備することができました。

■EXTENSION(エクステンション、拡張)


PostgreSQLの大きな特徴の一つは、その拡張性です。PostgreSQLの強みの一つとしてよく上げられるGIS拡張「PostGIS」も、EXTENSIONと呼ばれる仕組みで提供されています。

RDS for PostgreSQLで使用できるEXTENSIONの一覧を見てみます。
testdb=> select * FROM pg_available_extensions;
          name          | default_version | installed_version |                               comment
------------------------+-----------------+-------------------+---------------------------------------------------------------------
 cube                   | 1.0             |                   | data type for multidimensional cubes
 earthdistance          | 1.0             |                   | calculate great-circle distances on the surface of the Earth
 btree_gin              | 1.0             |                   | support for indexing common datatypes in GIN
 postgres_fdw           | 1.0             |                   | foreign-data wrapper for remote PostgreSQL servers
 pg_buffercache         | 1.0             |                   | examine the shared buffer cache
 pg_freespacemap        | 1.0             |                   | examine the free space map (FSM)
 intagg                 | 1.0             |                   | integer aggregator and enumerator (obsolete)
 unaccent               | 1.0             |                   | text search dictionary that removes accents
 postgis_topology       | 2.1.0           |                   | PostGIS topology spatial types and functions
 chkpass                | 1.0             |                   | data type for auto-encrypted passwords
 citext                 | 1.0             |                   | data type for case-insensitive character strings
 dict_xsyn              | 1.0             |                   | text search dictionary template for extended synonym processing
 dict_int               | 1.0             |                   | text search dictionary template for integers
 postgis_tiger_geocoder | 2.1.0           |                   | PostGIS tiger geocoder and reverse geocoder
 fuzzystrmatch          | 1.0             |                   | determine similarities and distance between strings
 pg_stat_statements     | 1.1             |                   | track execution statistics of all SQL statements executed
 pg_trgm                | 1.1             |                   | text similarity measurement and index searching based on trigrams
 hstore                 | 1.2             |                   | data type for storing sets of (key, value) pairs
 tsearch2               | 1.0             |                   | compatibility package for pre-8.3 text search functions
 intarray               | 1.0             |                   | functions, operators, and index support for 1-D arrays of integers
 uuid-ossp              | 1.0             |                   | generate universally unique identifiers (UUIDs)
 pgcrypto               | 1.0             |                   | cryptographic functions
 pgstattuple            | 1.1             |                   | show tuple-level statistics
 sslinfo                | 1.0             |                   | information about SSL certificates
 ltree                  | 1.0             |                   | data type for hierarchical tree-like structures
 pltcl                  | 1.0             |                   | PL/Tcl procedural language
 plpgsql                | 1.0             | 1.0               | PL/pgSQL procedural language
 btree_gist             | 1.0             |                   | support for indexing common datatypes in GiST
 plperl                 | 1.0             |                   | PL/Perl procedural language
 isn                    | 1.0             |                   | data types for international product numbering standards
 pgrowlocks             | 1.1             |                   | show row-level locking information
 tablefunc              | 1.0             |                   | functions that manipulate whole tables, including crosstab
 dblink                 | 1.1             |                   | connect to other PostgreSQL databases from within a database
 postgis                | 2.1.0           |                   | PostGIS geometry, geography, and raster spatial types and functions
(34 rows)

testdb=>
PostgreSQLのcontribにあるすべてのモジュールではないようですが、多くのEXTENSIONを使用できるようになっています(デフォルトでインストールされているのはplpgsqlのみ)。これらを使いたい場合には CREATE EXTENSION コマンドでインストールします。
testdb=> CREATE EXTENSION postgis;
CREATE EXTENSION
testdb=> \d
               List of relations
 Schema |       Name        | Type  |  Owner
--------+-------------------+-------+----------
 public | geography_columns | view  | rdsadmin
 public | geometry_columns  | view  | rdsadmin
 public | raster_columns    | view  | rdsadmin
 public | raster_overviews  | view  | rdsadmin
 public | spatial_ref_sys   | table | rdsadmin
(5 rows)

testdb=>

■レプリケーション


今回はマルチAZ構成でデプロイしたので、レプリケーションの設定を見てみます。レプリケーション関連の統計情報は pg_stat_replication で取得します。
testdb=> SELECT * FROM pg_stat_replication;
 pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | state | sent_location | write_location | flush_location | replay_location | sync_priority | sync_state
-----+----------+---------+------------------+-------------+-----------------+-------------+---------------+-------+-------------
--+----------------+----------------+-----------------+---------------+------------
(0 rows)

testdb=>
上記の通り、レプリケーションの統計情報が存在していませんでした。RDSのマルチAZ構成では、PostgreSQLのレプリケーション機能は使っていないようです。

ここからは想像ですが、以下のログアーカイブの設定やタイムアウト値から考えると、RDS for PostgreSQLのマルチAZ構成では、アーカイブログを介したホットスタンバイで構成しているのかもしれません。

■設定パラメータ(postgresql.conf)


最後に postgresql.conf の設定(pg_settings)を見てみます。 これは長くなるので、以下のGistに張り付けておきます。
特に変わったところは見られませんでしたが、マルチAZ構成でレプリケーションを使っていると想像していたものの、実際にはアーカイブログによるホットスタンバイ構成っぽい、ということくらいでしょうか。

■まとめ

というわけで、実際に使う上で若干気になるところもありましたが、まずは使い始めてみる、という点ではさすがによくできたサービスだと思います。興味のある方はぜひ試してみてください。私も少しずつ使ってみようと思います。

では、また。

(追記 11/18 16:22)
上記で「ホットスタンバイのHAかも」と書いたのですが、よく考えたら wal_level が archive なので、ホットスタンバイでもないと思われます。

ただ、Amazon RDS for PostgreSQLのドキュメント

"This allows you to restore your DB Instance to any second during your retention period, up to the last five minutes."

とあることと、archive_timeoutの300秒の設定を併せて考えると、おそらくアーカイブログの機能を使って可用性を確保しているのではないかと思います。(もしかしたら全然違うAWSの独自機能を使っているかもしれませんが)

18 件のコメント:

  1. Nice work, your blog is concept-oriented, kindly share more blogs like this
    AWS Online Course

    返信削除
  2. Appreciate it for this post, I am a big fan of this internet site would like to keep updated.온라인경마

    返信削除
  3. You have done a great job on this article. It’s very readable and highly intelligent. You have even managed to make it understandable and easy to read. You have some real writing talent.
    스포츠토토

    返信削除
  4. Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. 파칭코사이트인포

    返信削除
  5. Dynamic Health Staff stands as the leading nursing recruitment agency in India, specializing in matching highly qualified nursing professionals with top-tier healthcare institutions. Known for our robust selection process, we ensure only the most skilled and compassionate candidates are chosen. Our tailored training programs provide nurses with the latest industry expertise and knowledge. Efficient placement procedures guarantee seamless integration into healthcare teams. Committed to excellence and ethical standards, we have earned a trusted reputation within the medical community. With a focus on continuous career development, we help nurses thrive in their professional journeys. Dynamic Health Staff is dedicated to enhancing healthcare standards by fostering a competent and adaptable nursing workforce across India.
    https://dynamichealthstaff.com/

    返信削除
  6. Shared hosting in India is an economical and popular choice for websites, especially for small to medium-sized businesses. Providers like Hostinger and Bluehost offer attractive entry-level packages starting at ₹59 and ₹199 per month, respectively. These plans usually come with essential features such as 100 GB bandwidth, free SSL certificates, and automatic backups, ensuring security and reliability. Shared hosting is ideal for websites with moderate traffic and limited budgets. The shared nature of the server resources helps keep costs low while providing sufficient performance for most everyday needs. Additionally, many providers include user-friendly control panels and robust customer support, making it accessible even for those with limited technical skills.
    https://onohosting.com/

    返信削除
  7. The price of breast treatment in Delhi significantly varies, influenced largely by the type of healthcare facility and the complexity of the treatment required. Private hospitals, equipped with advanced technologies and experienced specialists, typically charge between INR 80,000 and INR 2,50,000 for surgical procedures. On the other hand, government hospitals offer more cost-effective solutions while still maintaining essential care standards. Additional costs may arise from pre-operative diagnostics, post-operative care, and necessary rehabilitation. Health insurance is instrumental in reducing out-of-pocket expenses, making it crucial for patients to thoroughly understand their policy coverage. Consulting with healthcare providers for a detailed and personalized cost estimate is strongly recommended.
    https://www.breastoncosurgery.com/services/breast-cancer-treatment-cost-in-delhi/

    返信削除
  8. Dr. Pooja Sharma is a highly regarded colon cancer specialist in Ahmedabad, celebrated for her exemplary skill and compassionate care. With over 22 years of experience, she is proficient in both traditional and modern surgical techniques, ensuring the best possible treatment outcomes. Dr. Sharma is affiliated with top hospitals featuring state-of-the-art technology and comprehensive cancer care facilities. Her patient-centered approach emphasizes personalized treatment plans tailored to individual needs, improving recovery and quality of life. Known for her meticulous surgical precision and empathetic consultation style, Dr. Sharma consistently earns high praise from both patients and peers. She remains deeply committed to medical research, continuously enhancing her knowledge and practice. Dr. Sharma’s dedication to excellence makes her a trusted name in colon cancer treatment in Ahmedabad.
    https://drvirajlavingia.com/colorectal-cancer-specialist-in-ahmedabad

    返信削除
  9. A distinguished breast cancer surgeon in Mumbai is renowned for expertise in complex surgical procedures. Board-certified and affiliated with leading medical institutions, they ensure the highest standards of patient care. The surgeon is committed to ongoing research and education, staying at the forefront of oncology advancements. Patients benefit from tailored surgical plans, thorough pre-operative evaluations, and meticulous post-operative care. Known for clear and compassionate communication, the surgeon prioritizes patient comfort and well-being. This dedication to excellence has established the surgeon as a trusted and respected authority in breast cancer surgery.
    https://drnitanair.com/about/about-top-breast-cancer-surgeon-mumbai

    返信削除
  10. Dr. Shona Nag is a highly esteemed breast cancer surgeon based in Pune, known for her exceptional clinical expertise and compassionate care. With extensive experience in diagnosing and treating various breast cancer cases, she employs advanced techniques such as genomic testing and targeted therapies. Dr. Nag adopts a multidisciplinary approach, working closely with oncologists, radiologists, and pathologists to create personalized treatment plans. Her commitment to continuous medical education ensures she is always at the cutting edge of breast cancer treatment. Respected by her peers and deeply trusted by her patients, Dr. Nag exemplifies excellence in breast cancer care, making her a leading figure in the field in Pune.
    https://www.drshonanagbreastcancer.in/understanding-cancer/what-is-cancer-can-cancer-be-cured

    返信削除
  11. Cheap logo designers in Delhi are essential for businesses seeking cost-effective branding solutions without compromising on quality. These designers possess a keen understanding of market trends and client needs, allowing them to create distinctive logos that encapsulate the essence of a brand. Offering a diverse range of design packages, they cater to both startups and established businesses, ensuring a suitable option for every budget. The design process typically includes initial concept creation, client feedback, and revisions, promoting collaborative and satisfying outcomes. With a focus on quick turnaround times, these professionals help businesses establish a strong visual presence in a competitive market. Their commitment to client satisfaction fosters enduring partnerships, resulting in logos that resonate with target audiences. By choosing affordable logo design services in Delhi, companies can make impactful first impressions that enhance brand recognition. Ultimately, these designers play a vital role in helping businesses define their identity and stand out in an increasingly crowded landscape.
    https://olycoder.com/cheap-logo-designers-delhi

    返信削除