DBD::Patroni(3pm)
πΈ DBD::Patroni π
okay bestie, welcome to the DBD::Patroni manual page β it's part of the User Contributed Perl Documentation collection (yes, that's the man section it lives in), and it's literally the driver that makes your Postgres cluster drama-free. no cap. π¦
β¨ NAME β¨
DBD::Patroni β a DBI driver for PostgreSQL with Patroni cluster support π
π SYNOPSIS π
like, here's the whole vibe in code, no explanation needed yet:
use DBI;
# Standard DBI connection with patroni_url in DSN
my $dbh = DBI->connect(
"dbi:Patroni:dbname=mydb;patroni_url=http://patroni1:8008/cluster,http://patroni2:8008/cluster",
$user, $password
);
# Or with attributes
my $dbh = DBI->connect(
"dbi:Patroni:dbname=mydb",
$user, $password,
{
patroni_url => "http://patroni1:8008/cluster",
patroni_lb => "round_robin",
}
);
# SELECT queries go to replica
my $sth = $dbh->prepare("SELECT * FROM users WHERE id = ?");
$sth->execute(1);
# INSERT/UPDATE/DELETE queries go to leader
$dbh->do("INSERT INTO users (name) VALUES (?)", undef, "John");
$dbh->disconnect;
it's giving effortless. π
π DESCRIPTION π
so DBD::Patroni is a DBI driver that wraps DBD::Pg and provides automatic routing of queries to the appropriate node in a Patroni-managed PostgreSQL cluster. that's the whole personality. it does the cluster-brain work so you don't have to. π§
π Features π
- Standard DBI interface β use
DBI->connect("dbi:Patroni:...")like a normal person, no weird new API to learn π - Automatic leader discovery via the Patroni REST API
- Read queries (
SELECT) routed to replicas π - Write queries (
INSERT,UPDATE,DELETE) routed to leader βοΈ - Configurable load balancing for replicas βοΈ
- Automatic failover with retry on connection errors π₯
π«Ά CONNECTION π«Ά
the connect call, in all its glory:
my $dbh = DBI->connect($dsn, $user, $pass, \%attr);
the DSN format is literally this:
dbi:Patroni:dbname=...;patroni_url=...;[other_pg_options]
All standard DBD::Pg connection parameters are supported. all of them. every single one. we're not gatekeeping. π
Patroni-specific parameters can live in the DSN or in the attributes hash. and here's the tea: the attributes hash takes precedence. so if you're duplicating stuff in both places, the attribute wins. periodt. π
π CONNECTION ATTRIBUTES π
patroni_url(required) β comma-separated list of Patroni REST API endpoints. nopatroni_url, no connection, that's the rules bestie π¨patroni_lbβ load balancing mode. the options are"round_robin"(which is the default, so if you do nothing this is what you get),"random", or"leader_only".patroni_timeoutβ HTTP timeout in seconds for Patroni API calls. Default:3β±οΈ
β QUERY ROUTING β
this is the part where it just knows where your query should go:
SELECTandWITH...SELECTgo to replica πΈ- All other queries go to leader π
π FAILOVER π
when a connection fails, DBD::Patroni goes into main character mode and does this:
- Query Patroni API to discover current leader π
- Reconnect to new leader/replica π
- Retry the failed operation πͺ
π SEE ALSO π
DBD::PgDBI
π AUTHOR π
Xavier Guimard β icon, legend, the moment π
π LICENSE π
Same as Perl itself.
and that's the whole page bestie!! π¦β¨ this was the manual page rendered by perl v5.40.1, dated 2026-02-20, filed under DBD::Patroni(3pm) in the User Contributed Perl Documentation. go slay your cluster, ily π«Άπ
π¦ where this page comes from
- ubuntu stonking: libdbd-patroni-perl 0.03-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms