環境
linux centOS 7.4
postgresql 12.2
postgis 2.5
mysql_fdw 1.1
pgrouting 2.6.3
操作步驟
前面寫過一篇postgresql安裝和使用mysql_fdw,但是那篇用的是postgresql9.4,現在該版本已經停止維護了。
所以與時俱進,更新一版postgresql12的安裝方式:
-
postgres下載大全
https://download.postgresql.org/pub/repos/yum/12/redhat/rhel-7-x86_64/ -
在安裝過程中,遇到需要mariadb-devel依賴。但是我的centerOS7.4版本中,裝了mysql5.6,一直提示mariadb-devel被已安裝的mysql-community-devel取代,單獨卸載mysql-community-devel也沒有用。

-
后來只能把mysql全部刪除了:
-
1)首先停用mysql:
service mysqld stop -
2)查看mysql所有安裝的包:
[root@localhost~]# rpm -qa | grep mysql

-
3)逐個卸載:
[root@localhost ~]# rpm -e mysql-community-release-el6-5.noarch //這里寫你自己的
[root@localhost~]# rpm -e --nodeps mysql包

-
4)檢查是否卸載干凈:

-
-
安裝mysql_fdw
yum是個好東西,只是mysql_fdw的資源很難找,現在我們有鏈接了就可以直接yum安裝了。
[root@localhost ~]# yum install mysql_fdw_12-2.5.3-1.rhel7.x86_64.rpm //會資源找不到
改用以下方法:
[root@localhost ~]# yum install https://download.postgresql.org/pub/repos/yum/12/redhat/rhel-7-x86_64/mysql_fdw_12-2.5.3-1.rhel7.x86_64.rpm
(這里雖然安裝成功,但是有警告。是否有問題,留待后面考證)

-
安裝PgRouting
[root@localhost ~]# yum install pgrouting_12(12是我裝的postgresql的版本)
這里遇到一個問題,pgrouting安裝時會檢測postgis的依賴。yum安裝,目前版本是pgrouting3.0,而pgrouting3.0依賴postgis3.0,與之前我們裝的postgis版本不一致,會報錯。所以這里安裝還是固定版本2.6.3
[root@localhost ~]# yum install https://download.postgresql.org/pub/repos/yum/12/redhat/rhel-7-x86_64/pgrouting_12-2.6.3-1.rhel7.x86_64.rpm
- 安裝完成后,檢查環境
gw_iocs=# \dx

功能記錄
Iocs_dispatch命令記錄:
1、 postgres=# create database gw_iocs owner postgres;
CREATE DATABASE
2、 postgres=# grant all privileges on database gw_iocs to postgres;
GRANT
3、 postgres=# \c gw_iocs;
您現在已經連接到數據庫 "gw_iocs",用戶 "postgres".
4、 gw_iocs=# create extension postgis;
CREATE EXTENSION
5、 gw_iocs=# create extension mysql_fdw;
CREATE EXTENSION
6、 gw_iocs=# create server iocs_server foreign data wrapper mysql_fdw options (host '10.19..',port '3306');
CREATE SERVER
7、 gw_iocs=# create user mapping for postgres server iocs_server options (username 'root',password '123456');
CREATE USER MAPPING
8、 gw_iocs=# grant usage on foreign server iocs_server to postgres;
GRANT
9、 gw_iocs=# create foreign table f_dispatch_ledger_area(id int,area_name text,parent_id int) server iocs_server options (dbname 'iocs-dispatch',table_name 'dispatch_ledger_area');
CREATE FOREIGN TABLE
10、gw_iocs=# select * from f_dispatch_ledger_area;

