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

34.1. データベース接続制御関数 #

<title>Database Connection Control Functions</title>

The following functions deal with making a connection to a <productname>PostgreSQL</productname> backend server. An application program can have several backend connections open at one time. (One reason to do that is to access more than one database.) Each connection is represented by a <structname>PGconn</structname><indexterm><primary>PGconn</primary></indexterm> object, which is obtained from the function <xref linkend="libpq-PQconnectdb"/>, <xref linkend="libpq-PQconnectdbParams"/>, or <xref linkend="libpq-PQsetdbLogin"/>. Note that these functions will always return a non-null object pointer, unless perhaps there is too little memory even to allocate the <structname>PGconn</structname> object. The <xref linkend="libpq-PQstatus"/> function should be called to check the return value for a successful connection before queries are sent via the connection object. PostgreSQLのバックエンドサーバとの接続を作成するには、以下の関数を使用します。 アプリケーションプログラムはバックエンドとの接続を一度に複数個開くことができます。 (そのようにする1つの理由として、複数のデータベースへのアクセスが挙げられます。) 個々の接続は、PQconnectdbPQconnectdbParamsまたはPQsetdbLogin関数を呼び出すことで得られるPGconnオブジェクトによって表されます。 なお、これらの関数は、PGconnオブジェクトに割り当てるほんのわずかなメモリの余裕さえもない場合を除き、NULLではなく常にオブジェクトのポインタを返します。 また、この接続オブジェクトを通じて問い合わせを送る前に、PQstatus関数を呼び出して、データベースとの接続に成功したか戻り値を検査しなければなりません。

警告

If untrusted users have access to a database that has not adopted a <link linkend="ddl-schemas-patterns">secure schema usage pattern</link>, begin each session by removing publicly-writable schemas from <varname>search_path</varname>. One can set parameter key word <literal>options</literal> to value <literal>-csearch_path=</literal>. Alternately, one can issue <literal>PQexec(<replaceable>conn</replaceable>, "SELECT pg_catalog.set_config('search_path', '', false)")</literal> after connecting. This consideration is not specific to <application>libpq</application>; it applies to every interface for executing arbitrary SQL commands. 信頼できないユーザが、安全なスキーマ使用パターンを適用していないデータベースへアクセスする際には、セッション開始時にsearch_pathから、第三者が書き込みができるスキーマを削除してください。 これはoptionsパラメータキーワードに値-csearch_path=を設定することで可能となります。 別の方法としては、接続後にPQexec(conn, "SELECT pg_catalog.set_config('search_path', '', false)")を発行しても構いません。 このような配慮は、libpqに限ったことではありません。 任意のSQLコマンドを実行するすべてのインタフェースに当てはまります。

警告

On Unix, forking a process with open libpq connections can lead to unpredictable results because the parent and child processes share the same sockets and operating system resources. For this reason, such usage is not recommended, though doing an <function>exec</function> from the child process to load a new executable is safe. Unix上で、libpq接続を開いたプロセスのフォークは、親と子のプロセスが同じソケットとオペレーティングシステムの資源を共有するため、予期せぬ結果を招くことがあります。 この理由により、新規実行形式を子プロセスが読み込むためexecを行うことが安全と言っても、このような使用方法は推奨されません。

PQconnectdbParams #

Makes a new connection to the database server. 新たにデータベースサーバへの接続を作成します。

PGconn *PQconnectdbParams(const char * const *keywords,
                          const char * const *values,
                          int expand_dbname);

This function opens a new database connection using the parameters taken from two <symbol>NULL</symbol>-terminated arrays. The first, <literal>keywords</literal>, is defined as an array of strings, each one being a key word. The second, <literal>values</literal>, gives the value for each key word. Unlike <xref linkend="libpq-PQsetdbLogin"/> below, the parameter set can be extended without changing the function signature, so use of this function (or its nonblocking analogs <xref linkend="libpq-PQconnectStartParams"/> and <function>PQconnectPoll</function>) is preferred for new application programming. この関数は、2つのNULL終端の配列から取得したパラメータを使用して、データベースとの接続を新たに1つ確立します。 1つ目は文字列配列として定義されるkeywordsで、それぞれがキーワードとなります。 2つ目はvaluesで、各キーワードの値を提供します。 後述のPQsetdbLoginとは異なり、関数のシグネチャを変更せずにパラメータ集合を拡張できますので、アプリケーションプログラムを新たに作成する際には、この関数(もしくは非ブロックモードでよく似た処理をするPQconnectStartParamsPQconnectPoll)を使用することをお勧めします。

The currently recognized parameter key words are listed in <xref linkend="libpq-paramkeywords"/>. 現在有効なパラメータキーワードを34.1.2に示します。

The passed arrays can be empty to use all default parameters, or can contain one or more parameter settings. They must be matched in length. Processing will stop at the first <symbol>NULL</symbol> entry in the <literal>keywords</literal> array. Also, if the <literal>values</literal> entry associated with a non-<symbol>NULL</symbol> <literal>keywords</literal> entry is <symbol>NULL</symbol> or an empty string, that entry is ignored and processing continues with the next pair of array entries. 渡される配列は、すべてのデフォルトパラメータを使用するために空にするか、または1つ以上のパラメータ設定を含むことができます。 それらは長さが一致する必要があります。 処理はkeywords配列内の最初のNULLエントリで停止します。 また、非NULL keywordsエントリに関連付けられたvaluesエントリがNULLまたは空文字列である場合、そのエントリは無視され、処理は配列エントリの次のペアで続行されます。

When <literal>expand_dbname</literal> is non-zero, the value for the first <parameter>dbname</parameter> key word is checked to see if it is a <firstterm>connection string</firstterm>. If so, it is <quote>expanded</quote> into the individual connection parameters extracted from the string. The value is considered to be a connection string, rather than just a database name, if it contains an equal sign (<literal>=</literal>) or it begins with a URI scheme designator. (More details on connection string formats appear in <xref linkend="libpq-connstring"/>.) Only the first occurrence of <parameter>dbname</parameter> is treated in this way; any subsequent <parameter>dbname</parameter> parameter is processed as a plain database name. expand_dbnameが0以外の場合、最初のdbnameキーワードの値が接続文字列かどうかチェックされます。 そうであれば、文字列から抽出された個々の接続パラメータに拡張されます。 等号(=)が含まれている場合や、URIスキーム指定子で始まっている場合、値は単なるデータベース名ではなく接続文字列とみなされます。 (接続文字列フォーマットの詳細は34.1.1を参照してください。) dbnameの最初の出現のみがこの方法で処理されます。 後続のdbnameパラメータはプレーンなデータベース名として処理されます。

In general the parameter arrays are processed from start to end. If any key word is repeated, the last value (that is not <symbol>NULL</symbol> or empty) is used. This rule applies in particular when a key word found in a connection string conflicts with one appearing in the <literal>keywords</literal> array. Thus, the programmer may determine whether array entries can override or be overridden by values taken from a connection string. Array entries appearing before an expanded <parameter>dbname</parameter> entry can be overridden by fields of the connection string, and in turn those fields are overridden by array entries appearing after <parameter>dbname</parameter> (but, again, only if those entries supply non-empty values). 一般的に、パラメータ配列は開始から終了まで処理されます。 キーワードが繰り返された場合、最後の値(NULLまたは空ではない)が使用されます。 この規則は特に、接続文字列内で見つかったキーワードがkeywords配列内で出現するキーワードと競合する場合に適用されます。 したがって、プログラマは、配列エントリが上書きするか、あるいは接続文字列から取得した値によって上書きされるかを判断できます。 拡張されたdbnameエントリの前に現れる配列エントリは、接続文字列のフィールドによって上書きされ、次にdbnameの後に現れる配列エントリによって上書きされます(ただし、これらのエントリが空でない値を提供する場合に限ります)。

After processing all the array entries and any expanded connection string, any connection parameters that remain unset are filled with default values. If an unset parameter's corresponding environment variable (see <xref linkend="libpq-envars"/>) is set, its value is used. If the environment variable is not set either, then the parameter's built-in default value is used. すべての配列エントリと拡張された接続文字列を処理した後、未設定のままの接続パラメータはデフォルト値で埋められます。 未設定パラメータに対応する環境変数(34.15参照)が設定されている場合は、その値が使用されます。 環境変数も設定されていない場合は、パラメータに組み込まれているデフォルト値が使用されます。

PQconnectdb #

Makes a new connection to the database server. 新たにデータベースサーバへの接続を作成します。

PGconn *PQconnectdb(const char *conninfo);

This function opens a new database connection using the parameters taken from the string <literal>conninfo</literal>. この関数はconninfo文字列から取得されるパラメータを使用して、新しいデータベース接続を開きます。

The passed string can be empty to use all default parameters, or it can contain one or more parameter settings separated by whitespace, or it can contain a <acronym>URI</acronym>. See <xref linkend="libpq-connstring"/> for details. 空の文字列を渡してすべてデフォルトパラメータを使用することができます。 また空白文字で区切ることで1つ以上のパラメータ設定を持たせることもできます。 さらにURIを含めることができます。 詳細については34.1.1を参照してください。

PQsetdbLogin #

Makes a new connection to the database server. 新たにデータベースサーバへの接続を作成します。

PGconn *PQsetdbLogin(const char *pghost,
                     const char *pgport,
                     const char *pgoptions,
                     const char *pgtty,
                     const char *dbName,
                     const char *login,
                     const char *pwd);

This is the predecessor of <xref linkend="libpq-PQconnectdb"/> with a fixed set of parameters. It has the same functionality except that the missing parameters will always take on default values. Write <symbol>NULL</symbol> or an empty string for any one of the fixed parameters that is to be defaulted. これはパラメータ群を固定したPQconnectdbの前身です。 設定できないパラメータが常にデフォルト値になる点を除き、同一の機能を持ちます。 固定のパラメータに対してNULLもしくは空文字列とすると、それはデフォルトを使用することになります。

If the <parameter>dbName</parameter> contains an <symbol>=</symbol> sign or has a valid connection <acronym>URI</acronym> prefix, it is taken as a <parameter>conninfo</parameter> string in exactly the same way as if it had been passed to <xref linkend="libpq-PQconnectdb"/>, and the remaining parameters are then applied as specified for <xref linkend="libpq-PQconnectdbParams"/>. dbName内に=記号が含まれる場合、または有効な接続URI接頭辞を持つ場合、PQconnectdbに渡された場合とまったく同じ扱いでconninfo文字列として扱われます。 その後残りのパラメータがPQconnectdbParamsの指定のように適用されます。

<literal>pgtty</literal> is no longer used and any value passed will be ignored. pgttyは使用されなくなり、渡された値は無視されます。

PQsetdb #

Makes a new connection to the database server. 新たにデータベースサーバへの接続を作成します。

PGconn *PQsetdb(char *pghost,
                char *pgport,
                char *pgoptions,
                char *pgtty,
                char *dbName);

This is a macro that calls <xref linkend="libpq-PQsetdbLogin"/> with null pointers for the <parameter>login</parameter> and <parameter>pwd</parameter> parameters. It is provided for backward compatibility with very old programs. これは、loginpwdにNULLポインタを設定するPQsetdbLoginを呼び出すマクロです。 非常に古いプログラムへの後方互換性のために提供されています。

PQconnectStartParams
PQconnectStart
PQconnectPoll #

Make a connection to the database server in a nonblocking manner. ブロックしない方法で、データベースサーバへの接続を作成します。

PGconn *PQconnectStartParams(const char * const *keywords,
                             const char * const *values,
                             int expand_dbname);

PGconn *PQconnectStart(const char *conninfo);

PostgresPollingStatusType PQconnectPoll(PGconn *conn);

