in reply to Identify host connected to in DBD::Oracle connection?

I think you can get what you want from the Name attribute. From DBI:

Holds the "name" of the database. Usually (and recommended to be) the same as the "dbi:DriverName:..." string used to connect to the database, but with the leading "dbi:DriverName:" removed.

This can be accessed as:

$handle->{Name}

Update: Does not meet spec -> only accesses local value (see below).

Replies are listed 'Best First'.
Re^2: Identify host connected to in DBD::Oracle connection?
by AlephZarro (Novice) on Sep 28, 2009 at 16:59 UTC
    Hi.

    print "Name: $dbh->{Name}\n"; returns Name: prod_01 which is the database name.

    I'm hoping I might be able to determine the hostname used for the connection (which one of the nine hosts listed in the tnsnames.ora definition was used for this connection).

      That's what I get for reading too fast. How about trying a get_info call on SQL_SERVER_NAME? I've verified the following against an Oracle database I have access to, but not in a multiple hosts/load balance context.

      #!/usr/bin/perl use strict; use warnings; use DBI; use DBI::Const::GetInfoType; my $_db_name = 'host'; my $_db_user = 'name'; my $_db_pass = 'password'; my @_dbi_path = ("dbi:Oracle:$_db_name",$_db_user,$_db_pass); my $handle = DBI->connect( @_dbi_path, { PrintError => 1, RaiseError => 0, AutoCommit => 0 } ); #print join "\n", sort keys %GetInfoType; print $handle->get_info($GetInfoType{SQL_SERVER_NAME});

      See DBI::Const::GetInfoType and get_info in DBI.

      Update: Still no dice -> in DBD::Oracle, this is just a synonym for $handle->{Name}, as is SQL_DATA_SOURCE_NAME.