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

23.1. 概要 #

<title>Overview</title>

A small number of objects, like role, database, and tablespace names, are defined at the cluster level and stored in the <literal>pg_global</literal> tablespace. Inside the cluster are multiple databases, which are isolated from each other but can access cluster-level objects. Inside each database are multiple schemas, which contain objects like tables and functions. So the full hierarchy is: cluster, database, schema, table (or some other kind of object, such as a function). ロール、データベース、テーブル空間名のような少数のオブジェクトはクラスタレベルで定義されており、pg_globalテーブル空間に格納されています。 クラスタの中には複数のデータベースがあり、互いに分離されているもののクラスタレベルのオブジェクトにはアクセスできます。 各データベースの中には複数のスキーマがあり、スキーマはテーブルや関数などのオブジェクトを含みます。 したがって階層の全体像は、クラスタ、データベース、スキーマ、テーブル(や関数などの何らかのオブジェクト)となります。

When connecting to the database server, a client must specify the database name in its connection request. It is not possible to access more than one database per connection. However, clients can open multiple connections to the same database, or different databases. Database-level security has two components: access control (see <xref linkend="auth-pg-hba-conf"/>), managed at the connection level, and authorization control (see <xref linkend="ddl-priv"/>), managed via the grant system. Foreign data wrappers (see <xref linkend="postgres-fdw"/>) allow for objects within one database to act as proxies for objects in other database or clusters. The older dblink module (see <xref linkend="dblink"/>) provides a similar capability. By default, all users can connect to all databases using all connection methods. データベースサーバに接続する時、クライアントはその接続要求の中で接続するデータベース名を指定しなければなりません。 1つの接続で複数のデータベースにアクセスすることはできません。 しかし、クライアントは同じデータベースに対して複数の接続を開いたり、異なるデータベースに対して複数の接続を開いたりできます。 データベースレベルでのセキュリティには2つの構成要素があります。接続レベルで管理されるアクセス制御(21.1参照)と、権限付与システムで管理される認証制御(5.7参照)です。 外部データラッパー(postgres_fdw参照)により、1つのデータベース内のオブジェクトが他のデータベースやクラスタ内にあるオブジェクトに対するプロキシとして動作できます。 古いdblinkモジュール(dblink参照)は同様の機能を提供します。 デフォルトでは、すべてのユーザはすべてのデータベースにすべての接続方法で接続できます。

If one <productname>PostgreSQL</productname> server cluster is planned to contain unrelated projects or users that should be, for the most part, unaware of each other, it is recommended to put them into separate databases and adjust authorizations and access controls accordingly. If the projects or users are interrelated, and thus should be able to use each other's resources, they should be put in the same database but probably into separate schemas; this provides a modular structure with namespace isolation and authorization control. More information about managing schemas is in <xref linkend="ddl-schemas"/>. 1つのPostgreSQLサーバクラスタに、たいていの場合お互いのことを意識しない、関係のないプロジェクトやユーザを含めるつもりなら、これらを別々のデータベースに含め、それに従って認証制御とアクセス制御を調整することが推奨されます。 複数のデータベースは物理的に分離されていて、アクセス制御は接続レベルで管理されています。 したがって、分離して、ほとんどの場面で互いに見えないようにする必要のある複数のプロジェクトやユーザを単一のPostgreSQLサーバインスタンスに収容する場合、これらを別々のデータベースに含めることが推奨されます。 もし、複数のプロジェクトやユーザが相互に関連していて互いのリソースを使用できる必要がある場合、これらは同じデータベースに含めるべきですが、スキーマを別にすることは可能です。これは名前空間での分離と認証制御によるモジュラー構造を提供します。 スキーマの管理についての詳細は5.9に記載されています。

While multiple databases can be created within a single cluster, it is advised to consider carefully whether the benefits outweigh the risks and limitations. In particular, the impact that having a shared WAL (see <xref linkend="wal"/>) has on backup and recovery options. While individual databases in the cluster are isolated when considered from the user's perspective, they are closely bound from the database administrator's point-of-view. 1つのクラスタ内に複数のデータベースを作成できますが、その利点がその危険性と制限に勝るかどうか慎重に検討することを勧めます。 特に、共有のWAL(第30章参照)を持つことの影響がバックアップとリカバリのオプションにあります。 クラスタ内の個々のデータベースは、ユーザの視点から考えれば分離していても、データベース管理者の観点からは密接に結びついています。

Databases are created with the <command>CREATE DATABASE</command> command (see <xref linkend="manage-ag-createdb"/>) and destroyed with the <command>DROP DATABASE</command> command (see <xref linkend="manage-ag-dropdb"/>). To determine the set of existing databases, examine the <structname>pg_database</structname> system catalog, for example データベースはCREATE DATABASEコマンド(23.2を参照)で作成され、DROP DATABASEコマンド(23.5を参照)で破棄されます。 既存のデータベース群を求めるには、以下の例のようにpg_databaseシステムカタログを確認してください。

SELECT datname FROM pg_database;

The <xref linkend="app-psql"/> program's <literal>\l</literal> meta-command and <option>-l</option> command-line option are also useful for listing the existing databases. また、psqlプログラムの\lメタコマンドや-lコマンドラインオプションも既存のデータベースを列挙する際に役に立ちます。

注記

The <acronym>SQL</acronym> standard calls databases <quote>catalogs</quote>, but there is no difference in practice. 標準SQLでは、データベースをカタログ(catalog)と呼ぶこともありますが、実際のところ違いはありません。