Configurando o Oracle Heterogêneos Service
Autor: Mario Leonel Martinez Junior | Publicado: 2014-05-24T11:32:00-04:00

&nbsp; &nbsp; Hoje vamos configurar o acesso a outros bancos de dados com o heterogêneos service do Oracle, com ele podemos fazer o Oracle e o Mysql se comunicarem e realizar consultas para integrar dados.Abaixo uma imagem que mostra o funcionamento desse tipo de conexão.  Antes de mais nada é necessário instalar o driver odbc de conexão para o banco desejado, no nosso caso vamos realizar a configuração para o Postgres. Eu fiz download no site do postgres e como root dentro do diretório descompactado executei:./configuremakemake installCom driver instalado vamos as configurações:-Oracle HSPrecisamos criar um listener ou se já existir um devemos fazer a configuração no listener existente Criar o listener Abaixo as entradas do Listener:# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora# Generated by Oracle configuration tools.db11g =&nbsp; (DESCRIPTION =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (ADDRESS =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (PROTOCOL = TCP)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (HOST = db11g)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (PORT = 2100)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )sid_list_db11g =&nbsp;&nbsp;&nbsp;&nbsp; (SID_LIST =&nbsp;&nbsp;&nbsp;&nbsp; (SID_DESC=&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (SID_NAME=pgdb)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (PROGRAM=dg4odbc)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )&nbsp;&nbsp;&nbsp; )&nbsp;&nbsp;&nbsp; Legendas:Nome do host= dbc11gPorta da conexão = 2100Agora vamos configurar o TnsNames# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora# Generated by Oracle configuration tools.orcl =&nbsp; (DESCRIPTION =&nbsp;&nbsp;&nbsp; (ADDRESS = (PROTOCOL = TCP)(HOST = db11g)(PORT = 1521))&nbsp;&nbsp;&nbsp; (CONNECT_DATA =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (SERVER = DEDICATED)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (SERVICE_NAME = orcl)&nbsp;&nbsp;&nbsp; )&nbsp; )# Configurcao servicos de conexao heterogeniapgdb=&nbsp; (DESCRIPTION=&nbsp;&nbsp;&nbsp; (ADDRESS = (PROTOCOL = TCP)(HOST = db11g)(PORT = 2100))&nbsp;&nbsp;&nbsp; (CONNECT_DATA = (SID=pgdb))&nbsp;&nbsp;&nbsp; (HS=OK)&nbsp; )&nbsp;Legendas:Nome do Banco Oracle= orclNome do Banco PG = pgbd &nbsp;Agora vamos levantar o listener :[oracle@db11g admin]$ lsnrctl start LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 28-APR-2014 10:21:37Copyright (c) 1991, 2011, Oracle.&nbsp; All rights reserved.Starting /u01/app/oracle/product/11.2.0/db_1/bin/tnslsnr: please wait...TNSLSNR for Linux: Version 11.2.0.3.0 - ProductionSystem parameter file is /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.oraLog messages written to /u01/app/oracle/diag/tnslsnr/db11g/db11g/alert/log.xmlListening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db11g)(PORT=2100)))Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=db11g)(PORT=2100)))STATUS of the LISTENER------------------------Alias&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db11gVersion&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TNSLSNR for Linux: Version 11.2.0.3.0 - ProductionStart Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 28-APR-2014 10:21:37Uptime&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 days 0 hr. 0 min. 0 secTrace Level&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; offSecurity&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ON: Local OS AuthenticationSNMP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OFFListener Parameter File&nbsp;&nbsp; /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.oraListener Log File&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /u01/app/oracle/diag/tnslsnr/db11g/db11g/alert/log.xmlListening Endpoints Summary...&nbsp; (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db11g)(PORT=2100)))Services Summary...Service "pgdb" has 1 instance(s).&nbsp; Instance "pgdb", status UNKNOWN, has 1 handler(s) for this service...Service "orcl" has 1 instance(s).&nbsp; Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...The command completed successfully&nbsp;Agora vamos configurar o odbc do linux para usar o driver que instalamos e configurar o data source name (dsn) :[root@db11g ~]# vi /etc/odbcinst.ini# Example driver definitions# See /usr/share/doc/unixODBC*/README.64bit for more information# Use these definitions with the original unixODBC package# Driver from the postgresql-odbc package# Setup from the unixODBC-libs package[PostgreSQL]Description&nbsp;&nbsp;&nbsp;&nbsp; = ODBC for PostgreSQLDriver&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = /usr/local/lib/psqlodbcw.soSetup&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = /usr/lib/libodbcpsqlS.so#Driver64&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = /usr/lib64/psqlodbc.so#Setup64&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = /usr/lib64/libodbcpsqlS.soFileUsage&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 1Edite o arquivo odbc.ini&nbsp; para configurar o dsn:[Data Sources]pgdb = Banco pgdb[pgdb]Driver = PostgreSQLDatabase = pgdbServername = 192.168.1.55Port = 5411Username = admPassword = admReadOnly = YesVarMaxAsLong = NoAgora com tudo quase pronto , vamos criar o arquivo de configuração do hs no Oracle:Crie o arquivo /u01/app/oracle/product/11.2.0/db_1/hs/admin/initpgdb.oraHS_FDS_CONNECT_INFO = pgdbHS_FDS_TRACE_LEVEL = ONHS_FDS_MAP_NCHAR=FALSEHS_KEEP_REMOTE_COLUMN_SIZE=ALLHS_LANGUAGE=american_america.WE8ISO8859P1HS_FDS_DEFAULT_OWNER=postgresqlHS_FDS_SHAREABLE_NAME = /usr/local/lib/psqlodbcw.soHS_FDS_SUPPORT_STATISTICS = FALSEHS_FDS_SQLLEN_INTERPRETATION=32HS_TRANSACTION_MODEL=READ_ONLY_AUTOCOMMITHS_FDS_REPORT_REAL_AS_DOUBLE = TRUEHS_NLS_LENGTH_SEMANTICS=CHARset ODBCINI=/etc/odbc.iniset ODBCINSTINI=/etc/odbcinst.iniAqui temos varias informações tais como idioma, driver a ser utilizado, a base a ser acessada etc…Agora so precisamos criar um dblink no Oracle Utilizar a conexão heterogênea:create database link pgdb&nbsp; connect to adm&nbsp; using 'pgdb';Agora podemos realizar uma consulta no banco remoto:select * from teste@pgdb ;Isso é realmente muito útil em empresas que utilizam bases mistas e muitas vezes tem a necessidade de realizar a integração destes dados no intuito de dar suporte a tomada de decisões .