These three functions are used to open a connection to a database server such that your application's thread of execution is not blocked on remote I/O whilst doing so. The point of this approach is that the waits for I/O to complete can occur in the application's main loop, rather than down inside <xref linkend="libpq-PQconnectdbParams"/> or <xref linkend="libpq-PQconnectdb"/>, and so the application can manage this operation in parallel with other activities. これら3つの関数は、リモートI/Oの実行時にアプリケーションスレッドの実行がブロックされないようなデータベースサーバへの接続を作成するために使われます。 この手法の利点は、I/Oの終了待ちがPQconnectdbParamsまたはPQconnectdb内部ではなく、アプリケーションプログラムのメインループでできることにあります。 これによって、アプリケーションは他の処理と並行してこの処理を管理することができます。

With <xref linkend="libpq-PQconnectStartParams"/>, the database connection is made using the parameters taken from the <literal>keywords</literal> and <literal>values</literal> arrays, and controlled by <literal>expand_dbname</literal>, as described above for <xref linkend="libpq-PQconnectdbParams"/>. PQconnectStartParamsでは、上でPQconnectdbParamsで説明したように、データベース接続はkeywordsおよびvalues配列から取得され、expand_dbnameによって制御されたパラメータを使用して確立します。

With <function>PQconnectStart</function>, the database connection is made using the parameters taken from the string <literal>conninfo</literal> as described above for <xref linkend="libpq-PQconnectdb"/>. PQconnectStartでは、上でPQconnectdbで説明したように、conninfo文字列から取得されたパラメータを使用してデータベース接続を確立します。

Neither <xref linkend="libpq-PQconnectStartParams"/> nor <function>PQconnectStart</function> nor <function>PQconnectPoll</function> will block, so long as a number of restrictions are met: PQconnectStartParamsPQconnectStartPQconnectPollのどちらも以下の制限に適合する場合ブロックしません。

  • The <literal>hostaddr</literal> parameter must be used appropriately to prevent DNS queries from being made. See the documentation of this parameter in <xref linkend="libpq-paramkeywords"/> for details. hostaddrパラメータは、DNS問い合わせが発生するのを防ぐように適切に使用されなければいけません。 詳細については34.1.2内のパラメータ説明を参照してください。

  • If you call <xref linkend="libpq-PQtrace"/>, ensure that the stream object into which you trace will not block. PQtraceを呼び出す場合は、トレースに使用するストリームオブジェクトがブロックされないことが保証されていなくてはなりません。

  • You must ensure that the socket is in the appropriate state before calling <function>PQconnectPoll</function>, as described below. プログラマ自身が、後に示すように、PQconnectPollを呼び出す前にソケットが適切な状態にあることを保証しなくてはいけません。

To begin a nonblocking connection request, call <function>PQconnectStart</function> or <xref linkend="libpq-PQconnectStartParams"/>. If the result is null, then <application>libpq</application> has been unable to allocate a new <structname>PGconn</structname> structure. Otherwise, a valid <structname>PGconn</structname> pointer is returned (though not yet representing a valid connection to the database). Next call <literal>PQstatus(conn)</literal>. If the result is <symbol>CONNECTION_BAD</symbol>, the connection attempt has already failed, typically because of invalid connection parameters. 非ブロック接続要求を始めるにはまず、PQconnectStartPQconnectStartParamsを呼び出します。 その結果がNULLの場合、libpqは新たなPGconn構造体を割り当てられませんでした。 そうでない場合は、適切なPGconnへのポインタが返されます (ただし、未だデータベースへの有効な接続を示しているわけではありません)。 次にPQstatus(conn)を呼び出します。 もし、結果がCONNECTION_BADであった場合、接続の試みは失敗しています。典型的には無効な接続パラメータに因ります。

If <function>PQconnectStart</function> or <xref linkend="libpq-PQconnectStartParams"/> succeeds, the next stage is to poll <application>libpq</application> so that it can proceed with the connection sequence. Use <function>PQsocket(conn)</function> to obtain the descriptor of the socket underlying the database connection. (Caution: do not assume that the socket remains the same across <function>PQconnectPoll</function> calls.) Loop thus: If <function>PQconnectPoll(conn)</function> last returned <symbol>PGRES_POLLING_READING</symbol>, wait until the socket is ready to read (as indicated by <function>select()</function>, <function>poll()</function>, or similar system function). Then call <function>PQconnectPoll(conn)</function> again. Conversely, if <function>PQconnectPoll(conn)</function> last returned <symbol>PGRES_POLLING_WRITING</symbol>, wait until the socket is ready to write, then call <function>PQconnectPoll(conn)</function> again. On the first iteration, i.e., if you have yet to call <function>PQconnectPoll</function>, behave as if it last returned <symbol>PGRES_POLLING_WRITING</symbol>. Continue this loop until <function>PQconnectPoll(conn)</function> returns <symbol>PGRES_POLLING_FAILED</symbol>, indicating the connection procedure has failed, or <symbol>PGRES_POLLING_OK</symbol>, indicating the connection has been successfully made. PQconnectStartあるいはPQconnectStartParamsが成功したら、次は接続シーケンスを進めるために、libpqをポーリングします。 データベース接続の背後にあるソケットの記述子を取り出すには、PQsocket(conn)を使用します。 (注意:複数のPQconnectPoll呼び出しでソケットが同じままであると思わないでください。) 以下の繰り返しです。 直前のPQconnectPoll(conn)PGRES_POLLING_READINGの場合、(select()poll()などのシステム関数で示されて)ソケットの読み込み準備が整うまで待機します。 そして、再度PQconnectPoll(conn)を呼び出します。 反対に直前のPQconnectPoll(conn)PGRES_POLLING_WRITINGの場合、ソケットの書き込み準備が整うまで待機し、その後、PQconnectPoll(conn)を再度呼び出します。 繰り返しの最初、すなわち、未だPQconnectPollを呼び出していない場合、最後にPGRES_POLLING_WRITINGを返したかのように振舞います。 この繰り返しをPQconnectPoll(conn)が、接続手続きの失敗を示すPGRES_POLLING_FAILED、もしくは、接続確立に成功したことを示すPGRES_POLLING_OKを返すまで継続します。

At any time during connection, the status of the connection can be checked by calling <xref linkend="libpq-PQstatus"/>. If this call returns <symbol>CONNECTION_BAD</symbol>, then the connection procedure has failed; if the call returns <function>CONNECTION_OK</function>, then the connection is ready. Both of these states are equally detectable from the return value of <function>PQconnectPoll</function>, described above. Other states might also occur during (and only during) an asynchronous connection procedure. These indicate the current stage of the connection procedure and might be useful to provide feedback to the user for example. These statuses are: 接続している間は、いつでもPQstatusを呼び出すことで、接続の状態を検査することができます。 この関数呼び出しがCONNECTION_BADを返す場合、接続手続きは失敗しており、CONNECTION_OKを返す場合、接続が確立しています。 上述のように、このいずれの状態も、PQconnectPollの戻り値から同様に検出できます。 これ以外の状態は、非同期の接続手続きの間(のみに)現れることがあります。 これらは、接続手続きの現在の段階を示すものであり、例えばユーザへのフィードバックを提供することに使用できます。 以下の状態があります。

CONNECTION_STARTED #

Waiting for connection to be made. 接続の確立待ち状態です。

CONNECTION_MADE #

Connection OK; waiting to send. 接続はOKです。送信待ち状態です。

CONNECTION_AWAITING_RESPONSE #

Waiting for a response from the server. サーバからの応答待ち状態です。

CONNECTION_AUTH_OK #

Received authentication; waiting for backend start-up to finish. 認証済みです。バックエンドの起動待ち状態です。

CONNECTION_SSL_STARTUP #

Negotiating SSL encryption. SSL暗号化の調停状態です。

CONNECTION_SETENV #

Negotiating environment-driven parameter settings. 環境が提供するパラメータ設定の調停状態です。

CONNECTION_CHECK_WRITABLE #

Checking if connection is able to handle write transactions. 接続が書き込みトランザクションを扱えるかどうかを調べています。

CONNECTION_CONSUME #

Consuming any remaining response messages on connection. 接続の残りの応答メッセージを消費しています。

Note that, although these constants will remain (in order to maintain compatibility), an application should never rely upon these occurring in a particular order, or at all, or on the status always being one of these documented values. An application might do something like this: これらの定数は(互換性を保つため)なくなることはありませんが、アプリケーションは、これらが特定の順で出現したり、本書に書いてある値のどれかに必ずステータス値が該当するということを決して当てにしてはいけません。 アプリケーションは、以下に示すようにするべきです。

switch(PQstatus(conn))
{
        case CONNECTION_STARTED:
            feedback = "Connecting...";
            break;

        case CONNECTION_MADE:
            feedback = "Connected to server...";
            break;
.
.
.
        default:
            feedback = "Connecting...";
}

The <literal>connect_timeout</literal> connection parameter is ignored when using <function>PQconnectPoll</function>; it is the application's responsibility to decide whether an excessive amount of time has elapsed. Otherwise, <function>PQconnectStart</function> followed by a <function>PQconnectPoll</function> loop is equivalent to <xref linkend="libpq-PQconnectdb"/>. PQconnectPollを使用する場合、connect_timeout接続パラメータは無視されます。 経過時間が長過ぎるかどうかの判定はアプリケーションの責任で行ないます。 さもないと、PQconnectStartの後のPQconnectPollの繰り返しがPQconnectdbと同じになります。

Note that when <function>PQconnectStart</function> or <xref linkend="libpq-PQconnectStartParams"/> returns a non-null pointer, you must call <xref linkend="libpq-PQfinish"/> when you are finished with it, in order to dispose of the structure and any associated memory blocks. This must be done even if the connection attempt fails or is abandoned. PQconnectStartPQconnectStartParamsが非NULLポインタを返した場合、処理を終了する際には、構造体や関連するメモリブロックを始末するために、PQfinishを呼び出さなくてはならないことに注意してください。 この処理は、接続試行が失敗した場合やその試行を中断する場合にも、必ず実行されなければいけません。

PQconndefaults #

Returns the default connection options. デフォルトの接続オプションを返します。

PQconninfoOption *PQconndefaults(void);

typedef struct
{

    char   *keyword;   /* The keyword of the option */
    char   *envvar;    /* Fallback environment variable name */
    char   *compiled;  /* Fallback compiled in default value */
    char   *val;       /* Option's current value, or NULL */
    char   *label;     /* Label for field in connect dialog */
    char   *dispchar;  /* Indicates how to display this field
                          in a connect dialog. Values are:
                          ""        Display entered value as is
                          "*"       Password field - hide value
                          "D"       Debug option - don't show by default */
    int     dispsize;  /* Field size in characters for dialog */

    char   *keyword;   /* このオプションのキーワード */
    char   *envvar;    /* 代替となる環境変数の名前 */
    char   *compiled;  /* 代替となるコンパイル時に組み込まれたデフォルト値 */
    char   *val;       /* オプションの現在値、もしくは、NULL */
    char   *label;     /* 接続ダイアログ内の当該フィールドのラベル */
    char   *dispchar;  /* 接続ダイアログ内の当該フィールドをどのように表示するかの指示
                          値:
                          ""        入力された値をそのまま表示
                          "*"       値を隠すパスワードフィールド用
                          "D"       デバッグオプション。デフォルトで何も表示しません */
    int     dispsize;  /* ダイアログ用のフィールドの大きさ(文字数単位) */
} PQconninfoOption;

Returns a connection options array. This can be used to determine all possible <xref linkend="libpq-PQconnectdb"/> options and their current default values. The return value points to an array of <structname>PQconninfoOption</structname> structures, which ends with an entry having a null <structfield>keyword</structfield> pointer. The null pointer is returned if memory could not be allocated. Note that the current default values (<structfield>val</structfield> fields) will depend on environment variables and other context. A missing or invalid service file will be silently ignored. Callers must treat the connection options data as read-only. 接続オプションの配列を返します。 これは、使用可能なPQconnectdb用オプションのすべてや、その時点でのデフォルト値を決定するために使用することができます。 戻り値は、PQconninfoOption構造体の配列へのポインタで、keywordポインタがヌルとなる項目が配列の末尾にきます。 メモリが確保できなかった場合にはヌルポインタを返します。 現在のデフォルト値(val フィールド)は、環境変数や他のコンテキストに依存します。 呼び出し側では、接続オプションの情報は、読み込み専用として取り扱わなければいけません。

