暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

​Apache Doris ODBC外表数据库主流版本及其ODBC版本对应关系

1303

使用的基础软件环境及版本:

  1. Centos版本:7.9

  2. unixODBC版本:2.3.1

  3. Apache Doris版本:0.15

1.安装unixODBC

yum install unixODBC unixODBC-devel libtool-ltdl libtool-ltdl-devel

安装完成之后执行odbcinst -j
,看到下面信息说明安装成功

#odbcinst -j
unixODBC 2.3.1
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8

2.PostgreSql数据验证及版本对应关系

2.1 PostgreSql安装

安装 yum 源

 yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

安装完成以后我们使用yum search PostgreSQL
搜索可以看到很多版本

postgresql10.x86_64 : PostgreSQL client programs and libraries
postgresql10-contrib.x86_64 : Contributed source and binaries distributed with PostgreSQL
postgresql10-devel.x86_64 : PostgreSQL development header files and libraries
postgresql10-docs.x86_64 : Extra documentation for PostgreSQL
postgresql10-libs.x86_64 : The shared libraries required for any PostgreSQL clients
postgresql10-odbc.x86_64 : PostgreSQL ODBC driver
postgresql10-plperl.x86_64 : The Perl procedural language for PostgreSQL
postgresql10-plpython.x86_64 : The Python procedural language for PostgreSQL
postgresql10-plpython3.x86_64 : The Python3 procedural language for PostgreSQL
postgresql10-pltcl.x86_64 : The Tcl procedural language for PostgreSQL
postgresql10-server.x86_64 : The programs needed to create and run a PostgreSQL server
postgresql10-tcl.x86_64 : A Tcl client library for PostgreSQL
postgresql10-test.x86_64 : The test suite distributed with PostgreSQL
postgresql11.x86_64 : PostgreSQL client programs and libraries
postgresql11-contrib.x86_64 : Contributed source and binaries distributed with PostgreSQL
postgresql11-devel.x86_64 : PostgreSQL development header files and libraries
postgresql11-docs.x86_64 : Extra documentation for PostgreSQL
postgresql11-libs.x86_64 : The shared libraries required for any PostgreSQL clients
postgresql11-llvmjit.x86_64 : Just-in-time compilation support for PostgreSQL
postgresql11-odbc.x86_64 : PostgreSQL ODBC driver
postgresql11-plperl.x86_64 : The Perl procedural language for PostgreSQL
postgresql11-plpython.x86_64 : The Python procedural language for PostgreSQL
postgresql11-plpython3.x86_64 : The Python3 procedural language for PostgreSQL
postgresql11-pltcl.x86_64 : The Tcl procedural language for PostgreSQL
postgresql11-server.x86_64 : The programs needed to create and run a PostgreSQL server
postgresql11-tcl.x86_64 : A Tcl client library for PostgreSQL
postgresql11-test.x86_64 : The test suite distributed with PostgreSQL
postgresql12.x86_64 : PostgreSQL client programs and libraries
postgresql12-contrib.x86_64 : Contributed source and binaries distributed with PostgreSQL
postgresql12-devel.x86_64 : PostgreSQL development header files and libraries
postgresql12-docs.x86_64 : Extra documentation for PostgreSQL
postgresql12-libs.x86_64 : The shared libraries required for any PostgreSQL clients
postgresql12-llvmjit.x86_64 : Just-in-time compilation support for PostgreSQL
postgresql12-odbc.x86_64 : PostgreSQL ODBC driver
postgresql12-odbc-debuginfo.x86_64 : Debug information for package postgresql12-odbc
postgresql12-plperl.x86_64 : The Perl procedural language for PostgreSQL
postgresql12-plpython.x86_64 : The Python procedural language for PostgreSQL
postgresql12-plpython3.x86_64 : The Python3 procedural language for PostgreSQL
postgresql12-pltcl.x86_64 : The Tcl procedural language for PostgreSQL
postgresql12-server.x86_64 : The programs needed to create and run a PostgreSQL server
postgresql12-tcl.x86_64 : A Tcl client library for PostgreSQL
postgresql12-test.x86_64 : The test suite distributed with PostgreSQL
postgresql13.x86_64 : PostgreSQL client programs and libraries
postgresql13-contrib.x86_64 : Contributed source and binaries distributed with PostgreSQL
postgresql13-devel.x86_64 : PostgreSQL development header files and libraries
postgresql13-docs.x86_64 : Extra documentation for PostgreSQL
postgresql13-libs.x86_64 : The shared libraries required for any PostgreSQL clients
postgresql13-llvmjit.x86_64 : Just-in-time compilation support for PostgreSQL
postgresql13-odbc.x86_64 : PostgreSQL ODBC driver
postgresql13-plperl.x86_64 : The Perl procedural language for PostgreSQL
postgresql13-plpython3.x86_64 : The Python3 procedural language for PostgreSQL
postgresql13-pltcl.x86_64 : The Tcl procedural language for PostgreSQL
postgresql13-server.x86_64 : The programs needed to create and run a PostgreSQL server
postgresql13-test.x86_64 : The test suite distributed with PostgreSQL
postgresql14.x86_64 : PostgreSQL client programs and libraries
postgresql14-contrib.x86_64 : Contributed source and binaries distributed with PostgreSQL
postgresql14-devel.x86_64 : PostgreSQL development header files and libraries
postgresql14-docs.x86_64 : Extra documentation for PostgreSQL
postgresql14-libs.x86_64 : The shared libraries required for any PostgreSQL clients
postgresql14-llvmjit.x86_64 : Just-in-time compilation support for PostgreSQL
postgresql14-odbc.x86_64 : PostgreSQL ODBC driver
postgresql14-plperl.x86_64 : The Perl procedural language for PostgreSQL
postgresql14-plpython3.x86_64 : The Python3 procedural language for PostgreSQL
postgresql14-pltcl.x86_64 : The Tcl procedural language for PostgreSQL
postgresql14-server.x86_64 : The programs needed to create and run a PostgreSQL server
postgresql14-tcl.x86_64 : A Tcl client library for PostgreSQL
postgresql14-test.x86_64 : The test suite distributed with PostgreSQL
postgresql96.x86_64 : PostgreSQL client programs and libraries
postgresql96-contrib.x86_64 : Contributed source and binaries distributed with PostgreSQL
postgresql96-devel.x86_64 : PostgreSQL development header files and libraries
postgresql96-docs.x86_64 : Extra documentation for PostgreSQL
postgresql96-libs.x86_64 : The shared libraries required for any PostgreSQL clients
postgresql96-odbc.x86_64 : PostgreSQL ODBC driver
postgresql96-plperl.x86_64 : The Perl procedural language for PostgreSQL
postgresql96-plpython.x86_64 : The Python procedural language for PostgreSQL
postgresql96-plpython3.x86_64 : The Python3 procedural language for PostgreSQL
postgresql96-pltcl.x86_64 : The Tcl procedural language for PostgreSQL
postgresql96-server.x86_64 : The programs needed to create and run a PostgreSQL server
postgresql96-tcl.x86_64 : A Tcl client library for PostgreSQL
postgresql96-test.x86_64 : The test suite distributed with PostgreSQL

