PostgreSQL外部表应用

本文介绍了在PostgreSQL 9.x及以上版本中,如何利用tds_fdw扩展连接到MS SQL Server,创建外部表,实现数据的实时同步。详细步骤包括安装EPEL repository、FreeTDS、PostgreSQL开发包,安装tds_fdw扩展,创建包装类和映射,以及建立和使用外部表。示例中展示了将SQL Server的student表映射到PostgreSQL,并在PostgreSQL中创建新表new_student进行数据迁移。
摘要由CSDN通过智能技术生成

Postgresql连接查询 MS SQL Server

简介

PostgreSQL从9.x开始支持所谓的外表的功能,就是在PostgreSQL中通过安装一些扩展再进行一些配置可以在本地建立一个外表映射到其他不同类型的数据库。
今天我们介绍一下在PostgreSQL中通过tds_fdw扩展来映射Sqlserver数据库的方法

环境

  • Sqlserver:
操作系统:Windows 8
数据库系统: MS SQL Server 2012
IP: 192.168.3.215
port: 1433
  • PostgreSQL:
操作系统:CentOS Linux release 7.3.1611 (Core)
数据库系统: PostgreSQL 9.5.8
IP: 192.168.230.134
port: 5432

PostgreSQL端插件安装

  • 安装EPEL repository
sudo yum install epel-release

输出:

[root@localhost ~]# sudo yum install epel-release
Loaded plugins: fastestmirror, langpacks
base                                                             | 3.6 kB  00:00:00     
extras                                                           | 3.4 kB  00:00:00     
pgdg95                                                           | 4.1 kB  00:00:00     
updates                                                          | 3.4 kB  00:00:00     
pgdg95/7/x86_64/primary_db                                       | 163 kB  00:00:02     
Loading mirror speeds from cached hostfile
 * base: mirrors.sohu.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-9 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================
 Package                  Arch               Version           Repository          Size
========================================================================================
Installing:
 epel-release             noarch             7-9               extras              14 k

Transaction Summary
========================================================================================
Install  1 Package

Total download size: 14 k
Installed size: 24 k
Is this ok [y/d/N]: y
Downloading packages:
epel-release-7-9.noarch.rpm                                      |  14 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : epel-release-7-9.noarch                                              1/1 
  Verifying  : epel-release-7-9.noarch                                              1/1 

Installed:
  epel-release.noarch 0:7-9                                                             

Complete!
  • 安装FreeTDS
sudo yum install freetds freetds-devel

输出:

[root@localhost ~]# sudo yum install freetds freetds-devel
Loaded plugins: fastestmirror, langpacks
epel/x86_64/metalink                                             | 6.5 kB  00:00:00     
epel                                                             | 4.3 kB  00:00:00     
(1/3): epel/x86_64/group_gz                                      | 170 kB  00:00:00     
(2/3): epel/x86_64/updateinfo                                    | 817 kB  00:00:01     
(3/3): epel/x86_64/primary_db                                    | 4.8 MB  00:00:01     
Loading mirror speeds from cached hostfile
 * base: mirrors.sohu.com
 * epel: mirrors.ustc.edu.cn
 * extras: mirrors.163.com
 * updates: mirrors.163.com
Resolving Dependencies
--> Running transaction check
---> Package fre
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值