After processing the options array, free it by passing it to <xref linkend="libpq-PQconninfoFree"/>. If this is not done, a small amount of memory is leaked for each call to <xref linkend="libpq-PQconndefaults"/>. オプションの配列を処理した後は、それをPQconninfoFreeに渡して解放します。 この処理をしないと、PQconndefaultsが呼び出されるたびに少しずつメモリリークが発生します。

PQconninfo #

Returns the connection options used by a live connection. 所在する接続で使用される接続オプションを返します。

PQconninfoOption *PQconninfo(PGconn *conn);

Returns a connection options array. This can be used to determine all possible <xref linkend="libpq-PQconnectdb"/> options and the values that were used to connect to the server. The return value points to an array of <structname>PQconninfoOption</structname> structures, which ends with an entry having a null <structfield>keyword</structfield> pointer. All notes above for <xref linkend="libpq-PQconndefaults"/> also apply to the result of <xref linkend="libpq-PQconninfo"/>. 接続オプション配列を返します。これは全ての可能性のあるPQconnectdbオプションとサーバに接続するのに使用される値を確定するために使用することができます。 返り値はPQconninfoOption構造体の配列を指し示します。それはnull keyword ポインタを持つ項目で終結します。PQconndefaultsに対する上記の全ての注釈はまたPQconninfoの結果に適用されます。

PQconninfoParse #

Returns parsed connection options from the provided connection string. 提供された接続文字列から構文解析された接続オプションを返します。

PQconninfoOption *PQconninfoParse(const char *conninfo, char **errmsg);

Parses a connection string and returns the resulting options as an array; or returns <symbol>NULL</symbol> if there is a problem with the connection string. This function can be used to extract the <xref linkend="libpq-PQconnectdb"/> options in the provided connection string. The return value points to an array of <structname>PQconninfoOption</structname> structures, which ends with an entry having a null <structfield>keyword</structfield> pointer. 接続文字列の構文解析を行い、配列として結果オプションを返すか、または接続文字列に問題があった場合にNULLを返します。 この関数を提供された接続文字列の中のPQconnectdbオプションを取り出すために使用することができます。 戻り値はPQconninfoOption構造体の配列を指し示し、それはヌルのkeywordポインタを持つ項目で終結します。

All legal options will be present in the result array, but the <literal>PQconninfoOption</literal> for any option not present in the connection string will have <literal>val</literal> set to <literal>NULL</literal>; default values are not inserted. 正規なオプションはすべて、結果配列内に現れます。 しかし接続文字列内に現れない、何らかのオプション用のPQconninfoOptionNULLに設定されたvalを持ちます。 デフォルトは挿入されません。

If <literal>errmsg</literal> is not <symbol>NULL</symbol>, then <literal>*errmsg</literal> is set to <symbol>NULL</symbol> on success, else to a <function>malloc</function>'d error string explaining the problem. (It is also possible for <literal>*errmsg</literal> to be set to <symbol>NULL</symbol> and the function to return <symbol>NULL</symbol>; this indicates an out-of-memory condition.) errmsgが非NULLであれば、成功した場合*errmsgNULLに設定され、そうでなければ、問題を説明したmallocされたエラー文字列になります。 (*errmsgNULLに設定され、かつ、この関数がNULLを返すこともあり得ます。 これはメモリ不足状態を意味します。)

After processing the options array, free it by passing it to <xref linkend="libpq-PQconninfoFree"/>. If this is not done, some memory is leaked for each call to <xref linkend="libpq-PQconninfoParse"/>. Conversely, if an error occurs and <literal>errmsg</literal> is not <symbol>NULL</symbol>, be sure to free the error string using <xref linkend="libpq-PQfreemem"/>. オプション配列を処理した後、それをPQconninfoFreeに渡して解放してください。 これが行われない場合、PQconninfoParseへのそれぞれの呼び出しに対してメモリーリークが起こります。 反対に、エラーが起こり、そしてerrmsgが非NULLであれば、PQfreememを使用してエラー文字列を必ず解放してください。

PQfinish #

Closes the connection to the server. Also frees memory used by the <structname>PGconn</structname> object. サーバとの接続を閉ざします。 また、PGconnオブジェクトが占めるメモリも解放します。

void PQfinish(PGconn *conn);

Note that even if the server connection attempt fails (as indicated by <xref linkend="libpq-PQstatus"/>), the application should call <xref linkend="libpq-PQfinish"/> to free the memory used by the <structname>PGconn</structname> object. The <structname>PGconn</structname> pointer must not be used again after <xref linkend="libpq-PQfinish"/> has been called. たとえサーバへの接続試行が失敗しても(PQstatusで調べます)、アプリケーションはPQfinishを呼び出しPGconnオブジェクトが占めるメモリを解放するべきです。 そしてPQfinishを呼び出したら、もうPGconnへのポインタを使ってはいけません。

PQreset #

Resets the communication channel to the server. サーバへの通信チャンネルをリセットします。

void PQreset(PGconn *conn);

This function will close the connection to the server and attempt to establish a new connection, using all the same parameters previously used. This might be useful for error recovery if a working connection is lost. この関数はサーバへの接続を閉じ、以前使用したパラメータをすべて使用して、同一のサーバへ新しく接続を確立します。 これは、作業中の接続が失われた場合のエラーの修復に役立つでしょう。

PQresetStart
PQresetPoll #

Reset the communication channel to the server, in a nonblocking manner. 非ブロッキング方式で、サーバへの接続チャンネルをリセットします。

int PQresetStart(PGconn *conn);

PostgresPollingStatusType PQresetPoll(PGconn *conn);

These functions will close the connection to the server and attempt to establish a new connection, using all the same parameters previously used. This can be useful for error recovery if a working connection is lost. They differ from <xref linkend="libpq-PQreset"/> (above) in that they act in a nonblocking manner. These functions suffer from the same restrictions as <xref linkend="libpq-PQconnectStartParams"/>, <function>PQconnectStart</function> and <function>PQconnectPoll</function>. これらの関数はサーバへの接続を閉じ、それから再度、以前使用したパラメータをすべて使用して、同じサーバと新たな接続を確立しようとします。 これらは作業中の接続が失われた場合のエラー修復に役立つでしょう。 PQreset(前述)との違いは、この2つの関数が非ブロック方式で動作することです。 また、これらの関数はPQconnectStartParamsPQconnectStartおよびPQconnectPollと同じ制限を受けます。

To initiate a connection reset, call <xref linkend="libpq-PQresetStart"/>. If it returns 0, the reset has failed. If it returns 1, poll the reset using <function>PQresetPoll</function> in exactly the same way as you would create the connection using <function>PQconnectPoll</function>. 接続のリセットを始めるためにはPQresetStartを呼び出します。 この関数がゼロを返す場合、リセットに失敗しています。 戻り値が1ならば、PQconnectPollを使って接続を確立した時とまったく同じに、PQresetPollを使用してリセットのポーリングを行います。

PQpingParams #

<xref linkend="libpq-PQpingParams"/> reports the status of the server. It accepts connection parameters identical to those of <xref linkend="libpq-PQconnectdbParams"/>, described above. It is not necessary to supply correct user name, password, or database name values to obtain the server status; however, if incorrect values are provided, the server will log a failed connection attempt. PQpingParamsはサーバの状態を報告します。 この関数は上述のPQconnectdbParamsと同じ接続パラメータを受け付けます。 サーバの状態を得るために正しいユーザ名、パスワード、データベース名を提供する必要はありません。 しかし、不適切な値が供給されると、サーバは不成功に終わった接続の試みをログに残します。

PGPing PQpingParams(const char * const *keywords,
                    const char * const *values,
                    int expand_dbname);

The function returns one of the following values: この関数は以下の値のいずれかを返します。

PQPING_OK #

The server is running and appears to be accepting connections. サーバは稼働中で、接続を受け付けているようです。

PQPING_REJECT #

The server is running but is in a state that disallows connections (startup, shutdown, or crash recovery). サーバは稼働中ですが、接続を許可しない状態(起動処理中、停止処理中、クラッシュリカバリ中)です。

PQPING_NO_RESPONSE #

The server could not be contacted. This might indicate that the server is not running, or that there is something wrong with the given connection parameters (for example, wrong port number), or that there is a network connectivity problem (for example, a firewall blocking the connection request). サーバと通信できません。 これは、サーバが稼働中ではない、指定した接続パラメータの何か(例えばポート番号の間違い)が間違っている、ネットワーク接続性の問題(例えば接続要求をブロックするファイアウォール)があることを示しているかもしれません。

PQPING_NO_ATTEMPT #

No attempt was made to contact the server, because the supplied parameters were obviously incorrect or there was some client-side problem (for example, out of memory). 指定されたパラメータが明らかに間違っている、または、(メモリ不足など)クライアント側の問題があったため、サーバとの通信を試行しませんでした。

PQping #

<xref linkend="libpq-PQping"/> reports the status of the server. It accepts connection parameters identical to those of <xref linkend="libpq-PQconnectdb"/>, described above. It is not necessary to supply correct user name, password, or database name values to obtain the server status; however, if incorrect values are provided, the server will log a failed connection attempt. PQpingはサーバの状態を報告します。 この関数は上述のPQconnectdbと同じ接続パラメータを受け付けます。 サーバの状態を得るために正しいユーザ名、パスワード、データベース名を提供する必要はありません。 しかし、不適切な値が供給されると、サーバは不成功に終わった接続の試みをログに残します。

PGPing PQping(const char *conninfo);

The return values are the same as for <xref linkend="libpq-PQpingParams"/>. 戻り値はPQpingParamsと同じです。

PQsetSSLKeyPassHook_OpenSSL #

<function>PQsetSSLKeyPassHook_OpenSSL</function> lets an application override <application>libpq</application>'s <link linkend="libpq-ssl-clientcert">default handling of encrypted client certificate key files</link> using <xref linkend="libpq-connect-sslpassword"/> or interactive prompting. PQsetSSLKeyPassHook_OpenSSLはアプリケーションにsslpasswordや対話的なプロンプトを使ってlibpq暗号化されたクライアント証明書キーファイルのデフォルト処理を置き換えさせます。

void PQsetSSLKeyPassHook_OpenSSL(PQsslKeyPassHook_OpenSSL_type hook);

The application passes a pointer to a callback function with signature: アプリケーションは以下のシグネチャを持つコールバック関数のポインタを渡します。

int callback_fn(char *buf, int size, PGconn *conn);

which <application>libpq</application> will then call <emphasis>instead of</emphasis> its default <function>PQdefaultSSLKeyPassHook_OpenSSL</function> handler. The callback should determine the password for the key and copy it to result-buffer <parameter>buf</parameter> of size <parameter>size</parameter>. The string in <parameter>buf</parameter> must be null-terminated. The callback must return the length of the password stored in <parameter>buf</parameter> excluding the null terminator. On failure, the callback should set <literal>buf[0] = '\0'</literal> and return 0. See <function>PQdefaultSSLKeyPassHook_OpenSSL</function> in <application>libpq</application>'s source code for an example. libpqはデフォルトのPQdefaultSSLKeyPassHook_OpenSSLハンドラの代わりに、これを呼び出します。 コールバックはキーに対するパスワードを決定して、それをsizeの大きさを持つ結果バッファbufにコピーすべきです。 buf内の文字列はNULL終端でなければなりません。 コールバックはbufに格納されたパスワードのヌル終端子を除いた長さを返さなければなりません。 失敗した場合、コールバックはbuf[0] = '\0'をセットし、0を返すべきです。 例として、libpqのソースコードのPQdefaultSSLKeyPassHook_OpenSSLを参照してください。

If the user specified an explicit key location, its path will be in <literal>conn->sslkey</literal> when the callback is invoked. This will be empty if the default key path is being used. For keys that are engine specifiers, it is up to engine implementations whether they use the <productname>OpenSSL</productname> password callback or define their own handling. ユーザが明示的なキー位置を指定した場合、コールバックが実行されたときにそのパスがconn->sslkeyに含まれます。 デフォルトのキーパスが使われている場合、これは空になります。 エンジン指定子であるキーに対して、OpenSSLパスワードコールバックを使うか固有の処理を定義するかは、エンジン実装によります。