这里我们介绍PostgreSQL 12的安装,其他的版本的安装一样

2.1.1 安装PostgreSQL 服务

yum install -y postgresql12 postgresql12-server

2.1.2 初始化数据库

#/usr/pgsql-12/bin/postgresql-12-setup initdb
#Initializing database ... OK

2.1.3 配置远程访问PG

修改postgresql.conf,在 /var/lib/pgsql/12/data/
目录下,编辑或添加下面一行,使PostgreSQL可以接受来自任意IP的连接请求。

listen_addresses = '*'

修改pg_hba.conf,在 /var/lib/pgsql/12/data/
目录下,在pg_hba.conf
中配置服务端允许的认证方式

任意编辑器打开该文件,编辑或添加下面一行。

# TYPE  DATABASE  USER  CIDR-ADDRESS  METHOD
host all all 0.0.0.0/0 md5

默认pg只允许本机通过密码认证登录,修改为上面内容后即可以对任意IP访问进行密码验证

2.1.4 启动服务

#启动PostgreSQL服务
sudo systemctl start postgresql-12

#设置PostgreSQL服务为开机启动
sudo systemctl enable postgresql-12

2.2 使用PostgreSQL和创建用户及数据库

默认情况下,Postgres使用称为“roles”的概念来处理身份验证和授权。在某些方面,这些类似于常规的Unix风格帐户,但Postgres不区分用户和组,而是更喜欢更灵活的术语“roles”。

安装后,Postgres设置为使用ident身份验证,这意味着它将Postgresroles与匹配的Unix / Linux系统帐户相关联。如果Postgres中存在roles,则具有相同名称的Unix / Linux用户名可以作为该roles登录。

安装过程创建了一个名为postgres的用户帐户,该帐户与默认的Postgresroles相关联。要使用Postgres,您可以登录该帐户。

有几种方法可以使用此帐户访问Postgres。

2.2.1 切换到postgres帐户

输入以下内容切换到服务器上的postgres帐户:

$ sudo -i -u postgres

您现在可以通过输入以下内容立即访问Postgres提示:

