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

34.17. 接続サービスファイル #

<title>The Connection Service File</title>

The connection service file allows libpq connection parameters to be associated with a single service name. That service name can then be specified in a libpq connection string, and the associated settings will be used. This allows connection parameters to be modified without requiring a recompile of the libpq-using application. The service name can also be specified using the <envar>PGSERVICE</envar> environment variable. 接続サービスファイルにより、libpq接続パラメータをひとつのサービス名に関連付けることができます。 サービス名は、libpq接続文字列によって指定され、関連付けられた設定が利用されます。 これは、接続パラメータをlibpqを使用するアプリケーションの再コンパイルをせずに修正できるというものです。 サービス名はPGSERVICE環境変数を利用することで使用できます。

Service names can be defined in either a per-user service file or a system-wide file. If the same service name exists in both the user and the system file, the user file takes precedence. By default, the per-user service file is named <filename>~/.pg_service.conf</filename>. On Microsoft Windows, it is named <filename>%APPDATA%\postgresql\.pg_service.conf</filename> (where <filename>%APPDATA%</filename> refers to the Application Data subdirectory in the user's profile). A different file name can be specified by setting the environment variable <envar>PGSERVICEFILE</envar>. The system-wide file is named <filename>pg_service.conf</filename>. By default it is sought in the <filename>etc</filename> directory of the <productname>PostgreSQL</productname> installation (use <literal>pg_config &#45;-sysconfdir</literal> to identify this directory precisely). Another directory, but not a different file name, can be specified by setting the environment variable <envar>PGSYSCONFDIR</envar>. サービス名は、ユーザ単位のサービスファイルまたはシステム全体のファイルのいずれかで定義できます。 ユーザとシステムファイルの両方に同じサービス名が存在する場合は、ユーザファイルが優先されます。 デフォルトでは、ユーザ単位のサービスファイルは~/.pg_service.confにあります。 Microsoft Windowsでは、%APPDATA%\postgresql\.pg_service.confという名前です(%APPDATA%は、ユーザプロファイル内のApplication Dataサブディレクトリです)。 これは環境変数PGSERVICEFILEを設定することで上書きできます。 システム全体のファイルはpg_service.confという名前です。 デフォルトでは、PostgreSQLインストールのetcディレクトリに検索されます(このディレクトリを正確に識別するにはpg_config--sysconfdirを使用します)。 環境変数PGSYSCONFDIRを設定することで、別のディレクトリを指定できますが、異なるファイル名は指定できません。

Either service file uses an <quote>INI file</quote> format where the section name is the service name and the parameters are connection parameters; see <xref linkend="libpq-paramkeywords"/> for a list. For example: どちらのサービスファイルもINIファイル書式を使用します。 セクション名がサービス名となり、パラメータが接続パラメータです。 34.1.2のリストを参照してください。 以下に例を示します。

# comment
[mydb]
host=somehost
port=5433
user=admin

An example file is provided in the <productname>PostgreSQL</productname> installation at <filename>share/pg_service.conf.sample</filename>. 例となるファイルがPostgreSQLインストールのshare/pg_service.conf.sampleにあります。

Connection parameters obtained from a service file are combined with parameters obtained from other sources. A service file setting overrides the corresponding environment variable, and in turn can be overridden by a value given directly in the connection string. For example, using the above service file, a connection string <literal>service=mydb port=5434</literal> will use host <literal>somehost</literal>, port <literal>5434</literal>, user <literal>admin</literal>, and other parameters as set by environment variables or built-in defaults. サービスファイルから取得された接続パラメータは、他のソースから取得されたパラメータと組み合わされます。 サービスファイルの設定は、対応する環境変数を上書きし、接続文字列で直接指定された値によって上書きすることができます。 たとえば、上記のサービスファイルを使用すると、接続文字列service=mydb port=5434は、hostsomehost、port5434、useradmin、および環境変数または組み込みデフォルトで設定されたその他のパラメータを使用します。