The app callback may choose to delegate unhandled cases to <function>PQdefaultSSLKeyPassHook_OpenSSL</function>, or call it first and try something else if it returns 0, or completely override it. アプリケーションのコールバックが対応していない場合についてPQdefaultSSLKeyPassHook_OpenSSLに委託したり、最初に呼び出して0が返った場合に何らか他のことを試みたり、あるいは完全に上書きしたりすることにしても良いです。

The callback <emphasis>must not</emphasis> escape normal flow control with exceptions, <function>longjmp(...)</function>, etc. It must return normally. コールバックは例外、longjmp(...)などで通常のフロー制御から脱出してはいけません。 正常にリターンしなければなりません。

PQgetSSLKeyPassHook_OpenSSL #

<function>PQgetSSLKeyPassHook_OpenSSL</function> returns the current client certificate key password hook, or <literal>NULL</literal> if none has been set. PQgetSSLKeyPassHook_OpenSSLは現在のクライアント証明書のキーパスワードのフックを、あるいは、設定されていない場合にNULLを返します。

PQsslKeyPassHook_OpenSSL_type PQgetSSLKeyPassHook_OpenSSL(void);

34.1.1. 接続文字列 #

<title>Connection Strings</title>

Several <application>libpq</application> functions parse a user-specified string to obtain connection parameters. There are two accepted formats for these strings: plain keyword/value strings and URIs. URIs generally follow <ulink url="https://tools.ietf.org/html/rfc3986">RFC 3986</ulink>, except that multi-host connection strings are allowed as further described below. 複数のlibpq関数は、接続パラメータを得るためにユーザが指定した文字列の解析を行います。 この文字列として、単純なキーワード/値文字列とURIという2種類の書式が受け付けられます。 URIは通常RFC3986に従いますが、以下で詳細を説明する複数ホスト接続文字列が使用できるところが例外です。

34.1.1.1. キーワード/値形式の接続文字列 #

<title>Keyword/Value Connection Strings</title>

In the keyword/value format, each parameter setting is in the form <replaceable>keyword</replaceable> <literal>=</literal> <replaceable>value</replaceable>, with space(s) between settings. Spaces around a setting's equal sign are optional. To write an empty value, or a value containing spaces, surround it with single quotes, for example <literal>keyword = 'a value'</literal>. Single quotes and backslashes within a value must be escaped with a backslash, i.e., <literal>\'</literal> and <literal>\\</literal>. キーワード/値書式では、各パラメータ設定は、各設定の間に空白文字があり、keyword = valueという形式です。 等号記号の前後の空白文字は省略可能です。 空の値を書く、または空白文字を含む値を書くためには、keyword = 'a value'のように単一引用符で値を括ります。 値内部の単一引用符とバックスラッシュはバックスラッシュでエスケープしなければなりません。 つまり\'\\です。

Example: 以下に例を示します。

host=localhost port=5432 dbname=mydb connect_timeout=10

The recognized parameter key words are listed in <xref linkend="libpq-paramkeywords"/>. 有効なパラメータキーワードを34.1.2に示します。

34.1.1.2. 接続URI #

<title>Connection URIs</title>

The general form for a connection <acronym>URI</acronym> is: 接続URIの一般的な形式を以下に示します。

postgresql://[userspec@][hostspec][/dbname][?paramspec]

where userspec is:

user[:password]

and hostspec is:

[host][:port][,...]

and paramspec is:

name=value[&...]

The <acronym>URI</acronym> scheme designator can be either <literal>postgresql://</literal> or <literal>postgres://</literal>. Each of the remaining <acronym>URI</acronym> parts is optional. The following examples illustrate valid <acronym>URI</acronym> syntax: URIスキーム指示子はpostgresql://またはpostgres://のいずれかを取ることができます。 個々のURIの残りの部品は省略可能です。 以下の例で有効なURI構文の使用例を示します。

postgresql://
postgresql://localhost
postgresql://localhost:5433
postgresql://localhost/mydb
postgresql://user@localhost
postgresql://user:secret@localhost
postgresql://other@localhost/otherdb?connect_timeout=10&application_name=myapp
postgresql://host1:123,host2:456/somedb?target_session_attrs=any&application_name=myapp

Values that would normally appear in the hierarchical part of the <acronym>URI</acronym> can alternatively be given as named parameters. For example: URIの階層部分に通常現れる値は、代わりに名前付きパラメータとして与えられます。例:

postgresql:///mydb?host=localhost&port=5433

All named parameters must match key words listed in <xref linkend="libpq-paramkeywords"/>, except that for compatibility with JDBC connection <acronym>URI</acronym>s, instances of <literal>ssl=true</literal> are translated into <literal>sslmode=require</literal>. JDBC接続URIとの互換性のために、ssl=trueのインスタンスがsslmode=requireに変換される点を除き、すべての名前付きパラメータは34.1.2に列挙されたキーワードと一致しなければなりません。

The connection <acronym>URI</acronym> needs to be encoded with <ulink url="https://tools.ietf.org/html/rfc3986#section-2.1">percent-encoding</ulink> if it includes symbols with special meaning in any of its parts. Here is an example where the equal sign (<literal>=</literal>) is replaced with <literal>%3D</literal> and the space character with <literal>%20</literal>: 接続URIは、その中のどこかの部分に特別な意味を持つシンボルを含む場合、パーセントエンコーディングでエンコードされている必要があります。 以下は等号(=)が%3D、空白が%20で置き換えられた例です。

postgresql://user@localhost:5433/mydb?options=-c%20synchronous_commit%3Doff

The host part may be either a host name or an IP address. To specify an IPv6 address, enclose it in square brackets: ホスト部分は、ホスト名またはIPアドレスのいずれかです。 IPv6アドレスを指定するには、角括弧で囲みます:

postgresql://[2001:db8::1234]/database

The host part is interpreted as described for the parameter <xref linkend="libpq-connect-host"/>. In particular, a Unix-domain socket connection is chosen if the host part is either empty or looks like an absolute path name, otherwise a TCP/IP connection is initiated. Note, however, that the slash is a reserved character in the hierarchical part of the URI. So, to specify a non-standard Unix-domain socket directory, either omit the host part of the URI and specify the host as a named parameter, or percent-encode the path in the host part of the URI: ホスト部分はパラメータhostで説明したように解釈されます。 具体的には、ホスト部が空または絶対パス名のように見える場合、Unixドメインソケット接続が選択され、さもなければTCP/IP接続で初期化されます。 しかしURIの階層部ではスラッシュが予約された文字であることに注意してください。 このため、標準以外のUnixドメインソケットディレクトリを指定するためには、URIからホスト指定を省き、名前付きパラメータとしてホストを指定するか、URIのホスト要素内のパスをパーセントエンコードするかどちらかを行ってください。

postgresql:///dbname?host=/var/lib/postgresql
postgresql://%2Fvar%2Flib%2Fpostgresql/dbname

It is possible to specify multiple host components, each with an optional port component, in a single URI. A URI of the form <literal>postgresql://host1:port1,host2:port2,host3:port3/</literal> is equivalent to a connection string of the form <literal>host=host1,host2,host3 port=port1,port2,port3</literal>. As further described below, each host will be tried in turn until a connection is successfully established. 単一のURIの中に、オプションのポート要素を伴う複数のホスト要素を指定することができます。 postgresql://host1:port1,host2:port2,host3:port3/という形式のURIは、host=host1,host2,host3 port=port1,port2,port3という形式の接続文字列と同じです。 更に以下に示すように、接続の確立に成功するまで、各々のホストが順番に試されます。

34.1.1.3. 複数ホストの指定 #

<title>Specifying Multiple Hosts</title>

It is possible to specify multiple hosts to connect to, so that they are tried in the given order. In the Keyword/Value format, the <literal>host</literal>, <literal>hostaddr</literal>, and <literal>port</literal> options accept comma-separated lists of values. The same number of elements must be given in each option that is specified, such that e.g., the first <literal>hostaddr</literal> corresponds to the first host name, the second <literal>hostaddr</literal> corresponds to the second host name, and so forth. As an exception, if only one <literal>port</literal> is specified, it applies to all the hosts. 接続先に複数のホストを指定することができ、指定された順に試されます。 キーワード/値形式では、hosthostaddrportオプションは、カンマで区切った値のリストを受け付けます。 指定された各々のオプションでは、同じ数の要素を与えなければなりません。 たとえば、最初のhostaddrは最初のホスト名に関連付けられ、二番目のhostaddrは二番目のホスト名に関連付けられる、という具合です。 例外として、一つのportだけが指定された場合には、すべてのホストにそれが適用されます。

In the connection URI format, you can list multiple <literal>host:port</literal> pairs separated by commas in the <literal>host</literal> component of the URI. 接続URI形式では、host要素中にカンマで区切って複数のhost:portペアを指定できます。

In either format, a single host name can translate to multiple network addresses. A common example of this is a host that has both an IPv4 and an IPv6 address. いずれの形式でも、単一ホスト名は複数のネットワークアドレスに変換されることがあります。 これの一般的な例はIPv4とIPv6のアドレスを両方持つホストです。

When multiple hosts are specified, or when a single host name is translated to multiple addresses, all the hosts and addresses will be tried in order, until one succeeds. If none of the hosts can be reached, the connection fails. If a connection is established successfully, but authentication fails, the remaining hosts in the list are not tried. 複数のホスト名が指定された場合、あるいは単一のホスト名が複数のアドレスに変換された場合、そのうちの一つが成功するまで、すべてのホストとアドレスがその順に試されます。 どのホストも到達可能でなければ、接続は失敗します。 接続の確立に成功しても、認証に失敗すると、リスト中の残りのホストは試されません。

If a password file is used, you can have different passwords for different hosts. All the other connection options are the same for every host in the list; it is not possible to e.g., specify different usernames for different hosts. パスワードファイルが使用される場合は、異なるホストに対して異なるパスワードを使用できます。 他の接続オプションは、リスト中のすべてのホストで同じです。 たとえば、異なるユーザ名を異なるホストに指定することはできません。

34.1.2. パラメータキーワード #

<title>Parameter Key Words</title>

The currently recognized parameter key words are: 現時点で有効なパラメータのキーワードは以下に示す通りです。

host #

Name of host to connect to.<indexterm><primary>host name</primary></indexterm> If a host name looks like an absolute path name, it specifies Unix-domain communication rather than TCP/IP communication; the value is the name of the directory in which the socket file is stored. (On Unix, an absolute path name begins with a slash. On Windows, paths starting with drive letters are also recognized.) If the host name starts with <literal>@</literal>, it is taken as a Unix-domain socket in the abstract namespace (currently supported on Linux and Windows). The default behavior when <literal>host</literal> is not specified, or is empty, is to connect to a Unix-domain socket<indexterm><primary>Unix domain socket</primary></indexterm> in <filename>/tmp</filename> (or whatever socket directory was specified when <productname>PostgreSQL</productname> was built). On Windows, the default is to connect to <literal>localhost</literal>. 《マッチ度[]》接続するホスト名を指定します。 ホスト名が絶対パス名のように見えるなら、それはTCP/IPによる通信ではなく、Unixドメインの通信を示します。 その場合、この値はソケットファイルを格納するディレクトリの名前になります。 (Unixでは絶対パス名はスラッシュから始まります。Windowsではドライブ文字から始まるパスも認められます。) ホスト名が@から始まっていると、抽象名前空間(今のところLinuxとWindowsでサポートされています)内のUnixドメインソケットとして扱われます。 hostが指定されなかったり、空の場合のデフォルトの振る舞いは、/tmp(または、PostgreSQLの構築時に指定したソケットディレクトリ)にあるUnixドメインのソケットに接続することです。 Unixドメインソケットを持たないマシンにおけるデフォルトは、localhostに接続することです。