$ psql

这将使您进入PostgreSQL提示符,从此处您可以立即与数据库管理系统进行交互。

输入以下命令退出PostgreSQL提示符:

postgres=# \q

这将带您回到postgres
Linux命令提示符。

2.2.2 在不切换帐户的情况下访问Postgres

您也可以让postgres帐户用sudo
运行您想要的命令。

例如,在最后一个示例中,您被指示通过首先切换到postgres用户然后运行psql
以打开Postgres提示来进入Postgres提示。您可以通过psql
postgres用户身份运行单个命令来一步完成此操作sudo
,如下所示:

$ sudo -u postgres psql

这将直接登录到Postgres,中间没有中间bash
shell。

同样,您可以通过输入以下内容退出交互式Postgres会话:

postgres=# \q

许多用例需要多个Postgresroles。继续阅读以了解如何配置这些

2.2.3 创建用户,数据库及表

使用默认用户登录postgresql创建用户、创建数据库及完成授权

$ sudo -u postgres psql

创建数据库新用户,如 dbuser:

postgres=# CREATE USER dbuser WITH PASSWORD 'zhangfeng';

注意:

语句要以分号结尾。密码要用单引号括起来。创建用户数据库,你也可以通过你创建的用户登录进去以后创建数据库,如demo:

postgres=# CREATE DATABASE demo OWNER dbuser;

将demo数据库的所有权限都赋予dbuser:

postgres=# GRANT ALL PRIVILEGES ON DATABASE demo TO dbuser;

使用命令 \q 退出psql:

postgres=# \q

创建Linux普通用户,与刚才新建的数据库用户同名,如 dbuser:

$ sudo adduser dbuser
$ sudo passwd dbuser

以dbuser的身份连接数据库exampledb:

$ su - dbuser

Password:
Last login: Wed Mar 1 11:52:07 CST 2017 on pts/

用我们创建的用户(dbuser)登录psql

# sudo -u dbuser psql -U dbuser -d demo
could not change directory to "/root": Permission denied
psql (12.9 (Ubuntu 12.9-0ubuntu0.20.04.1))
Type "help" for help.

demo=> \d
                   List of relations
Schema |           Name            |   Type   | Owner
--------+---------------------------+----------+----------
public | playground                | table    | postgres
public | playground_1              | table    | dbuser
public | playground_1_equip_id_seq | sequence | dbuser
public | playground_equip_id_seq   | sequence | postgres
(4 rows)

创建表及插入数据

CREATE TABLE playground_test_odbc (
  equip_id serial PRIMARY KEY,
  type varchar (50) NOT NULL,
  color varchar (25) NOT NULL,
  location varchar(25) ,
  install_date date
);

示例数据

INSERT INTO playground_test_odbc (type, color, location, install_date) VALUES ('slide', 'blue', 'south', '2017-04-28');
INSERT INTO playground_test_odbc (type, color, location, install_date) VALUES ('swing', 'yellow', 'northwest', '2018-08-16');

执行结果

