Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 99FBB6336BA for ; Mon, 23 Feb 2009 16:30:44 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 34560-04 for ; Mon, 23 Feb 2009 16:30:40 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from vms173017pub.verizon.net (vms173017pub.verizon.net [206.46.173.17]) by mail.postgresql.org (Postfix) with ESMTP id 00BB063315D for ; Mon, 23 Feb 2009 16:30:40 -0400 (AST) Received: from ridley.home ([173.67.16.250]) by vms173017.mailsrvcs.net (Sun Java(tm) System Messaging Server 6.3-7.04 (built Sep 26 2008; 32bit)) with ESMTPA id <0KFJ00M62CYK1HWV@vms173017.mailsrvcs.net> for pgsql-admin@postgresql.org; Mon, 23 Feb 2009 14:30:20 -0600 (CST) From: Robert Treat To: pgsql-admin@postgresql.org Subject: Re: Problem With using PERL::DBI in plperlu function Date: Mon, 23 Feb 2009 15:30:19 -0500 User-Agent: KMail/1.9.10 Cc: Pawel Socha , Tomasz Olszak References: <57da2175.1ad3af61.49a26c33.ce91@o2.pl> In-reply-to: MIME-version: 1.0 Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7bit Content-disposition: inline Message-id: <200902231530.19579.xzilla@users.sourceforge.net> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200902/198 X-Sequence-Number: 31419 On Monday 23 February 2009 06:24:26 Pawel Socha wrote: > 2009/2/23 Tomasz Olszak : > > Greetings! > > > > First, sorry for my english. > > > > Postgresql 8.2 is installed on Suse. > > I want to connect from postgres plperlu function with oracle and import > > some data from time to time. PGAgent will execute this function every X > > minutes. > > > > Code: > > > > I've written simple script for example: > > #!/usr/bin/perl > > > > use strict; > > use DBI; > > my $query="select 1 from dual"; > > $dbh =DBI->connect("dbi:Oracle:tns_alias","user","pass")|| > > die "Database connection not made: $DBI::errstr"; > > > > my $sth = $dbh->prepare( $query, {ora_check_sql => 0} ); > > $sth->execute(); > > my $tmp; > > $sth->bind_columns( undef, \$tmp); > > if ( $sth->fetch() ) > > print "value from oracle:$tmp"; > > else > > print "can't fetch from oracle"; > > > > I execute this script from postgres user on linux and it's working. > > Connection with oracle is made using tnsnames.ora etc. > > When I write this script like a postgresql plperlu function it have > > problem with tnsnames. > > Code: > > > > CREATE OR REPLACE FUNCTION connect_ora() > > RETURNS void AS > > $BODY$ > > use strict; > > use DBI; > > > > my $query="select 1 from dual"; > > > > elog WARNING,$ENV{LD_LIBRARY_PATH}; > > elog WARNING,$ENV{PATH}; > > elog WARNING,$ENV{USER}; > > elog WARNING,$ENV{TNS_ADMIN}; > > elog WARNING,$ENV{ORACLE_SID}; > > elog WARNING,$ENV{ORACLE_BASE}; > > elog WARNING,$ENV{ORACLE_HOME}; > > $dbh =DBI->connect("dbi:Oracle:tns_alias","user","pass",{ RaiseError => > > 0, AutoCommit => 0, ora_envhp=> 0 }) > > > > || elog ERROR, $DBI::errstr; > > > > my $sth = $dbh->prepare( $query, {ora_check_sql => 0} ); > > $sth->execute(); > > my $tmp; > > $sth->bind_columns( undef, \$tmp); > > if ( $sth->fetch() ) > > elog WARNING, "value from oracle:$tmp"; > > else > > elog ERROR, "can't fetch from oracle"; > > $BODY$ > > LANGUAGE 'plperlu' VOLATILE; > > > > When i execute this plperlu function I get following error: > > > > NOTICE: DBI connect('tns_test','user',...) failed: ORA-12154: TNS:could > > not resolve the connect identifier specified (DBD ERROR: OCIServerAttach) > > at line 19 > > > > > > ERROR: error from Perl function: ORA-12154: TNS:could not resolve the > > connect identifier specified (DBD ERROR: OCIServerAttach) at line 19. > > > > I'm printing notices (as you see) i this function showing values of > > environment variables. They are the same as variables in postgres user on > > linux. > > > > Any idea what am i doing wrong? > > > > I'm thankful for any of Your help. > > check $ORA_HOME > and settings in tnsnames.ora in $ORA_HOME dir. > > Or try connect by host,port and SID. > > :) > There is a bug somewhere in the plperlu <-> oracle dbi stack (most likely in the oracle dbd driver, but that just a guess) that prevents these type of connections from work from a non-local connection, specifically due to lack of environment variable sanity. We spent quite a bit of time trying to figure this out a few years ago, but to no avail, so generally my answer on this is "you can't do that", but by all means feel free to dig in and post if you find a way to make it work (I'm hopeful that newer versions of the software involved might work, but haven't had any luck in the combinations I've tested so far). -- Robert Treat Conjecture: http://www.xzilla.net Consulting: http://www.omniti.com