A comma-separated list of host names is also accepted, in which case each host name in the list is tried in order; an empty item in the list selects the default behavior as explained above. See <xref linkend="libpq-multiple-hosts"/> for details. カンマで区切ったホスト名も受け付けます。 この場合、リスト中のホスト名が順に試されます。 リスト中の空の項目には、上で説明したデフォルトの挙動が適用されます。 詳細は34.1.1.3をご覧ください。

hostaddr #

Numeric IP address of host to connect to. This should be in the standard IPv4 address format, e.g., <literal>172.28.40.9</literal>. If your machine supports IPv6, you can also use those addresses. TCP/IP communication is always used when a nonempty string is specified for this parameter. If this parameter is not specified, the value of <literal>host</literal> will be looked up to find the corresponding IP address &mdash; or, if <literal>host</literal> specifies an IP address, that value will be used directly. 接続するホストのIPアドレスを指定します。 これは、172.28.40.9といった標準的なIPv4アドレス書式でなければなりません。 使用するマシンでIPv6をサポートする場合は、そのアドレスを使用することもできます。 このパラメータに空以外の文字列が指定されると、TCP/IP通信が常に使用されます。 パラメータが指定されない場合、対応するIPアドレスを探すためにhostの値が調べられます。あるいは、hostでIPアドレスを指定している場合、その値が直接使われます。

Using <literal>hostaddr</literal> allows the application to avoid a host name look-up, which might be important in applications with time constraints. However, a host name is required for GSSAPI or SSPI authentication methods, as well as for <literal>verify-full</literal> SSL certificate verification. The following rules are used: hostaddrを使用することで、アプリケーションがホスト名の検索を行なわずに済みます。 特に時間的制約があるアプリケーションでは重要になるでしょう。 しかし、GSSAPI、SSPI認証方式では、ホスト名が必要になります。 verify-fullSSL証明書検証を行う場合も同様です。 以下の規則が使用されます。

  • If <literal>host</literal> is specified without <literal>hostaddr</literal>, a host name lookup occurs. (When using <function>PQconnectPoll</function>, the lookup occurs when <function>PQconnectPoll</function> first considers this host name, and it may cause <function>PQconnectPoll</function> to block for a significant amount of time.) hostaddrを使わずにhostを指定した場合は、ホスト名の検索が発生します。 (PQconnectPollを使う場合、PQconnectPollが最初にホスト名を考慮するときに、PQconnectPollをかなり長い時間、ブロックさせてしまうかもしれません。)

  • If <literal>hostaddr</literal> is specified without <literal>host</literal>, the value for <literal>hostaddr</literal> gives the server network address. The connection attempt will fail if the authentication method requires a host name. hostを使わずにhostaddrを指定した場合、hostaddrの値はサーバのネットワークアドレスとなります。 認証方式がホスト名を必要する場合は接続試行が失敗します。

  • If both <literal>host</literal> and <literal>hostaddr</literal> are specified, the value for <literal>hostaddr</literal> gives the server network address. The value for <literal>host</literal> is ignored unless the authentication method requires it, in which case it will be used as the host name. hosthostaddrの両方を指定した場合、hostaddrがサーバのネットワークアドレスとなります。 hostの値は認証方式で必要とされない限り無視され、必要とされる場合にはホスト名として使用されます。

Note that authentication is likely to fail if <literal>host</literal> is not the name of the server at network address <literal>hostaddr</literal>. Also, when both <literal>host</literal> and <literal>hostaddr</literal> are specified, <literal>host</literal> is used to identify the connection in a password file (see <xref linkend="libpq-pgpass"/>). hosthostaddrネットワークアドレスに対応するマシンの名前と一致しない場合は、認証に失敗する可能性があるので注意してください。 また、hosthostaddrの両方が指定されると、hostがパスワードファイル(34.16を参照)での接続の識別に使用されます。

A comma-separated list of <literal>hostaddr</literal> values is also accepted, in which case each host in the list is tried in order. An empty item in the list causes the corresponding host name to be used, or the default host name if that is empty as well. See <xref linkend="libpq-multiple-hosts"/> for details. カンマ区切りのhostaddr値のリストも受け付けます。 この場合、リスト中のホストが順に試されます。 リスト中の空の項目には、対応するホスト名が使用されます。 そのホスト名も空の場合は、デフォルトのホスト名が使用されます。 詳細は34.1.1.3をご覧ください。

Without either a host name or host address, <application>libpq</application> will connect using a local Unix-domain socket; or on Windows, it will attempt to connect to <literal>localhost</literal>. 《マッチ度[61.616162]》ホスト名もホストのアドレスも用いない場合、libpqはローカルのUnixドメインソケットを使用して接続します。 ただし、WindowsとUnixドメインソケットを持たないマシンでは、localhostへの接続を試みます。 《機械翻訳》ホスト名またはホストアドレスのいずれかがない場合、libpqはローカルのUnixドメインソケットを使用して接続します。 または、Windowsでは、localhostに接続します。

port #

Port number to connect to at the server host, or socket file name extension for Unix-domain connections.<indexterm><primary>port</primary></indexterm> If multiple hosts were given in the <literal>host</literal> or <literal>hostaddr</literal> parameters, this parameter may specify a comma-separated list of ports of the same length as the host list, or it may specify a single port number to be used for all hosts. An empty string, or an empty item in a comma-separated list, specifies the default port number established when <productname>PostgreSQL</productname> was built. サーバホストでの接続用のポート番号、または、Unixドメイン接続の場合は、ソケットファイルの拡張子を指定します。 もし複数のホストがhostあるいはhostaddrパラメータで与えられると、このパラメータで同じ長さのポートのリストを与えることができます。 あるいは、一つのポート番号をすべてのホストに指定することもできます。 空文字、あるいはカンマ区切りリスト中の空の項目は、PostgreSQLが構築されたときに設定されたデフォルトポート番号を指定します。

dbname #

The database name. Defaults to be the same as the user name. In certain contexts, the value is checked for extended formats; see <xref linkend="libpq-connstring"/> for more details on those. データベース名を指定します。 デフォルトはユーザ名と同じです。 特定の文脈では、この値は拡張書式で検査されます。 詳細については34.1.1を参照してください。

user #

<productname>PostgreSQL</productname> user name to connect as. Defaults to be the same as the operating system name of the user running the application. データベースへ接続するPostgreSQLユーザ名を指定します。 デフォルトは、そのアプリケーションを実行しているユーザのオペレーティングシステム上の名前と同じです。

password #

Password to be used if the server demands password authentication. サーバがパスワードによる認証を必要とした場合に使用されるパスワードを指定します。

passfile #

Specifies the name of the file used to store passwords (see <xref linkend="libpq-pgpass"/>). Defaults to <filename>~/.pgpass</filename>, or <filename>%APPDATA%\postgresql\pgpass.conf</filename> on Microsoft Windows. (No error is reported if this file does not exist.) パスワードを格納するファイル名を指定します(34.16参照)。 デフォルトは~/.pgpassまたは、Microsoft Windowsでは%APPDATA%\postgresql\pgpass.confです。 (このファイルが存在しなくてもエラーは報告されません。)

require_auth #

Specifies the authentication method that the client requires from the server. If the server does not use the required method to authenticate the client, or if the authentication handshake is not fully completed by the server, the connection will fail. A comma-separated list of methods may also be provided, of which the server must use exactly one in order for the connection to succeed. By default, any authentication method is accepted, and the server is free to skip authentication altogether. 《機械翻訳》クライアントがサーバーから要求する認証方法を指定します。 サーバーがクライアントの認証に必要なメソッドを使用しない場合、またはサーバーが認証ハンドシェイクを完全に完了しない場合、接続は失敗します。 必要なメソッドのコンマ区切りリストも指定できます。 このリストでは、サーバーは接続を正常に完了するために、そのうちの1つを使用する必要があります。 デフォルトでは、任意の認証方法が受け入れられ、サーバーは認証を完全にスキップできます。

Methods may be negated with the addition of a <literal>!</literal> prefix, in which case the server must <emphasis>not</emphasis> attempt the listed method; any other method is accepted, and the server is free not to authenticate the client at all. If a comma-separated list is provided, the server may not attempt <emphasis>any</emphasis> of the listed negated methods. Negated and non-negated forms may not be combined in the same setting. 《機械翻訳》メソッドは、!接頭辞を付けて否定することができます。 その場合、サーバはリストされたメソッドを試みないことになります。 他のメソッドはすべて受け入れられます。 また、クライアントを全く認証しないこともできます。 コンマ区切りのリストが与えられた場合、サーバは、リストされた否定されたメソッドのいずれも試みてはならない。 否定された形式と否定されていない形式は、同じ設定では組み合わせることができません。

As a final special case, the <literal>none</literal> method requires the server not to use an authentication challenge. (It may also be negated, to require some form of authentication.) 《機械翻訳》最後の特殊なケースとして、noneメソッドはサーバが認証チャレンジを使用しないことを要求します。 (また、何らかの形の認証を要求するために否定されることもあります。)

The following methods may be specified: 《機械翻訳》次のメソッドを指定できます。

password

The server must request plaintext password authentication. 《機械翻訳》サーバは、平文パスワード認証を要求する必要があります。

md5

The server must request MD5 hashed password authentication. 《機械翻訳》サーバは、MD5ハッシュパスワード認証を要求する必要があります。

gss

The server must either request a Kerberos handshake via <acronym>GSSAPI</acronym> or establish a <acronym>GSS</acronym>-encrypted channel (see also <xref linkend="libpq-connect-gssencmode" />). 《機械翻訳》サーバはGSSAPIを介してKerberosハンドシェイクを要求するか、GSSで暗号化されたチャネルを確立する必要があります(gssencmodeも参照してください)。

sspi

The server must request Windows <acronym>SSPI</acronym> authentication. 《機械翻訳》サーバは Windows SSPI認証を要求する必要があります。

scram-sha-256

The server must successfully complete a SCRAM-SHA-256 authentication exchange with the client. 《機械翻訳》サーバは、クライアントとのSCRAM-SHA-256認証交換を正常に完了する必要があります。

none

The server must not prompt the client for an authentication exchange. (This does not prohibit client certificate authentication via TLS, nor GSS authentication via its encrypted transport.) 《機械翻訳》サーバはクライアントに認証交換を要求してはならない(これは、TLSによるクライアント証明書認証や、その暗号化されたトランスポートによるGSS認証を禁止するものではない)。

channel_binding #

This option controls the client's use of channel binding. A setting of <literal>require</literal> means that the connection must employ channel binding, <literal>prefer</literal> means that the client will choose channel binding if available, and <literal>disable</literal> prevents the use of channel binding. The default is <literal>prefer</literal> if <productname>PostgreSQL</productname> is compiled with SSL support; otherwise the default is <literal>disable</literal>. このオプションはクライアントのチャンネルバインディングの使用を制御します。 require設定では接続はチャンネルバイデンディングを使わなければならず、preferではクラアイントが可能であればチャンネルバインディングを使い、disableではチャンネルバイディングを使用させません。 PostgreSQLがSSLサポートを伴ってコンパイルされている場合のデフォルトはpreferで、そうでなければデフォルトはdisableです。

Channel binding is a method for the server to authenticate itself to the client. It is only supported over SSL connections with <productname>PostgreSQL</productname> 11 or later servers using the <literal>SCRAM</literal> authentication method. チャンネルバインディングはサーバが自身が信頼できることをクライアントに証明する方法です。 これは、SCRAM認証方式を使ったPostgreSQL 11以降のサーバとのSSL接続上でのみサポートされます。

connect_timeout #

