TECH BLOG
技術ブログ

ARTICLE

  • 2023-09-20 PostgreSQL

    PostgreSQL16ではconfigureの–with-icuオプションがデフォルトで有効となりました。

PostgreSQL16の icu ロケールプロバイダに関する仕様変更

タイトルの通り、PostgreSQL16 では configure 時に --with-icu オプションがデフォルトで有効となるようです(2023 年 09 月 20 日時点)。
そのため、icu 関連ライブラリがインストールされていないと、configure でエラーが発生するようになります。
また、PostgreSQL16 の beta1 が公開された時点では「ロケールプロバイダのデフォルトを icu ロケールプロバイダとする」という仕様変更もあったそうですが、取り消しとなったようです。

実際に挙動を確認します

では、具体的に何がどう変更されるのかを実際に PostgreSQL16 rc1 をインストールして確認してみました。

検証に利用した環境は

  • Ubuntu 22.04
  • PostgreSQL 16 rc1

となります。

PostgreSQL16 rc1 をインストールする

PostgreSQL 15 以前で、インストール時に必要なライブラリをインストール
# apt-get update
# apt install gcc
# apt install make
# apt install zlib1g-dev
# apt install libreadline-dev

PostgreSQL 15 以前で必要なライブラリ群をインストールしました。

PostgreSQL16 rc1 をビルド
# wget https://ftp.postgresql.org/pub/source/v16rc1/postgresql-16rc1.tar.gz
# tar -xvzf postgresql-16rc1.tar.gz
# cd postgresql-16rc1/
# ./configure --prefix=/usr/local/pgsql-16/
checking build system type... aarch64-unknown-linux-gnu
checking host system type... aarch64-unknown-linux-gnu
:
:
:
checking for icu-uc icu-i18n... no
configure: error: ICU library not found
If you have ICU already installed, see config.log for details on the
failure.  It is possible the compiler isn't looking in the proper directory.
Use --without-icu to disable ICU support.

予定通り configure でエラーが発生しました。
icu 関連のライブラリをインストールするか、--without-icu オプションをつけて icu サポートを無効にしてください、とのことです。

--without-icu オプションをつけて configure

メッセージ通りに --without-out オプションをつけて、再度 configure します。

# ./configure --prefix=/usr/local/pgsql-16/ --without-icu
checking build system type... aarch64-unknown-linux-gnu
checking host system type... aarch64-unknown-linux-gnu
:
:
config.status: linking src/include/port/linux.h to src/include/pg_config_os.h
config.status: linking src/makefiles/Makefile.linux to src/Makefile.port

# echo $?
0

無事にインストールできました。
しかし、icu をサポートした状態にしたいので、必要なライブラリをインストールして再度 configure します。

icu 関連のライブラリをインストールして、再度 configure

インストールするライブラリは libicu-dev と pkgconf の 2 つです。

# apt install libicu-dev
# apt install pkgconf

必要なライブラリのインストールが完了したので、configure します。

# ./configure --prefix=/usr/local/pgsql-16/
checking build system type... aarch64-unknown-linux-gnu
checking host system type... aarch64-unknown-linux-gnu
:
:
config.status: linking src/include/port/linux.h to src/include/pg_config_os.h
config.status: linking src/makefiles/Makefile.linux to src/Makefile.port

# echo $?
0

icu 関連のライブラリをインストールすることで、configure が問題なく完了しました。
後は make と make install してインストール完了となります。

# make && make install

こちらも問題なく完了しました。

データベースクラスタの作成

インストールが完了しましたので、例として data_v16 という名前のデータベースクラスタを作成して、ロケールプロバイダを確認します。
インストールした PostgreSQL 16 rc1 にパスを通した後、オプションなしで initdb コマンドを実行し、データベースクラスタを作成します。
実際に実行する initdb コマンドは下記となります。

$ initdb -D ./data_v16

作成したデータベースクラスタを起動します。

$ pg_ctl start -D ./data_v16

問題なく起動できましたら、ロケールプロバイダを確認します。
ロケールプロバイダは psql の -l オプションで確認できます。

$ psql -l
                                                   List of databases
   Name    |  Owner   | Encoding | Locale Provider | Collate |  Ctype  | ICU Locale | ICU Rules |   Access privileges   
-----------+----------+----------+-----------------+---------+---------+------------+-----------+-----------------------
 postgres  | postgres | UTF8     | libc            | C.UTF-8 | C.UTF-8 |            |           | 
 template0 | postgres | UTF8     | libc            | C.UTF-8 | C.UTF-8 |            |           | =c/postgres          +
           |          |          |                 |         |         |            |           | postgres=CTc/postgres
 template1 | postgres | UTF8     | libc            | C.UTF-8 | C.UTF-8 |            |           | =c/postgres          +
           |          |          |                 |         |         |            |           | postgres=CTc/postgres
(3 rows)
  • ロケールプロバイダ(Locale Provider)は libc であることを確認しました。
icu ロケールプロバイダを利用する。

ロケールプロバイダを指定するには initdb の --locale-provider オプションを利用します。
また、icu ロケールプロバイダを利用する際には --icu-locale オプションの指定も必要となります。

$ initdb --locale-provider=icu --icu-locale=ja_JP.UTF8 -D v16_data_icu

作成された v16_data_icu データベースクラスタを起動し、ロケールプロバイダを確認します。

$ pg_ctl start -D v16_data_icu
$ psql -l
                                                   List of databases
   Name    |  Owner   | Encoding | Locale Provider | Collate |  Ctype  | ICU Locale | ICU Rules |   Access privileges   
-----------+----------+----------+-----------------+---------+---------+------------+-----------+-----------------------
 postgres  | postgres | UTF8     | icu             | C.UTF-8 | C.UTF-8 | ja-JP      |           | 
 template0 | postgres | UTF8     | icu             | C.UTF-8 | C.UTF-8 | ja-JP      |           | =c/postgres          +
           |          |          |                 |         |         |            |           | postgres=CTc/postgres
 template1 | postgres | UTF8     | icu             | C.UTF-8 | C.UTF-8 | ja-JP      |           | =c/postgres          +
           |          |          |                 |         |         |            |           | postgres=CTc/postgres
(3 rows)

無事に icu ロケールプロバイダとなりました。

まとめ

本記事では PostgreSQL16 rc1 を実際にインストールして、ロケールプロバイダの指定方法を確認しました。
次回以降のブログ記事で、デフォルトのロケールプロバイダである libc と icu の違いについても検証した結果をご報告したいと考えています。

CATEGORY

ARCHIVE

PostgreSQLの
ハイパフォーマンスチューニングのご相談は
株式会社インサイトまで
お気軽にお問い合わせください。

CONTACT