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

34.16. パスワードファイル #

<title>The Password File</title>

The file <filename>.pgpass</filename> in a user's home directory can contain passwords to be used if the connection requires a password (and no password has been specified otherwise). On Microsoft Windows the file is named <filename>%APPDATA%\postgresql\pgpass.conf</filename> (where <filename>%APPDATA%</filename> refers to the Application Data subdirectory in the user's profile). Alternatively, the password file to use can be specified using the connection parameter <xref linkend="libpq-connect-passfile"/> or the environment variable <envar>PGPASSFILE</envar>. ユーザのホームディレクトリの.pgpassは、接続にパスワードが必要な場合(かつ、他に指定されたパスワードが無かった場合)に使用するパスワードを格納するファイルです。 Microsoft Windowsでは、このファイルの名前は%APPDATA%\postgresql\pgpass.conf(ここで%APPDATA%はユーザのプロファイル内のアプリケーションデータディレクトリ)です。 他に、接続パラメータpassfileを利用するか、環境変数PGPASSFILEで、パスワードファイルを指定できます。

This file should contain lines of the following format: このファイル内の行の書式は次の通りです。

hostname:port:database:username:password

(You can add a reminder comment to the file by copying the line above and preceding it with <literal>#</literal>.) Each of the first four fields can be a literal value, or <literal>*</literal>, which matches anything. The password field from the first line that matches the current connection parameters will be used. (Therefore, put more-specific entries first when you are using wildcards.) If an entry needs to contain <literal>:</literal> or <literal>\</literal>, escape this character with <literal>\</literal>. The host name field is matched to the <literal>host</literal> connection parameter if that is specified, otherwise to the <literal>hostaddr</literal> parameter if that is specified; if neither are given then the host name <literal>localhost</literal> is searched for. The host name <literal>localhost</literal> is also searched for when the connection is a Unix-domain socket connection and the <literal>host</literal> parameter matches <application>libpq</application>'s default socket directory path. In a standby server, a database field of <literal>replication</literal> matches streaming replication connections made to the primary server. The database field is of limited usefulness otherwise, because users have the same password for all databases in the same cluster. (このファイルでは、上のような行をコピーし、その先頭に#をつけて忘れないようにコメントとして残すことができます。) 先頭の4フィールドはそれぞれリテラル値にすることも、あるいはすべてに一致する*を使用することもできます。 最初に現在の接続パラメータと一致した行のパスワードフィールドが使用されます。 (従って、ワイルドカードを使用する場合は、始めの方により具体的な項目を入力してください。) 項目内に:または\を含める必要があれば、\でこれらの文字をエスケープする必要があります。 ホスト名フィールドは、host接続パラメータか、もし指定されていれば、hostaddrパラメータと一致します。 どちらも指定されていなければ、ホスト名localhostが検索されます。 接続がUnixドメインソケット接続で、hostパラメータがlibpqのデフォルトソケットディレクトリパスに一致した場合も、ホスト名localhostが検索されます。 スタンバイサーバでは、replicationという名称のデータベースは、プライマリサーバとの間でなされるストリーミングレプリケーション用の接続に一致します。 同一のクラスタ内のすべてのデータベースに対するパスワードは同じものですので、データベースフィールドの有用性は限定的なものです。

On Unix systems, the permissions on a password file must disallow any access to world or group; achieve this by a command such as <command>chmod 0600 ~/.pgpass</command>. If the permissions are less strict than this, the file will be ignored. On Microsoft Windows, it is assumed that the file is stored in a directory that is secure, so no special permissions check is made. Unixシステムにおいて、パスワードファイルの権限はグループ、他者へのアクセスをすべて拒否しなければなりません。 これはchmod 0600 ~/.pgpassといったコマンドによって行います。 権限をこれよりも緩くすると、このファイルは無視されます。 Microsoft Windowsにおいては、このファイルが安全なディレクトリに格納されていることを前提としていますので、特別に行われる権限の検査はありません。