设置从 SQL Server 2005 到 PostgreSQL 的链接服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/711303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 23:41:04  来源:igfitidea点击:

Setting up a linked server from SQL Server 2005 to PostgreSQL

sql-serversql-server-2005postgresqllinked-server

提问by Tom H

Since I struggled a bit with this one and couldn't find a good online source with simple steps, here it is.

由于我在这个方面有点挣扎,并且无法通过简单的步骤找到好的在线资源,因此就在这里。

回答by Tom H

  1. Download ODBCngand install it
  2. Set up a System DNS that connects to your PostgreSQL server. I named mine POSTGRESQL, which is used in the next couple of steps
  3. Run the following code in SSMS to create the linked server. This assumes a PostgreSQL instance on the local machine (hence localhost):

    EXEC master.dbo.sp_addlinkedserver @server = N'POSTGRESQL', @srvproduct=N'Microsoft OLE DB Provider for ODBC Driver', @provider=N'MSDASQL', @datasrc='PostgreSQL', @location='localhost', @catalog='public'

  4. Run the following code in SSMS to create a login mapping for the linked server:

    EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'POSTGRESQL', @useself=N'False', @locallogin=NULL, @rmtuser='', @rmtpassword=''

  5. Issue statements such as:

    SELECT * FROM OpenQuery(POSTGRESQL, 'select my_column from my_table limit 10')

  1. 下载ODBCng并安装它
  2. 设置连接到 PostgreSQL 服务器的系统 DNS。我将我的 POSTGRESQL 命名为,在接下来的几个步骤中使用
  3. 在 SSMS 中运行以下代码以创建链接服务器。这假设本地机器上有一个 PostgreSQL 实例(因此是 localhost):

    EXEC master.dbo.sp_addlinkedserver @server = N'POSTGRESQL', @srvproduct=N'Microsoft OLE DB Provider for ODBC Driver', @provider=N'MSDASQL', @datasrc='PostgreSQL', @location='localhost', @catalog='公共'

  4. 在 SSMS 中运行以下代码以创建链接服务器的登录映射:

    EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'POSTGRESQL', @useself=N'False', @locallogin=NULL, @rmtuser='', @rmtpassword=''

  5. 发出声明,例如:

    SELECT * FROM OpenQuery(POSTGRESQL, 'select my_column from my_table limit 10')

I had to use the double-quote

我不得不使用双引号

回答by Tom H

You can use PGNP OLE DB provider for PostgreSQL (pgoledb.com). See example on how to configure Linked Server at http://www.pgoledb.com/forum/viewtopic.php?f=4&t=6).

您可以使用 PGNP OLE DB provider for PostgreSQL (pgoledb.com)。有关如何配置链接服务器的示例,请参见http://www.pgoledb.com/forum/viewtopic.php?f=4&t=6)。

It is very high performance and scalable driver. We use it to work with tens of millions rows tables.

它是非常高性能和可扩展的驱动程序。我们用它来处理数千万行的表。

Regards, Carlos

问候, 卡洛斯