バージョンごとのドキュメント一覧

第75章 システムカタログの宣言と初期内容

目次

75.1. システムカタログの宣言ルール
75.2. システムカタログ初期データ
75.2.1. データファイル形式
75.2.2. OIDの割当
75.2.3. OID参照検索
75.2.4. 配列型の自動作成
75.2.5. データファイルの編集方法
75.3. BKIファイル形式
75.4. BKIコマンド
75.5. BKIファイルのブートストラップの構成
75.6. BKIの例
<title>System Catalog Declarations and Initial Contents</title>

<productname>PostgreSQL</productname> uses many different system catalogs to keep track of the existence and properties of database objects, such as tables and functions. Physically there is no difference between a system catalog and a plain user table, but the backend C code knows the structure and properties of each catalog, and can manipulate it directly at a low level. Thus, for example, it is inadvisable to attempt to alter the structure of a catalog on-the-fly; that would break assumptions built into the C code about how rows of the catalog are laid out. But the structure of the catalogs can change between major versions. PostgreSQLは、テーブルや関数のようなデータベースオブジェクトの存在の有無と特性を追跡するために、多くの異なるシステムカタログを使用します。 物理的な観点ではシステムカタログとユーザーテーブルの間に違いはありませんが、バックエンドのCコードはそれぞれのカタログの構造と特性を把握しており、直接カタログを低レベルで操作することができます。 ですから、たとえばカタログの構造を思いつきで変更しようとするのはおすすめできません。そのことによって、Cのコードに組み込まれているカタログの行のレイアウトに関する前提を壊してしまうことになるからです。 とはいえ、カタログの構造はメジャーバージョン間で変更されることがあります。

The structures of the catalogs are declared in specially formatted C header files in the <filename>src/include/catalog/</filename> directory of the source tree. For each catalog there is a header file named after the catalog (e.g., <filename>pg_class.h</filename> for <structname>pg_class</structname>), which defines the set of columns the catalog has, as well as some other basic properties such as its OID. カタログの構造は、ソースツリーのsrc/include/catalog/ディレクトリの中の特殊な形式のCヘッダファイルに宣言されています。 個々のカタログに対応して、カタログと同じ名前のヘッダファイルが存在し(たとえば、pg_classに対してpg_class.hというように)、カタログが持つ一連の列やOIDのような基本的な特性を定義しています。

Many of the catalogs have initial data that must be loaded into them during the <quote>bootstrap</quote> phase of <application>initdb</application>, to bring the system up to a point where it is capable of executing SQL commands. (For example, <filename>pg_class.h</filename> must contain an entry for itself, as well as one for each other system catalog and index.) This initial data is kept in editable form in data files that are also stored in the <filename>src/include/catalog/</filename> directory. For example, <filename>pg_proc.dat</filename> describes all the initial rows that must be inserted into the <structname>pg_proc</structname> catalog. SQLコマンドを実行可能な状態にまでシステムを持っていくために、多くのカタログはinitdbbootstrapフェーズで読み込まなければならない初期データを持っています。 (たとえば、pg_class.hは、他のシステムカタログとインデックス同様、自分自身のエントリを含んでいなければなりません。) この初期データも、src/include/catalog/ディレクトリに格納されているデータファイル中に編集可能な形式で保存されています。 たとえば、pg_proc.datは、pg_procカタログに挿入されるべき初期の行を記述しています。

To create the catalog files and load this initial data into them, a backend running in bootstrap mode reads a <acronym>BKI</acronym> (Backend Interface) file containing commands and initial data. The <filename>postgres.bki</filename> file used in this mode is prepared from the aforementioned header and data files, while building a <productname>PostgreSQL</productname> distribution, by a Perl script named <filename>genbki.pl</filename>. Although it's specific to a particular <productname>PostgreSQL</productname> release, <filename>postgres.bki</filename> is platform-independent and is installed in the <filename>share</filename> subdirectory of the installation tree. カタログファイルを作り初期データをそこにロードするために、ブートストラップモードで実行中のバックエンドは、コマンドと初期データを含むBKI(Backend Interface: バックエンドインタフェース)ファイルを読み込みます。 このモードで使用されるpostgres.bkiは、genbki.plというPerlスクリプトを使って、PostgreSQLディストリビューションを構築する過程で前述のヘッダーとデータファイルから作成されます。 postgres.bkiPostgreSQLの特定のリリースに固有のものですが、プラットフォームからは独立しており、インストレーションツリーのshareサブディレクトリにインストールされます。

<filename>genbki.pl</filename> also produces a derived header file for each catalog, for example <filename>pg_class_d.h</filename> for the <structname>pg_class</structname> catalog. This file contains automatically-generated macro definitions, and may contain other macros, enum declarations, and so on that can be useful for client C code that reads a particular catalog. genbki.plは、他にも各々のカタログで使用する、たとえばpg_classのためのpg_class_d.hのような派生ファイルを生成します。 このファイルには自動生成されたマクロ定義が含まれているほか、他のマクロとenum宣言も含まれており、特定のカタログを読み込むクライアントCコードに役立ちます。

Most PostgreSQL developers don't need to be directly concerned with the <acronym>BKI</acronym> file, but almost any nontrivial feature addition in the backend will require modifying the catalog header files and/or initial data files. The rest of this chapter gives some information about that, and for completeness describes the <acronym>BKI</acronym> file format. ほとんどのPostgreSQL開発者は直接BKIファイルのことを気にかける必要はありませんが、バックエンドに些細ではない機能を追加する際にはカタログヘッダファイル、あるいはまた初期データファイルの変更が必要になるでしょう。 この章の残りの部分でそれについての情報をお届けします。 また網羅性のために、BKIファイルのフォーマットも説明します。