demo=> CREATE TABLE playground_test_odbc (
demo(>     equip_id serial PRIMARY KEY,
demo(>     type varchar (50) NOT NULL,
demo(>     color varchar (25) NOT NULL,
demo(>     location varchar(25) ,
demo(>     install_date date
demo(> );
CREATE TABLE
demo=> INSERT INTO playground_test_odbc (type, color, location, install_date) VALUES ('slide', 'blue', 'south', '2017-04-28');
INSERT 0 1
demo=> INSERT INTO playground_test_odbc (type, color, location, install_date) VALUES ('swing', 'yellow', 'northwest', '2018-08-16');
INSERT 0 1

2.3 配置ODBC

2.3.1 配置注册Postgresql ODBC驱动

编辑/etc/odbcinst.ini,加入下面的内容

[PostgreSQL]
Description=ODBC for PostgreSQL
Driver=/usr/pgsql-12/lib/psqlodbcw.so
Setup=/usr/pgsql-12/lib/psqlodbcw.so
Setup = /usr/lib64/libodbc.so
Setup64 = /usr/lib64/libodbc.so
FileUsage=1

2.3.2 配置PG 数据源

编辑/etc/odbc.ini

加入下面内容

[postgresql]
Driver = PostgreSQL    ###这里的名称和odbcinst.ini里配置的名称一致
Description = Postgres DSN
Servername = localhost
Database = demo
Username = dbuser
Password = zhangfeng
Port = 5432
ReadOnly = No

其他的是你的Postgresql地址及刚才创建的用户、密码、数据库、端口等

2.3.3 验证是否成功

isql -v postgresql dbuser zhangfeng
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL>

注意这里的PostgresDB是我们在odbc.ini里定义的名称,这里显示ODBC正常

2.4 Apache Doris 验证

2.4.1 修改配置

修改BE节点conf/odbcinst.ini文件,加入刚才/etc/odbcinst.ini添加的一样内容,并删除原先的PostgreSQL配置

[PostgreSQL]
Description=ODBC for PostgreSQL
Driver=/usr/pgsql-12/lib/psqlodbcw.so
Setup=/usr/pgsql-12/lib/psqlodbcw.so
Setup = /usr/lib64/libodbc.so
Setup64 = /usr/lib64/libodbc.so
FileUsage = 1

2.4.2 验证

创建PG ODBC Resource

CREATE EXTERNAL RESOURCE `pg_12`
PROPERTIES (
"host" = "localhost",
"port" = "5432",
"user" = "dbuser",
"password" = "zhangfeng",
"database" = "demo",
"table" = "playground_test_odbc",
"driver" = "PostgreSQL",  
"odbc_type" = "postgresql",
"type" = "odbc_catalog"
);

2.4.3.创建ODBC外表

 CREATE EXTERNAL TABLE `playground_odbc_12` (
  equip_id int NOT NULL,
  type varchar (50) NOT NULL,
  color varchar (25) NOT NULL,
  location varchar(25) ,
  install_date date
) ENGINE=ODBC
COMMENT "ODBC"
PROPERTIES (
"odbc_catalog_resource" = "pg_12",
"database" = "demo",
"table" = "playground_test_odbc"
);

在Doris下执行查询:

ysql> show tables;
+--------------------+
| Tables_in_demo     |
+--------------------+
| playground_odbc_12 |
| test_odbc_5        |
| test_odbc_8        |
| test_odbc_8_0_26   |
| test_odbc_mysql    |
| test_odbc_mysql_8  |
+--------------------+
6 rows in set (0.00 sec)

mysql> select * from playground_odbc_12;
+----------+-------+--------+-----------+--------------+
| equip_id | type  | color  | location  | install_date |
+----------+-------+--------+-----------+--------------+
|        1 | slide | blue   | south     | 2017-04-28   |
|        2 | swing | yellow | northwest | 2018-08-16   |
+----------+-------+--------+-----------+--------------+
2 rows in set (0.01 sec)

OK,一切正常,相对Mysql PG的ODBC驱动更简单一些,只要你的PG版本和ODBC驱动版本对应上问题都不大。

2.5 ODBC驱动版本适配验证结果

以下是PostgreSQL数据库版本和PostgreSQL ODBC驱动版本和Apache Doris版本适配没问题列表

PostgreSQL版本PostgreSQL ODBC版本
12.9postgresql12-odbc-13.02.0000
13.5postgresql13-odbc-13.02.0000
14.1postgresql14-odbc-13.02.0000
9.6.24postgresql96-odbc-13.02.0000
10.6postgresql10-odbc-13.02.0000
11.6postgresql11-odbc-13.02.0000

3.Mysql版本和ODBC驱动版本对应关系

这里Mysql的安装就不在详细介绍了,只给出Mysql常用主流版本和其ODBC的版本对应关系

Mysql版本Mysql ODBC版本
8.0.278.0.27,8.026
5.7.365.3.11,5.3.13
5.6.51  5.3.11,5.3.13
5.5.62  5.3.11,5.3.13

4.Oracle版本和ODBC驱动版本对应关系

Oracle版本Oracle ODBC版本
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Productionoracle-instantclient19.13-odbc-19.13.0.0.0
Oracle Database 12c Standard Edition Release 12.2.0.1.0 - 64bit Productionoracle-instantclient19.13-odbc-19.13.0.0.0
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Productionoracle-instantclient19.13-odbc-19.13.0.0.0
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Productionoracle-instantclient19.13-odbc-19.13.0.0.0
Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Productionoracle-instantclient19.13-odbc-19.13.0.0.0

Oracle ODBC驱动版本下载地址:

https://download.oracle.com/otn_software/linux/instantclient/1913000/oracle-instantclient19.13-sqlplus-19.13.0.0.0-2.x86_64.rpm
https://download.oracle.com/otn_software/linux/instantclient/1913000/oracle-instantclient19.13-devel-19.13.0.0.0-2.x86_64.rpm
https://download.oracle.com/otn_software/linux/instantclient/1913000/oracle-instantclient19.13-odbc-19.13.0.0.0-2.x86_64.rpm
https://download.oracle.com/otn_software/linux/instantclient/1913000/oracle-instantclient19.13-basic-19.13.0.0.0-2.x86_64.rpm


文章转载自 锋哥聊DORIS数仓,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论