Oracle/DB2/Postgresql/Mysql/Hadoop/Greenplum/Postgres-xl/Mongodb
分类: Mysql/postgreSQL
2011-04-28 13:27:02
If you want to join Oracle tables from PostgreSQL on Debian GNU/Linux, you can use .
Also, you can use PostgreSQL queries to access Oracle tables as local schemas.
At some deployment scenarios, one may have to access Oracle tables transparently using PostgreSQL functions, without installing other language specific libraries.
There is a caveat for this version:
You will need the to convert rpm files to deb files.
You will need to have an Oracle account to download the Oracle Instant Client Basic and Oracle Instant Client Devel rpm files suitable for your Oracle backend version from the vendor site.
At this example, we will use
oracle-instantclient-basic-10.2.0.3-1.i386.rpm
oracle-instantclient-devel-10.2.0.3-1.i386.rpm
Convert *.rpm to *.debThe alien package makes a brute conversion from rpm to deb, without careful checks. You must to test the results on a disposable laboratory machine before deploying at a valuable server.
debian:~# alien --to-deb oracle-instantclient-basic-10.2.0.3-1.i386.rpm debian:~# dpkg --install oracle-instantclient-basic_10.2.0.3-2_i386.deb debian:~# alien --to-deb oracle-instantclient-devel_10.2.0.3-2_i386.rpm debian:~# dpkg --install oracle-instantclient-devel_10.2.0.3-2_i386.debInstall dbi-link and dependenciesThe libaio1 is needed by the oracle programs.
debian:~# apt-get update debian:~# apt-get install libdbd-oracle-perl dbi-link libaio1Configure Oracle Instant Client BasicPrepare the tnsnames.oradebian:~# mkdir -p /usr/lib/oracle/10.2.0.3/client/network/admin/ debian:~# nano /usr/lib/oracle/10.2.0.3/client/network/admin/tnsnames.ora /usr/lib/oracle/10.2.0.3/client/network/admin/tnsnames.oraA very simple example below, adapt it to your Oracle available database service.
your_symbolic_service_name = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (HOST = your_oracle_server_address)(PORT = 1521)) ) (CONNECT_DATA = (SID = your_available_oracle_sid)) )/usr/lib/oracle/10.2.0.3/client/network/admin/sqlnet.oraWe will not use sqlnet.ora at this example. Please read the useful links section at the end of article.
/etc/ld.so.conf.d/oracle.conf/usr/lib/oracle/10.2.0.3/client/libdebian:~# nano /etc/ld.so.conf.d/oracle.conf debian:~# ldconfigConfiguring DBI-Link for PostgreSQL access Oracle tablesThe step for creating the accessor_functions may be lenghty as it downloads all tables informations from the Oracle backend.
Your local schema MUST NOT EXISTS before creating the accessor functions. Read the dbi-link debian package documentation on your disk.
There are paremeters you must edit to your needs, like the oracle server port, and we use an example query.
Notably, the connection string:
'dbi:Oracle:host=your_oracle_server_address;sid=your_available_oracle_sid;port=1521',could be something like:
'dbi:Oracle:user=your_available_oracle_username;host=your_oracle_server_address;sid=your_available_oracle_sid;port=1521',or even could be:
'dbi:Oracle:database=your_oracle_available_database;host=your_oracle_server_address;sid=your_available_oracle_sid;port=1521',It depends on your user access permissions and Oracle configuration files. Be careful with the syntax.
When it enters psql the first time, one must update the pg_settings for the dbi-link too. The sql is at the Debian dbi-link package documentation.
debian:~# su postgres postgres@debian:/root$ createdb teste postgres@debian:/root$ createlang plperlu teste postgres@debian:/root$ psql -d teste -f /usr/share/dbi-link/dbi_link.sql postgres@debian:/root$ psql teste Bem vindo ao psql 8.3.14, o terminal iterativo do PostgreSQL. Digite: \copyright para mostrar termos de distribuição \h para ajuda com comandos SQL \? para ajuda com comandos do psql \g ou terminar com ponto-e-vírgula para executar a consulta \q para sair teste=# UPDATE pg_catalog.pg_settings SET setting = CASE WHEN 'dbi_link' = ANY(string_to_array(setting, ',')) THEN setting ELSE 'dbi_link,' || setting END WHERE name = 'search_path' ; teste=# SELECT make_accessor_functions( 'dbi:Oracle:host=your_oracle_server_address;sid=your_available_oracle_sid;port=1521', 'your_available_oracle_username', 'your_available_oracle_password', '--- AutoCommit: 1 RaiseError: 1 ', NULL, NULL, NULL, 'your_local_schema' ); teste=# \d teste=# select count(*) from your_local_schema."VW_SISCOR_02"; teste=# select count(*) from your_local_schema."VW_LOTACAO"; teste=# select count(*) from your_local_schema."VW_LOTACAO" where "UF" = 'RS'; teste=# \q postgres@debian:/root$ exit exit debian:~# Useful Links