dblink_connect <refpurpose>opens a persistent connection to a remote database</refpurpose> — リモートデータベースへの永続的な接続を開く
dblink_connect(text connstr) returns text dblink_connect(text connname, text connstr) returns text
<function>dblink_connect()</function> establishes a connection to a remote
<productname>PostgreSQL</productname> database. The server and database to
be contacted are identified through a standard <application>libpq</application>
connection string. Optionally, a name can be assigned to the
connection. Multiple named connections can be open at once, but
only one unnamed connection is permitted at a time. The connection
will persist until closed or until the database session is ended.
dblink_connect()
はリモートのPostgreSQLデータベースへの接続を確立します。
接続先のサーバとデータベースは標準のlibpq接続文字列を通して識別されます。
省略可能ですが、名前を接続に割り当てることも可能です。
複数の名前付きの接続を一度に開くことができますが、無名の接続は同時に1つしか許されません。
接続は、閉ざされるまで、または、データベースセッションが終わるまで永続します。
The connection string may also be the name of an existing foreign
server. It is recommended to use the foreign-data wrapper
<literal>dblink_fdw</literal> when defining the foreign
server. See the example below, as well as
<xref linkend="sql-createserver"/> and
<xref linkend="sql-createusermapping"/>.
接続文字列は同時に既存の外部サーバ名であっても構いません。
外部サーバを定義する場合、外部データラッパーdblink_fdw
を使用することを推奨します。
後述の例とCREATE SERVER、CREATE USER MAPPINGを参照してください。
connname
The name to use for this connection; if omitted, an unnamed connection is opened, replacing any existing unnamed connection. 接続に使用する名前です。省略した場合、既存の無名の接続を閉ざし、無名の接続を開きます。
connstr
例えばhostaddr=127.0.0.1 port=5432 dbname=mydb user=postgres password=mypasswd
といったlibpq形式の接続情報文字列です。
詳細は32.1.1を参照してください。
もしくは外部サーバ名です。
Returns status, which is always <literal>OK</literal> (since any error
causes the function to throw an error instead of returning).
状態を返します。
これは常にOK
です(何らかのエラーが起きるとこの関数は戻らずエラーとなるためです)。
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 could, for example,
add <literal>options=-csearch_path=</literal> to
<parameter>connstr</parameter>. This consideration is not specific
to <filename>dblink</filename>; it applies to every interface for
executing arbitrary SQL commands.
信頼できないユーザが、安全なスキーマ使用パターンを適用していないデータベースへアクセスする際には、セッション開始時にsearch_path
から、第三者が書き込みができるスキーマを削除してください。
これはたとえばconnstr
に値-csearch_path=
を設定することで可能となります。
このような配慮は、dblink
に限ったことではありません。
任意のSQLコマンドを実行するすべてのインタフェースに当てはまります。
The foreign-data wrapper <filename>dblink_fdw</filename> has an additional
Boolean option <literal>use_scram_passthrough</literal> that controls
whether <filename>dblink</filename> will use the SCRAM pass-through
authentication to connect to the remote database. With SCRAM pass-through
authentication, <filename>dblink</filename> uses SCRAM-hashed secrets
instead of plain-text user passwords to connect to the remote server. This
avoids storing plain-text user passwords in PostgreSQL system catalogs.
See the documentation of the equivalent <link
linkend="postgres-fdw-option-use-scram-passthrough"><literal>use_scram_passthrough</literal></link>
option of postgres_fdw for further details and restrictions.
《機械翻訳》外部データラッパーdblink_fdw
には、追加のブールオプションがありますuse_scram_passthrough
dblink
がSCRAMパススルー認証を使用してリモートデータベースに接続するかどうかを制御します。
SCRAMパススルー認証では、はdblink
SCRAMハッシュされた秘密代わりプレーンテキストユーザパスワードを使用してリモートサーバに接続します。
これにより、プレーンテキストユーザパスワードがPostgreSQLシステムカタログに格納されるのを回避します。
詳細と制限については、POSTGRES_fdwの対応するuse_scram_passthrough
オプションの文書を参照してください。
Only superusers may use <function>dblink_connect</function> to create
connections that use neither password authentication, SCRAM pass-through,
nor GSSAPI-authentication.
If non-superusers need this capability, use
<function>dblink_connect_u</function> instead.
《マッチ度[71.647510]》スーパーユーザのみがパスワード認証やGSSAPI認証がない接続を作成するためにdblink_connect
を使用できます。
スーパーユーザ以外でこの機能が必要ならばdblink_connect_u
を代わりに使用してください。
《機械翻訳》スーパーユーザのみがdblink_connect
パスワード認証、SCRAMパススルー、GSSAPI-認証のいずれも使用しない接続を作成するために使用できます。
スーパーユーザ以外がこの機能を必要とする場合は、dblink_connect_u
代わりにを使用してください。
It is unwise to choose connection names that contain equal signs,
as this opens a risk of confusion with connection info strings
in other <filename>dblink</filename> functions.
他のdblink
関数内で接続情報文字列が混乱する危険が発生しますので、等号記号を含む接続名を選択することは勧めません。
SELECT dblink_connect('dbname=postgres options=-csearch_path='); dblink_connect ---------------- OK (1 row) SELECT dblink_connect('myconn', 'dbname=postgres options=-csearch_path='); dblink_connect ---------------- OK (1 row) -- FOREIGN DATA WRAPPER functionality -- Note: local connections that don't use SCRAM pass-through require password -- authentication for this to work properly. Otherwise, you will receive -- the following error from dblink_connect(): -- ERROR: password is required -- DETAIL: Non-superuser cannot connect if the server does not request a password. -- HINT: Target server's authentication method must be changed. CREATE SERVER fdtest FOREIGN DATA WRAPPER dblink_fdw OPTIONS (hostaddr '127.0.0.1', dbname 'contrib_regression'); CREATE USER regress_dblink_user WITH PASSWORD 'secret'; CREATE USER MAPPING FOR regress_dblink_user SERVER fdtest OPTIONS (user 'regress_dblink_user', password 'secret'); GRANT USAGE ON FOREIGN SERVER fdtest TO regress_dblink_user; GRANT SELECT ON TABLE foo TO regress_dblink_user; \set ORIGINAL_USER :USER \c - regress_dblink_user SELECT dblink_connect('myconn', 'fdtest'); dblink_connect ---------------- OK (1 row) SELECT * FROM dblink('myconn', 'SELECT * FROM foo') AS t(a int, b text, c text[]); a | b | c ----+---+--------------- 0 | a | {a0,b0,c0} 1 | b | {a1,b1,c1} 2 | c | {a2,b2,c2} 3 | d | {a3,b3,c3} 4 | e | {a4,b4,c4} 5 | f | {a5,b5,c5} 6 | g | {a6,b6,c6} 7 | h | {a7,b7,c7} 8 | i | {a8,b8,c8} 9 | j | {a9,b9,c9} 10 | k | {a10,b10,c10} (11 rows) \c - :ORIGINAL_USER REVOKE USAGE ON FOREIGN SERVER fdtest FROM regress_dblink_user; REVOKE SELECT ON TABLE foo FROM regress_dblink_user; DROP USER MAPPING FOR regress_dblink_user SERVER fdtest; DROP USER regress_dblink_user; DROP SERVER fdtest;