Maximum time to wait while connecting, in seconds (write as a decimal integer, e.g., <literal>10</literal>). Zero, negative, or not specified means wait indefinitely. The minimum allowed timeout is 2 seconds, therefore a value of <literal>1</literal> is interpreted as <literal>2</literal>. This timeout applies separately to each host name or IP address. For example, if you specify two hosts and <literal>connect_timeout</literal> is 5, each host will time out if no connection is made within 5 seconds, so the total time spent waiting for a connection might be up to 10 seconds. 接続中の最大待機時間を秒単位(10進整数で記述してください、10など)で指定します。 ゼロ、負値、もしくは未設定は、無期限の待機を意味します。 許容される最小のタイムアウトは2秒です。 したがって、12と解釈されます。 このタイムアウトは各ホスト名やIPアドレスに別々に適用されます。 例えば、二つのホストを指定して、connect_timeoutが5であるなら、各ホストが5秒以内に接続できないときにタイムアウトして、接続を待つ合計所要時間は10秒近くになるかもしれません。

client_encoding #

This sets the <varname>client_encoding</varname> configuration parameter for this connection. In addition to the values accepted by the corresponding server option, you can use <literal>auto</literal> to determine the right encoding from the current locale in the client (<envar>LC_CTYPE</envar> environment variable on Unix systems). 接続用のclient_encoding設定パラメータを設定します。 対応するサーバオプションで受け付けられる値の他に、クライアントにおける現在のロケール(Unixシステムの場合はLC_CTYPE環境変数)から正しい符号化方式を決定するautoを使用することができます。

options #

Specifies command-line options to send to the server at connection start. For example, setting this to <literal>-c geqo=off</literal> sets the session's value of the <varname>geqo</varname> parameter to <literal>off</literal>. Spaces within this string are considered to separate command-line arguments, unless escaped with a backslash (<literal>\</literal>); write <literal>\\</literal> to represent a literal backslash. For a detailed discussion of the available options, consult <xref linkend="runtime-config"/>. 接続開始時にサーバに送信するコマンドラインオプションを指定します。 例えば、これを-c geqo=offに設定すると、geqoパラメータのセッション値はoffになります。 この文字列中の空白はバックスラッシュ(\)でエスケープされていなければコマンド行引数の区切りであるとみなされます。 リテラルのバックスラッシュを表すには\\と書いて下さい。 利用可能なオプションに関する詳細については第20章を参照してください。

application_name #

Specifies a value for the <xref linkend="guc-application-name"/> configuration parameter. application_name設定パラメータの値を指定します。

fallback_application_name #

Specifies a fallback value for the <xref linkend="guc-application-name"/> configuration parameter. This value will be used if no value has been given for <literal>application_name</literal> via a connection parameter or the <envar>PGAPPNAME</envar> environment variable. Specifying a fallback name is useful in generic utility programs that wish to set a default application name but allow it to be overridden by the user. application_name設定パラメータの予備値を指定します。 接続パラメータまたはPGAPPNAME環境変数によりapplication_nameの値が指定されない場合に、この値が使用されます。 予備の名前を指定することは、デフォルトのアプリケーション名を設定したいが、ユーザにもそれを上書きできるようにしておきたい、一般的なユーティリティプログラムで有用です。

keepalives #

Controls whether client-side TCP keepalives are used. The default value is 1, meaning on, but you can change this to 0, meaning off, if keepalives are not wanted. This parameter is ignored for connections made via a Unix-domain socket. クライアント側におけるTCPキープアライブの使用を制御します。 デフォルト値は1であり、有効であることを意味します。 しかしキープアライブを望まない場合は、無効であることを意味するゼロに設定することができます。 このパラメータはUnixドメインソケット経由の接続では無視されます。

keepalives_idle #

Controls the number of seconds of inactivity after which TCP should send a keepalive message to the server. A value of zero uses the system default. This parameter is ignored for connections made via a Unix-domain socket, or if keepalives are disabled. It is only supported on systems where <symbol>TCP_KEEPIDLE</symbol> or an equivalent socket option is available, and on Windows; on other systems, it has no effect. TCPがサーバにキープアライブメッセージを送信した後に活動を行わない期間を秒単位で制御します。 ゼロという値ではシステムのデフォルトを使用します。 Unixドメインソケット経由でなされた接続の場合もしくはキープアライブが無効な場合、このパラメータは無視されます。 これはTCP_KEEPIDLEまたは同等のソケットオプションが利用できるシステムおよびWindowsでのみサポートされます。 他のシステムでは効果がありません。

keepalives_interval #

Controls the number of seconds after which a TCP keepalive message that is not acknowledged by the server should be retransmitted. A value of zero uses the system default. This parameter is ignored for connections made via a Unix-domain socket, or if keepalives are disabled. It is only supported on systems where <symbol>TCP_KEEPINTVL</symbol> or an equivalent socket option is available, and on Windows; on other systems, it has no effect. TCPキープアライブメッセージに対する応答がサーバからない場合に、何秒後に再送を行うかを制御します。 ゼロという値ではシステムのデフォルトを使用します。 Unixドメインソケット経由でなされた接続の場合、またはキープアライブを無効にしている場合、このパラメータは無視されます。 これはTCP_KEEPINTVLまたは同等のソケットオプションが利用できるシステムおよびWindowsでのみサポートされます。 他のシステムでは効果がありません。

keepalives_count #

Controls the number of TCP keepalives that can be lost before the client's connection to the server is considered dead. A value of zero uses the system default. This parameter is ignored for connections made via a Unix-domain socket, or if keepalives are disabled. It is only supported on systems where <symbol>TCP_KEEPCNT</symbol> or an equivalent socket option is available; on other systems, it has no effect. サーバへのクライアント接続が不要になったとみなすまで、何回キープアライブの欠落を認めるかを制御します。 ゼロという値ではシステムのデフォルトを使用します。 Unixドメインソケット経由でなされた接続の場合、またはキープアライブを無効にしている場合、このパラメータは無視されます。 これはTCP_KEEPCNTまたは同等のソケットオプションが利用できるシステムでのみサポートされます。 他のシステムでは効果がありません。

tcp_user_timeout #

Controls the number of milliseconds that transmitted data may remain unacknowledged before a connection is forcibly closed. A value of zero uses the system default. This parameter is ignored for connections made via a Unix-domain socket. It is only supported on systems where <symbol>TCP_USER_TIMEOUT</symbol> is available; on other systems, it has no effect. 接続が強制的に閉じられるまで、送信されたデータに対して応答がない状況をどれだけ認めるかをミリ秒単位で制御します。 値0はシステムのデフォルトを使用します。 Unixドメインソケット経由でなされた接続の場合、このパラメータは無視されます。 TCP_USER_TIMEOUTが利用可能なシステムでのみサポートされます。 他のシステムでは効果がありません。

replication #

This option determines whether the connection should use the replication protocol instead of the normal protocol. This is what PostgreSQL replication connections as well as tools such as <application>pg_basebackup</application> use internally, but it can also be used by third-party applications. For a description of the replication protocol, consult <xref linkend="protocol-replication"/>. このオプションは接続が通常プロトコルの代わりにレプリケーションプロトコルを使うかどうかを決めます。 これはPostgreSQLのレプリケーション接続やpg_basebackupなどのツールが内部的に使うものですが、サードパーティアプリケーションからも使われることがあります。 レプリケーションプロトコルについての説明は55.4を参照してください。

The following values, which are case-insensitive, are supported: 以下の値がサポートされます。これらは大文字小文字を区別しません。

true, on, yes, 1

The connection goes into physical replication mode. 接続は物理レプリケーションモードになります。

database

The connection goes into logical replication mode, connecting to the database specified in the <literal>dbname</literal> parameter. 接続は論理レプリケーションモードになり、dbnameパラメータで指定されたデータベースに接続します。

false, off, no, 0

The connection is a regular one, which is the default behavior. 接続は通常のものになります。これがデフォルトの振る舞いです。

In physical or logical replication mode, only the simple query protocol can be used. 物理あるいは論理レプリケーションモードでは、簡易問い合わせプロトコルのみが使用できます。

gssencmode #

This option determines whether or with what priority a secure <acronym>GSS</acronym> TCP/IP connection will be negotiated with the server. There are three modes: このオプションは、GSSによる安全なTCP/IP接続をサーバと調停するか、するのならどの優先度で調停するかを決定します。 3つのモードがあります。

disable

only try a non-<acronym>GSSAPI</acronym>-encrypted connection GSSAPI暗号化接続のみ試行

prefer (デフォルト)

if there are <acronym>GSSAPI</acronym> credentials present (i.e., in a credentials cache), first try a <acronym>GSSAPI</acronym>-encrypted connection; if that fails or there are no credentials, try a non-<acronym>GSSAPI</acronym>-encrypted connection. This is the default when <productname>PostgreSQL</productname> has been compiled with <acronym>GSSAPI</acronym> support. GSSAPI認証情報が(すなわち認証情報キャッシュに)存在すれば、まずGSSAPI暗号化接続を試行します。 その試行に失敗した場合、もしくは認証情報がない場合には非GSSAPI暗号化接続を試行します。 これがPostgreSQLGSSAPIサポートを有効にしてコンパイルした場合のデフォルトです。

require

only try a <acronym>GSSAPI</acronym>-encrypted connection GSSAPI暗号化接続のみ試行

<literal>gssencmode</literal> is ignored for Unix domain socket communication. If <productname>PostgreSQL</productname> is compiled without GSSAPI support, using the <literal>require</literal> option will cause an error, while <literal>prefer</literal> will be accepted but <application>libpq</application> will not actually attempt a <acronym>GSSAPI</acronym>-encrypted connection.<indexterm><primary>GSSAPI</primary><secondary sortas="libpq">with libpq</secondary></indexterm> gssencmodeはUnixドメインソケット通信では無視されます。 PostgreSQLがGSSAPIなしでコンパイルされた場合、requireオプションを使うとエラーになります。一方、preferは受け付けられますが、libpqは実際にはGSSAPI暗号化接続を試行しません。

sslmode #

This option determines whether or with what priority a secure <acronym>SSL</acronym> TCP/IP connection will be negotiated with the server. There are six modes: このオプションは、どのSSLによる安全なTCP/IP接続の優先度でサーバと調停するかを決定します。 6つのモードがあります。

disable

only try a non-<acronym>SSL</acronym> connection SSL接続のみ試行

allow

first try a non-<acronym>SSL</acronym> connection; if that fails, try an <acronym>SSL</acronym> connection 最初に非SSL接続を試行し、失敗したら、SSL接続を試行

prefer (デフォルト)

first try an <acronym>SSL</acronym> connection; if that fails, try a non-<acronym>SSL</acronym> connection 最初にSSL接続を試行し、失敗したら、非SSL接続を試行

require

only try an <acronym>SSL</acronym> connection. If a root CA file is present, verify the certificate in the same way as if <literal>verify-ca</literal> was specified SSL接続のみ試行。 ルートCAファイルが存在する場合、verify-caが指定された場合と同じ方法で証明書が検証されます。

verify-ca

only try an <acronym>SSL</acronym> connection, and verify that the server certificate is issued by a trusted certificate authority (<acronym>CA</acronym>) SSL接続のみ試行し、サーバ証明書が信用された認証局(CA)から発行されたかを検証

verify-full

only try an <acronym>SSL</acronym> connection, verify that the server certificate is issued by a trusted <acronym>CA</acronym> and that the requested server host name matches that in the certificate SSL接続のみ試行し、サーバ証明書が信用されたCAから発行されたか、およびそのサーバホスト名が証明書内のものと一致するかを検証

See <xref linkend="libpq-ssl"/> for a detailed description of how these options work. これらのオプションがどのように動くのかについては34.19を参照してください。

<literal>sslmode</literal> is ignored for Unix domain socket communication. If <productname>PostgreSQL</productname> is compiled without SSL support, using options <literal>require</literal>, <literal>verify-ca</literal>, or <literal>verify-full</literal> will cause an error, while options <literal>allow</literal> and <literal>prefer</literal> will be accepted but <application>libpq</application> will not actually attempt an <acronym>SSL</acronym> connection.<indexterm><primary>SSL</primary><secondary sortas="libpq">with libpq</secondary></indexterm> sslmodeはUnixドメインソケット通信では無視されます。 SSLサポートなしでPostgreSQLがコンパイルされた場合に、requireverify-caverify-fullを使用するとエラーになります。 一方、allowpreferは使用できますが、実際にlibpqSSL接続を受け付けません。

