DBIx-HA
view release on metacpan or search on metacpan
lib/DBIx/HA.pm view on Meta::CPAN
This method is called as a static method after database configuration is
done.
At this point, database configuration resides in the I<%DATABASE::conf> hash
that needs to be properly populated. Later revisions of C<DBIx::HA> will
allow the passing of a reference to any configuration hash to I<initialize>.
See a sample %DATABASE::conf in the SYNOPSIS section. That section creates
an entry for the 'test' HA database handle, which is comprised of 3 physical
database handles (prod1, prod2, prod3). 'prod1' is the main handle, while the
other 2 are backup handles.
Add other HA database handles by creating more entries in I<%DATABASE::conf>.
=item connect ( $dbname )
Static method to connect to the HA handle 'dbname'. There must be a valid
entry for $DATABASE::conf{'dbname'}.
Returns a standard DBI database handle.
=item prepare ( $dbh, $sql )
lib/DBIx/HA.pm view on Meta::CPAN
=head1 TIPS AND TECHNIQUES
=over 4
=item load-balancing across read-only servers
It is very simple to load-balance across read-only database servers.
Simply randomize or reorder the 'db_stack' entry in your database
configuration on a per-process basis. This will make each process have
its own set of primary and backup servers.
Obviously you should never do that on a read-write environment with hot
spares as you will be writing to the hot spares without writing to the
primary server. Consider C<DBD::Multiplex> for such an application.
=item manually setting the active datasource without downtime
Under mod_perl you can flip all Apache processes to a specific datasource
by simply modifying the file B<DBIxHA_activedb_$dbname> located in the /log
directory in your Apache installation. Assuming that you are using
B<failoverlevel 'application'>, all processes will switch to the datasource you
( run in 1.139 second using v1.01-cache-2.11-cpan-49f99fa48dc )