Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 5451D6354E3 for ; Mon, 23 Feb 2009 07:24:33 -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 00795-01 for ; Mon, 23 Feb 2009 07:24:29 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-bw0-f170.google.com (mail-bw0-f170.google.com [209.85.218.170]) by mail.postgresql.org (Postfix) with ESMTP id 6194E6354B4 for ; Mon, 23 Feb 2009 07:24:29 -0400 (AST) Received: by bwz18 with SMTP id 18so6114115bwz.19 for ; Mon, 23 Feb 2009 03:24:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=m1JOjlRn3W81a/8aaOC4u9RghcxpRVuJ5t3fAyOmq6w=; b=dsdY6IXhHiEpaEkqDJWo++/SGaiMt/NKKT+Sp4MYZbjEh9eS4ZoKGLlXcnrG3vHasM TKyQK/T+/IjHwZkh6XOTJPAkaqH2ohzowqpnlkXZdQw7jccmBzFzb2o9yaDD1UPWdFz7 0uQFqNnNsqeoRCuwSJR+VzebV75Qu6+wTcxu4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=Rha12Iwg1gh8hcASjxAzvQbAf6V4NrTMbBUUOr9j/Plf8nudgG4LpclDTep0g88sHQ Ft/E7gvd6D2Zv9P+TK4mWH9XWF9Uh98qha7CGakQ5V7gRYiAvFblwnlU60VMeT9jLm/k fiY5HQMuIsvNClcZKM8b3wQU0iENjqExVU7N4= MIME-Version: 1.0 Received: by 10.223.112.130 with SMTP id w2mr4690412fap.65.1235388267041; Mon, 23 Feb 2009 03:24:27 -0800 (PST) In-Reply-To: <57da2175.1ad3af61.49a26c33.ce91@o2.pl> References: <57da2175.1ad3af61.49a26c33.ce91@o2.pl> Date: Mon, 23 Feb 2009 12:24:26 +0100 Message-ID: Subject: Re: Problem With using PERL::DBI in plperlu function From: Pawel Socha To: Tomasz Olszak Cc: pgsql-admin@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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/193 X-Sequence-Number: 31414 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. :) -- Pawel Socha