Note that if <acronym>GSSAPI</acronym> encryption is possible, that will be used in preference to <acronym>SSL</acronym> encryption, regardless of the value of <literal>sslmode</literal>. To force use of <acronym>SSL</acronym> encryption in an environment that has working <acronym>GSSAPI</acronym> infrastructure (such as a Kerberos server), also set <literal>gssencmode</literal> to <literal>disable</literal>. GSSAPI暗号化が可能な場合、sslmodeの値に関係なく、SSL暗号化よりも優先して使用されることに注意してください。 GSSAPIインフラストラクチャが動作している環境(Kerberosサーバなど)でSSL暗号化を強制的に使用するには、gssencmodedisableに設定します。

requiressl #

This option is deprecated in favor of the <literal>sslmode</literal> setting. このオプションはsslmode設定を支持する観点から廃止予定になっています。

If set to 1, an <acronym>SSL</acronym> connection to the server is required (this is equivalent to <literal>sslmode</literal> <literal>require</literal>). <application>libpq</application> will then refuse to connect if the server does not accept an <acronym>SSL</acronym> connection. If set to 0 (default), <application>libpq</application> will negotiate the connection type with the server (equivalent to <literal>sslmode</literal> <literal>prefer</literal>). This option is only available if <productname>PostgreSQL</productname> is compiled with SSL support. 1に設定することで、サーバへのSSL接続が必要になります (これはsslmoderequireと同じです)。 サーバがSSL接続を受け付けない場合、libpqは接続を拒絶します。 0(デフォルト)に設定することで、libpqはサーバと接続形式の調停を行います。 (sslmodepreferと同じです。) SSLサポート付きでPostgreSQLをコンパイルした場合にのみ、このオプションが利用できます。

sslcompression #

If set to 1, data sent over SSL connections will be compressed. If set to 0, compression will be disabled. The default is 0. This parameter is ignored if a connection without SSL is made. 1に設定することで、SSL接続越えで送信されるデータは圧縮されます。 0に設定すると、圧縮が無効になります。 デフォルトは0です。 このパラメータはSSLを使わない接続では無視されます。

SSL compression is nowadays considered insecure and its use is no longer recommended. <productname>OpenSSL</productname> 1.1.0 disables compression by default, and many operating system distributions disable it in prior versions as well, so setting this parameter to on will not have any effect if the server does not accept compression. <productname>PostgreSQL</productname> 14 disables compression completely in the backend. SSL圧縮は今日では安全ではないと考えられていて、もはや使用は推奨されません。 OpenSSL 1.1.0はデフォルトでは圧縮を無効にしており、多くのOSディストリビューションでもこれまでのバージョンで無効化しています。そのため、サーバが圧縮を受け付けない場合、本パラメータをonに設定しても効果がありません。 PostgreSQL 14はバックエンドでの圧縮を完全に無効にしています。

If security is not a primary concern, compression can improve throughput if the network is the bottleneck. Disabling compression can improve response time and throughput if CPU performance is the limiting factor. セキュリティが主要な関心でないなら、ネットワークがボトルネックであるとき圧縮でスループットを改善できます。 CPU性能が律速要素であるなら、圧縮を無効化することで応答時間とスループットを改善できます。

sslcert #

This parameter specifies the file name of the client SSL certificate, replacing the default <filename>~/.postgresql/postgresql.crt</filename>. This parameter is ignored if an SSL connection is not made. このパラメータは、~/.postgresql/postgresql.crtというデフォルトを置き換えるクライアントSSL証明書のファイル名を指定します。 このパラメータはSSL接続が確立していない場合は無視されます。

sslkey #

This parameter specifies the location for the secret key used for the client certificate. It can either specify a file name that will be used instead of the default <filename>~/.postgresql/postgresql.key</filename>, or it can specify a key obtained from an external <quote>engine</quote> (engines are <productname>OpenSSL</productname> loadable modules). An external engine specification should consist of a colon-separated engine name and an engine-specific key identifier. This parameter is ignored if an SSL connection is not made. このパラメータはクライアント証明書に対して使用される秘密鍵の場所を指定します。 デフォルトの~/.postgresql/postgresql.keyの代わりに使用されるファイル名、または外部エンジン(エンジンとはOpenSSLロード可能なモジュール)から得られるキーを指定することも可能です。 外部エンジンの指定にはコロンで区切ったエンジン名とエンジン特有の鍵識別子を含んでいなければなりません。 SSL接続が確立していない場合このパラメータは無視されます。

sslpassword #

This parameter specifies the password for the secret key specified in <literal>sslkey</literal>, allowing client certificate private keys to be stored in encrypted form on disk even when interactive passphrase input is not practical. このパラメータはsslkeyで指定される秘密鍵に対するパスワードを指定して、対話的なパスフレーズ入力が現実的でないときにも、クライアント証明書のプライベートキーを暗号化された形式でディスクに格納できるようにします。

Specifying this parameter with any non-empty value suppresses the <literal>Enter PEM pass phrase:</literal> prompt that <productname>OpenSSL</productname> will emit by default when an encrypted client certificate key is provided to <literal>libpq</literal>. 空でない値でこのパラメータを指定することで、暗号化されたクライアント証明書キーがlibpqに供給されるときにOpenSSLがデフォルトで出すEnter PEM pass phrase:プロンプトを抑止します。

If the key is not encrypted this parameter is ignored. The parameter has no effect on keys specified by <productname>OpenSSL</productname> engines unless the engine uses the <productname>OpenSSL</productname> password callback mechanism for prompts. キーが暗号化されていない場合、このパラメータは無視されます。 OpenSSLエンジンがプロンプトにOpenSSLパスワードコールバックの仕組みを使わない限り、このパラメータはエンジンで指定されたキーに影響しません。

There is no environment variable equivalent to this option, and no facility for looking it up in <filename>.pgpass</filename>. It can be used in a service file connection definition. Users with more sophisticated uses should consider using <productname>OpenSSL</productname> engines and tools like PKCS#11 or USB crypto offload devices. このオプションと同等の環境変数、および、パスワードを.pgpassから探す機能はありません。 このオプションはサービスファイルの接続定義で使用できます。 より高度な使用法を用いるユーザは、OpenSSLエンジンとPKCS#11やUSB暗号オフロードデバイスといったツールの利用を検討すべきです。

sslcertmode #

This option determines whether a client certificate may be sent to the server, and whether the server is required to request one. There are three modes: 《機械翻訳》このオプションは、クライアント証明書をサーバに送信するかどうか、およびサーバがそれを要求する必要があるかどうかを決定します。 以下の3つのモードがあります。

disable

A client certificate is never sent, even if one is available (default location or provided via <xref linkend="libpq-connect-sslcert" />). 《機械翻訳》クライアント証明書は、使用可能であっても(デフォルトの場所またはsslcertで提供されている場合)、決して送信されません。

allow (default)

A certificate may be sent, if the server requests one and the client has one to send. 《機械翻訳》サーバが証明書を要求し、クライアントが送信する証明書を持っている場合は、証明書を送信することができます。

require

The server <emphasis>must</emphasis> request a certificate. The connection will fail if the client does not send a certificate and the server successfully authenticates the client anyway. 《機械翻訳》サーバは証明書を要求する必要があります。 クライアントが証明書を送信しない場合でも、サーバはクライアントを認証するため、接続は失敗します。

注記

<literal>sslcertmode=require</literal> doesn't add any additional security, since there is no guarantee that the server is validating the certificate correctly; PostgreSQL servers generally request TLS certificates from clients whether they validate them or not. The option may be useful when troubleshooting more complicated TLS setups. 《機械翻訳》sslcertmode=requireは、サーバが証明書を正しく検証しているかどうかを保証しないため、追加のセキュリティを追加するものではありません。 PostgreSQLサーバは、一般に、有効にするかどうかに関係なく、クライアントからTLS証明書を要求します。 このオプションは、より複雑なTLS設定のトラブルシューティングに役立つ場合があります。

sslrootcert #

This parameter specifies the name of a file containing SSL certificate authority (<acronym>CA</acronym>) certificate(s). If the file exists, the server's certificate will be verified to be signed by one of these authorities. The default is <filename>~/.postgresql/root.crt</filename>. このパラメータはSSL認証局(CA)の証明書のファイル名を指定します。 このファイルが存在する場合、サーバ証明書はこれらの認証局の1つで署名されているかどうか検証されます。 デフォルトは~/.postgresql/root.crtです。

The special value <literal>system</literal> may be specified instead, in which case the system's trusted CA roots will be loaded. The exact locations of these root certificates differ by SSL implementation and platform. For <productname>OpenSSL</productname> in particular, the locations may be further modified by the <envar>SSL_CERT_DIR</envar> and <envar>SSL_CERT_FILE</envar> environment variables. 《機械翻訳》特別な値systemを指定することもできます。 この場合、システムの信頼できるCAルートがロードされます。 これらのルート証明書の正確な位置は、SSL実装とプラットフォームによって異なります。 OpenSSLの場合、特に、SSL_CERT_DIRSSL_CERT_FILE環境変数によって位置がさらに変更される可能性があります。

注記

When using <literal>sslrootcert=system</literal>, the default <literal>sslmode</literal> is changed to <literal>verify-full</literal>, and any weaker setting will result in an error. In most cases it is trivial for anyone to obtain a certificate trusted by the system for a hostname they control, rendering <literal>verify-ca</literal> and all weaker modes useless. 《機械翻訳》sslrootcert=systemを使用すると、デフォルトのsslmodeverify-fullに変更され、より弱い設定はエラーになります。 ほとんどの場合、誰かが制御するホスト名に対してシステムが信頼できる証明書を取得することは簡単であり、verify-caや他の弱いモードはすべて無意味になります。

The magic <literal>system</literal> value will take precedence over a local certificate file with the same name. If for some reason you find yourself in this situation, use an alternative path like <literal>sslrootcert=./system</literal> instead. 《機械翻訳》マジック値 system は、同じ名前のローカル証明書ファイルよりも優先されます。 何らかの理由でこのような状況になった場合は、代わりに sslrootcert=./system のような別のパスを使用してください。

sslcrl #

This parameter specifies the file name of the SSL server certificate revocation list (CRL). Certificates listed in this file, if it exists, will be rejected while attempting to authenticate the server's certificate. If neither <xref linkend="libpq-connect-sslcrl"/> nor <xref linkend="libpq-connect-sslcrldir"/> is set, this setting is taken as <filename>~/.postgresql/root.crl</filename>. 《マッチ度[82.005141]》このパラメータはSSLサーバ証明書失効リスト(CRL)のファイル名を指定します。 このファイルに列挙された証明書が存在した場合、それはサーバ証明書を承認しようとする時に拒絶されます。 sslcrlsslcrldirも設定されていなければ、設定は~/.postgresql/root.crlから取得されます。 《機械翻訳》このパラメータは、SSLサーバ証明書失効リスト(CRL)のファイル名を指定します。 このファイルが存在する場合、サーバの証明書を認証しようとするときに拒否されます。 sslcrlsslcrldirも設定されていない場合、この設定は~/.postgresql/root.crlとして取られます。

sslcrldir #

This parameter specifies the directory name of the SSL server certificate revocation list (CRL). Certificates listed in the files in this directory, if it exists, will be rejected while attempting to authenticate the server's certificate. このパラメータは、SSLサーバ証明書失効リスト(CRL)のディレクトリ名を指定します。 このディレクトリのファイルにリストされている証明書が存在する場合は、サーバーの証明書の認証中に拒否されます。

The directory needs to be prepared with the <productname>OpenSSL</productname> command <literal>openssl rehash</literal> or <literal>c_rehash</literal>. See its documentation for details. ディレクトリは、OpenSSLコマンドopenssl rehashまたはc_rehashを使用して準備する必要があります。 詳細はそのドキュメントを参照してください。

Both <literal>sslcrl</literal> and <literal>sslcrldir</literal> can be specified together. sslcrlsslcrldirの両方を同時に指定できます。

sslsni #

