bug with {Name}, DBD::Pg and DBIx::HA

Mark Stosberg <mark-WmyhgDpj2fCHT8/[email protected]>
Newsgroups gmane.comp.db.postgresql.dbdpg
Message-ID <[email protected]>
I'm trying out DBIx::HA with DBD::Pg. DBIx::HA is intended to help with
high availability, load-balancing and failover.

I noticed a bug when using it with DBD::Pg 1.49. Looking into it
further, I think it could be considered a bug in DBD::Pg.

DBIx::HA builds a look-up table of several connection strings before any
connections are made.

Later, when it needs to use a new database connection, it constructs a
the DSN like this:

 my $dsn = 'dbi:'.$dbh->{Driver}->{Name}.':'.$dbh->{Name};

This fails with PostgreSQL, because the original lookup hash uses

"dbname=my_db"

but later $dbh->{Name} returned by DBD::Pg contains just "my_db".

I referenced the DBI docs to see what the standard says about this
value. It says:

 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.

Based on that, I think the assumption in DBIx::HA is reasonable.
Further, I think there is no other way to solve the issue reliably in
DBIx::HA in a driver-independent way, without connecting to all the data
sources first, which misses the point of only failing over as needed.

    Mark
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.