• 南大通用数据库-Gbase-8a-学习-11-Oracle通过Dblink访问Gbase8a


    一、测试环境

    名称
    cpuIntel® Core™ i5-1035G1 CPU @ 1.00GHz
    操作系统CentOS Linux release 7.9.2009 (Core)
    内存4G
    逻辑核数3
    Gbase-8a节点1-IP192.168.142.10
    Gbase-8a节点2-IP192.168.142.11
    Oracle节点1-IP192.168.142.11
    Gbase-8a数据库版本8.6.2.43-R33.132743
    Oracle数据库版本Release 11.2.0.1.0 Production
    unixODBC版本2.3.4

    二、测试步骤

    1、查看是否安装Oracle网关

    默认安装的。

    [root@xdw1 ~]# su - oracle
    上一次登录:二 816 09:14:39 CST 2022pts/3 上
    
    [oracle@xdw1 ~]$  dg4odbc
    
    
    Oracle Corporation --- TUESDAY   AUG 16 2022 09:31:12.030
    
    Heterogeneous Agent Release 11.2.0.1.0 - 64bit Production  Built with
       Oracle Database Gateway for ODBC
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    2、安装unixODBC

    相关安装包下载可以参考之前写的一篇文章Postgresql学习02-配置ODBC数据源

    (1)解压

    [root@xdw1 pkg]# tar -xvf unixODBC-2.3.4.tar.gz
    
    • 1

    (2)编译安装

    [root@xdw1 unixODBC-2.3.4]# ./configure --prefix=/usr/local/unixODBC-2.3.4 --includedir=/usr/include --libdir=/usr/lib -bindir=/usr/bin --sysconfdir=/etc
    
    [root@xdw1 unixODBC-2.3.4]# make -j 3
    
    [root@xdw1 unixODBC-2.3.4]# make install
    
    • 1
    • 2
    • 3
    • 4
    • 5

    (3)查看unixodbc是否安装成功

    [root@xdw1 unixODBC-2.3.4]# odbcinst -j
    unixODBC 2.3.4
    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    (4)配置ODBC环境变量

    /etc/profile文件末尾添加如下两行。

    export ODBCSYSINI=/etc
    export ODBCINI=/etc/odbc.ini
    
    • 1
    • 2

    添加完source一下这个文件,让环境变量在当前会话生效。

    [root@xdw1 unixODBC-2.3.4]# source /etc/profile
    
    • 1

    3、配置相关文件

    (1)odbcinst.ini

    我的libgsodbc8.so动态库放在/opt/pkg下,需要和官网申请。

    [root@xdw1 unixODBC-2.3.4]# cat /etc/odbcinst.ini 
    [GBaseODBCDriver]
    Driver=/opt/pkg/libgsodbc8.so
    UsageCount=1
    DontDLClose=1
    Threading=0
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    (2)odbc.ini

    [root@xdw1 unixODBC-2.3.4]# cat /etc/odbc.ini
    [gbase8a]
    Description=ODBC
    Driver=GBaseODBCDriver
    Server=192.168.142.10
    Port=5258
    UID=czg
    Password=qwer1234
    Database=czg
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    4、测试数据源配置是否正常

    [root@xdw1 unixODBC-2.3.4]# su - oracle
    上一次登录:二 816 09:31:10 CST 2022pts/3 上
    
    [oracle@xdw1 ~]$ isql gbase8a -v
    +---------------------------------------+
    | Connected!                            |
    |                                       |
    | sql-statement                         |
    | help [tablename]                      |
    | quit                                  |
    |                                       |
    +---------------------------------------+
    
    SQL> select version();
    +--------------------+
    | version()          |
    +--------------------+
    | 8.6.2.43-R33.132743|
    +--------------------+
    SQLRowCount returns 1
    1 rows fetched
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    5、配置tnsnames.ora文件

    tnsnames.ora添加如下内容:

    gbase8a =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.142.11)(PORT = 1521))
        (CONNECT_DATA =
          (SERVER = DEDICATED)
          (SERVICE_NAME = gbase8a)
        )
     (HS = OK)
      )
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    完整内容如下:

    [oracle@xdw1 admin]$ pwd
    /u01/app/oracle/product/11.2.0/network/admin
    
    [oracle@xdw1 admin]$ cat tnsnames.ora 
    # tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/network/admin/tnsnames.ora
    # Generated by Oracle configuration tools.
    
    ORCL =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.142.11)(PORT = 1521))
        (CONNECT_DATA =
          (SERVER = DEDICATED)
          (SERVICE_NAME = orcl)
        )
      )
    
    gbase8a =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.142.11)(PORT = 1521))
        (CONNECT_DATA =
          (SERVER = DEDICATED)
          (SERVICE_NAME = gbase8a)
        )
     (HS = OK)
      )
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25

    6、配置listener.ora文件

    listener.ora添加如下内容:

      (SID_DESC =
      (SID_NAME = gbase8a)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0)
      (PROGRAM = dg4odbc)
    
    • 1
    • 2
    • 3
    • 4

    完整内容如下:

    [oracle@xdw1 admin]$ pwd
    /u01/app/oracle/product/11.2.0/network/admin
    
    [oracle@xdw1 admin]$ echo $ORACLE_HOME
    /u01/app/oracle/product/11.2.0
    
    [oracle@xdw1 admin]$ cat listener.ora 
    # listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/network/admin/listener.ora
    # Generated by Oracle configuration tools.
    
    LISTENER =
      (DESCRIPTION_LIST =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
          (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.142.11)(PORT = 1521))
        )
      )
    
    ADR_BASE_LISTENER = /u01/app/oracle
    
    SID_LIST_LISTENER =  
    (SID_LIST =  
      (SID_DESC =  
      (GLOBAL_DBNAME = orcl)
      (SID_NAME = orcl)
      )
      (SID_DESC =
      (SID_NAME = gbase8a)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0) 
      (PROGRAM = dg4odbc)
      )
    )
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    7、配置initgbase8a.ora文件

    [oracle@xdw1 admin]$ pwd
    /u01/app/oracle/product/11.2.0/hs/admin
    
    [oracle@xdw1 admin]$ cat initgbase8a.ora
    HS_FDS_CONNECT_INFO = gbase8a
    HS_FDS_TRACE_LEVEL = 0
    HS_FDS_SHAREABLE_NAME=/usr/lib64/libodbc.so
    HS_FDS_SUPPORT_STATISTICS=FALSE
    HS_LANGUAGE=AMERICAN_AMERICA.WE8ISO8859P15
    set ODBCINI=/etc/odbc.ini
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    8、监听重载

    [oracle@xdw1 admin]$ lsnrctl reload
    
    LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 16-AUG-2022 14:48:41
    
    Copyright (c) 1991, 2009, Oracle.  All rights reserved.
    
    Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
    The command completed successfully
    
    [oracle@xdw1 admin]$ lsnrctl status
    
    LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 16-AUG-2022 14:48:47
    
    Copyright (c) 1991, 2009, Oracle.  All rights reserved.
    
    Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
    STATUS of the LISTENER
    ------------------------
    Alias                     LISTENER
    Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
    Start Date                15-AUG-2022 14:42:47
    Uptime                    1 days 0 hr. 5 min. 59 sec
    Trace Level               off
    Security                  ON: Local OS Authentication
    SNMP                      OFF
    Listener Parameter File   /u01/app/oracle/product/11.2.0/network/admin/listener.ora
    Listener Log File         /u01/app/oracle/diag/tnslsnr/xdw1/listener/alert/log.xml
    Listening Endpoints Summary...
      (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
      (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.142.11)(PORT=1521)))
    Services Summary...
    Service "gbase8a" has 1 instance(s).
      Instance "gbase8a", status UNKNOWN, has 1 handler(s) for this service...
    Service "orcl" has 1 instance(s).
      Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
    The command completed successfully
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36

    9、Oracle创建Dblink

    [oracle@xdw1 admin]$ sqlplus / as sysdba
    
    SQL*Plus: Release 11.2.0.1.0 Production on Tue Aug 16 14:11:27 2022
    
    Copyright (c) 1982, 2009, Oracle.  All rights reserved.
    
    
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    
    SQL> conn czg/qwer1234
    Connected.
    
    SQL>  create public database link gbase8a connect to "czg" identified by "qwer1234" using 'gbase8a';
    
    Database link created.
    
    SQL> select * from czg@gbase8a;
    
    	 a b
    ---------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    	 2 zxj
    	 1 czg
    
    SQL> 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    10、Gbase8a中验证

    gbase> select * from czg.czg;
    +------+------+
    | a    | b    |
    +------+------+
    |    2 | zxj  |
    |    1 | czg  |
    +------+------+
    2 rows in set (Elapsed: 00:00:00.17)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
  • 相关阅读:
    Redis学习(三)之 分布式锁详解
    网络安全(黑客)—-2024自学手册
    B样条插值:Python实现给定一些坐标,在这些坐标中间插入一些坐标,使得它们更连贯
    9.03 Day45---搭建Vue开发环境,NPM工具使用,Vue工程创建,启动,打包,部署
    Windows 下 Sublime Text 2.0.2 下载及配置
    Qt5和Qt6的区别
    单片机——硬件系统
    区块链技术的飞跃: 2023年的数字革命
    08.23递归 以及python算法(快排,冒泡,选择)
    智慧用电监控装置:引领0.4kV安全用电新时代
  • 原文地址:https://blog.csdn.net/qq_45111959/article/details/126359175