If set to 1 (default), libpq sets the TLS extension <quote>Server Name Indication</quote> (<acronym>SNI</acronym>) on SSL-enabled connections. By setting this parameter to 0, this is turned off. 1(デフォルト)に設定されている場合、libpqはTLS拡張Server Name Indication(SNI)をSSL使用可能な接続に設定します。 このパラメータを0に設定することにより、これはオフになります。

The Server Name Indication can be used by SSL-aware proxies to route connections without having to decrypt the SSL stream. (Note that this requires a proxy that is aware of the PostgreSQL protocol handshake, not just any SSL proxy.) However, <acronym>SNI</acronym> makes the destination host name appear in cleartext in the network traffic, so it might be undesirable in some cases. Server Name Indicationは、SSLストリームを復号化することなく接続をルーティングするために、SSL対応プロキシによって使用できます(これには、SSLプロキシだけでなく、PostgreSQLプロトコルハンドシェイクを認識するプロキシが必要であることに注意してください)。 しかし、SNIは宛先ホスト名をネットワークトラフィック中に平文で表示しますので、場合によっては望ましくないかもしれません。

requirepeer #

This parameter specifies the operating-system user name of the server, for example <literal>requirepeer=postgres</literal>. When making a Unix-domain socket connection, if this parameter is set, the client checks at the beginning of the connection that the server process is running under the specified user name; if it is not, the connection is aborted with an error. This parameter can be used to provide server authentication similar to that available with SSL certificates on TCP/IP connections. (Note that if the Unix-domain socket is in <filename>/tmp</filename> or another publicly writable location, any user could start a server listening there. Use this parameter to ensure that you are connected to a server run by a trusted user.) This option is only supported on platforms for which the <literal>peer</literal> authentication method is implemented; see <xref linkend="auth-peer"/>. このパラメータは、例えばrequirepeer=postgresのようにサーバのオペレーティングシステムのユーザ名を指定します。 Unixドメインソケット接続を確立する時に、このパラメータが設定された場合、クライアントは接続開始時にサーバプロセスが指定されたユーザ名で稼働しているか検査し、稼働していない場合は接続をエラーとして中断します。 このパラメータは、TCP/IP接続においてSSL証明書で実現するようなサーバ認証を実現するために使用することができます。 (Unixドメインソケットが/tmpなどの誰にでも書き込むことができる場所にある場合、誰でもそこで接続を監視するサーバを起動できることに注意してください。 信頼できるユーザが起動したサーバに接続することを確実に行うために、このパラメータを使用してください。) このオプションはpeer認証方式が実装されたプラットフォームでのみでサポートされます。 21.9を参照してください。

ssl_min_protocol_version #

This parameter specifies the minimum SSL/TLS protocol version to allow for the connection. Valid values are <literal>TLSv1</literal>, <literal>TLSv1.1</literal>, <literal>TLSv1.2</literal> and <literal>TLSv1.3</literal>. The supported protocols depend on the version of <productname>OpenSSL</productname> used, older versions not supporting the most modern protocol versions. If not specified, the default is <literal>TLSv1.2</literal>, which satisfies industry best practices as of this writing. このパラメータは接続で許容されるSSL/TLSプロトコルの最小バージョンを指定します。 有効な値はTLSv1TLSv1.1TLSv1.2、および、TLSv1.3です。 対応しているプロトコルは使われているOpenSSLバージョンに依存し、より古いバージョンでは最新プトロコルバージョンに対応していません。 指定しない場合、デフォルトはTLSv1.2で、これは執筆時点では業界標準を満たします。

ssl_max_protocol_version #

This parameter specifies the maximum SSL/TLS protocol version to allow for the connection. Valid values are <literal>TLSv1</literal>, <literal>TLSv1.1</literal>, <literal>TLSv1.2</literal> and <literal>TLSv1.3</literal>. The supported protocols depend on the version of <productname>OpenSSL</productname> used, older versions not supporting the most modern protocol versions. If not set, this parameter is ignored and the connection will use the maximum bound defined by the backend, if set. Setting the maximum protocol version is mainly useful for testing or if some component has issues working with a newer protocol. このパラメータは接続で許容されるSSL/TLSプロトコルの最大バージョンを指定します。 有効な値はTLSv1TLSv1.1TLSv1.2、および、TLSv1.3です。 対応しているプロトコルは使われているOpenSSLバージョンに依存し、より古いバージョンでは最新のプロトコルバージョンに対応していません。 設定しない場合、このパラメータは無視されて、接続ではバックエンドで定義されている最大範囲が、もし定義されているなら、使われます。 テストや、一部コンポーネントがより新しいプロトコルでの動作に問題がある場合に対して、大概はプロトコルの最大バージョンを設定することが有用です。

krbsrvname #

Kerberos service name to use when authenticating with GSSAPI. This must match the service name specified in the server configuration for Kerberos authentication to succeed. (See also <xref linkend="gssapi-auth"/>.) The default value is normally <literal>postgres</literal>, but that can be changed when building <productname>PostgreSQL</productname> via the <option>&#45;-with-krb-srvnam</option> option of <application>configure</application>. In most environments, this parameter never needs to be changed. Some Kerberos implementations might require a different service name, such as Microsoft Active Directory which requires the service name to be in upper case (<literal>POSTGRES</literal>). GSSAPIの認証時に使われるKerberosサービス名です。 成功するためには、これはサーバのKerberos認証設定のサービス名と一致していなければなりません。 (21.6も参照してください。) デフォルト値は通常postgresですが、PostgreSQLconfigure--with-krb-srvnamオプションを使ってビルドすることにより変更できます。 大抵の環境ではこのパラメータは滅多に変更の必要がありません。 サービス名が大文字(POSTGRES)であることを要求するMicrosoft Active Directoryのように、ある種のKerberos実装では異なるサービス名が必要になるかもしれません。

gsslib #

GSS library to use for GSSAPI authentication. Currently this is disregarded except on Windows builds that include both GSSAPI and SSPI support. In that case, set this to <literal>gssapi</literal> to cause libpq to use the GSSAPI library for authentication instead of the default SSPI. GSSAPI認証で使用されるGSSライブラリです。 これは今のところ、GSSAPIとSSPIの両方のサポートを含むWindowsビルド版を除いて無視されます。 その場合、認証にデフォルトのSSPIではなく、GSSAPIライブラリを使うようlibpqに強制するには、これをgssapiに設定してください。

gssdelegation #

Forward (delegate) GSS credentials to the server. The default is <literal>0</literal> which means credentials will not be forwarded to the server. Set this to <literal>1</literal> to have credentials forwarded when possible. 《機械翻訳》GSS 資格証明をサーバに転送 (委任) します。 デフォルトは 0 で、これは資格証明がサーバに転送されないことを意味します。 可能な場合は資格証明を転送するには 1 に設定します。

service #

Service name to use for additional parameters. It specifies a service name in <filename>pg_service.conf</filename> that holds additional connection parameters. This allows applications to specify only a service name so connection parameters can be centrally maintained. See <xref linkend="libpq-pgservice"/>. 追加のパラメータ用に使用されるサービス名です。 pg_service.conf内の追加的な接続パラメータを保持するサービス名を指定します。 これによりアプリケーションはサービス名だけを指定でき、接続パラメータを集中的に保守できるようになります。 34.17を参照してください。

target_session_attrs #

This option determines whether the session must have certain properties to be acceptable. It's typically used in combination with multiple host names to select the first acceptable alternative among several hosts. There are six modes: このオプションは、セッションが受け入れられるために特定のプロパティを持つ必要があるかどうかを決定します。 これは通常、複数のホスト名と組み合わせて使用され、いくつかのホストの中から最初に受け入れられる代替を選択します。 6つのモードがあります:

any (default)

any successful connection is acceptable 成功した接続は受け入れられます

read-write

session must accept read-write transactions by default (that is, the server must not be in hot standby mode and the <varname>default_transaction_read_only</varname> parameter must be <literal>off</literal>) セッションはデフォルトで読み書きトランザクションを受け入れなければなりません(つまり、サーバはホットスタンバイモードであってはならず、default_transaction_read_onlyパラメータはoffでなければなりません)。

read-only

session must not accept read-write transactions by default (the converse) セッションはデフォルトで読み書きトランザクションを受け入れてはなりません(逆)

primary

server must not be in hot standby mode サーバーはホット・スタンバイ・モードであってはなりません

standby

server must be in hot standby mode サーバーはホット・スタンバイ・モードでなければなりません

prefer-standby

first try to find a standby server, but if none of the listed hosts is a standby server, try again in <literal>any</literal> mode 最初にスタンバイサーバを見つけようとしますが、リストされているホストがいずれもスタンバイサーバでない場合は、anyモードで再試行します。

load_balance_hosts #

Controls the order in which the client tries to connect to the available hosts and addresses. Once a connection attempt is successful no other hosts and addresses will be tried. This parameter is typically used in combination with multiple host names or a DNS record that returns multiple IPs. This parameter can be used in combination with <xref linkend="libpq-connect-target-session-attrs"/> to, for example, load balance over standby servers only. Once successfully connected, subsequent queries on the returned connection will all be sent to the same server. There are currently two modes: 《機械翻訳》使用可能なホストおよびアドレスへの接続試行をクライアントが試行する順序を制御します。 接続が成功すると、他のホストおよびアドレスへの試行は行われません。 このパラメータは、通常、複数のホスト名または複数のIPを返すDNSレコードと組み合わせて使用されます。 このパラメータは、例えばロードバランシングを実行するためにtarget_session_attrsと組み合わせて使用できます。 接続に成功すると、返された接続に対するすべての負荷分散は同じサーバで実行されます。 クライアントが提供されたホストからの接続を試行し、DNSまたはホストファイルからIPを受信する順序でアドレスが試行されます。

disable (default)

No load balancing across hosts is performed. Hosts are tried in the order in which they are provided and addresses are tried in the order they are received from DNS or a hosts file.

random

Hosts and addresses are tried in random order. This value is mostly useful when opening multiple connections at the same time, possibly from different machines. This way connections can be load balanced across multiple <productname>PostgreSQL</productname> servers. 《機械翻訳》ホストとアドレスはランダムな順序で試されます。 この値は、同時に複数の接続を開こうとする場合、おそらく異なるマシンからの接続を開こうとする場合に便利です。 このようにして、複数のPostgreSQLサーバ間で接続をロードバランスできます。

While random load balancing, due to its random nature, will almost never result in a completely uniform distribution, it statistically gets quite close. One important aspect here is that this algorithm uses two levels of random choices: First the hosts will be resolved in random order. Then secondly, before resolving the next host, all resolved addresses for the current host will be tried in random order. This behaviour can skew the amount of connections each node gets greatly in certain cases, for instance when some hosts resolve to more addresses than others. But such a skew can also be used on purpose, e.g. to increase the number of connections a larger server gets by providing its hostname multiple times in the host string. 《機械翻訳》ランダム負荷分散は、そのランダムな性質のために、完全に均一な分布になることはほとんどありませんが、統計的には非常に近くなります。 ここで重要な側面の1つは、このアルゴリズムが2つのレベルのランダム選択を使用することである。 まず、ホストはランダムな順序で解決される。 次に、次のホストを解決する前に、現在のホストのすべての解決済みアドレスがランダムな順序で試される。 この動作は、特定のケースで各ノードが取得する接続の数を大幅に歪める可能性があります。たとえば、一部のホストが他のホストより多くのアドレスを解決する場合などです。 しかし、このようなスキューは、特定の目的で意図的に使用することもできます。たとえば、ホスト文字列で複数回ホスト名を指定することによって、大きなサーバーが取得する接続数を増やすことができます。

When using this value it's recommended to also configure a reasonable value for <xref linkend="libpq-connect-connect-timeout"/>. Because then, if one of the nodes that are used for load balancing is not responding, a new node will be tried. 《機械翻訳》この値を使用する場合、connect_timeoutにも妥当な値を設定することをお勧めします。 なぜなら、負荷分散に使用されているノードの1つが応答しない場合、新しいノードが試されるからです。