当我使用远程服务器的命名连接或未命名的连接和断开时,似乎无法工作。如果我在dblink()中使用带有连接字符串的未命名连接,它可以正常工作。它似乎连接良好,但当我尝试使用它时,我的连接是不可用的。对于如何使用命名的连接,有什么想法吗?
未命名的connstr工作很好:
SELECT testtable.*
FROM dblink('dbname=testdb port=5432 host=192.168.1.1 user=usr password=pw'
,'SELECT * FROM testtable')
AS testtable(testtable_id integer, testtable_name text);返回:如预期的两列。
命名不起作用:
连接:
SELECT dblink_connect('myconn'
,'dbname=testdb port=5432 host=192.168.1.1 user=usr password=pw');返回:“确定”
查询:
SELECT testtable.* FROM dblink('myconn', 'SELECT * FROM testtable')
AS testtable(testtable_id integer, testtable_name text);返回:
ERROR: could not establish connection
DETAIL: missing "=" after "myconn" in connection info string
********** Error **********
ERROR: could not establish connection
SQL state: 08001
Detail: missing "=" after "myconn" in connection info string断开:
SELECT dblink_disconnect('myconn');返回:
ERROR: connection "myconn" not available
********** Error **********
ERROR: connection "myconn" not available
SQL state: 08003未命名的_connect和_disconnect不起作用:
连接:
SELECT dblink_connect('dbname=testdb port=5432 host=192.168.1.1
user=usr password=pw');返回:“确定”
查询:
SELECT testtable.* FROM dblink('SELECT * FROM testtable')
AS testtable(testtable_id integer, testtable_name text);返回:
ERROR: connection not available
********** Error **********
ERROR: connection not available
SQL state: 08003断开:
SELECT dblink_disconnect();返回:
ERROR: connection not available
********** Error **********
ERROR: connection not available
SQL state: 08003发布于 2012-03-26 18:01:52
我有一个具有未命名连接的工作设置。
在您的问题中,您所称的“未命名的”实际上有一个名称参数。你把这两个变体搞混了。不用'myconn'就试试吧
SELECT *
FROM dblink('SELECT * FROM testtable'
) AS testtable (testtable_id integer, testtable_name text);请记住,建立并使用连接必须发生在同一个会话中。
但老实说,我找不到您的名为connection的有什么问题。我做了几次测试,一切看起来都是正确的。我用PostgreSQL 9.1进行了测试。
错误消息意味着dblink需要一个connstr。只有当第一个参数与存在的任何connname不匹配时才会发生这种情况:没有找到连接'myconn' --这使我怀疑您在会话中没有调用与dblink_connect()相同的会话。
https://stackoverflow.com/questions/9876573
复制相似问题