Deadpool for PostgreSQL 
Deadpool is a dead simple async pool for connections and objects of any type.
This crate implements a deadpool
manager for tokio-postgres
and also provides a statement
cache by wrapping tokio_postgres::Client
and tokio_postgres::Transaction
.
Features
Feature | Description | Extra dependencies | Default |
---|---|---|---|
config |
Enable support for config crate | config , serde/derive |
yes |
Example
use ;
use ;
async
Example with config
and dotenv
crate
# .env
PG.DBNAME=deadpool
use ;
use dotenv;
use Deserialize;
use ;
async
Note: The code above uses the crate name config_crate
because of the
config
feature and both features and dependencies share the same namespace.
In your own code you will probably want to use ::config::ConfigError
and
::config::Config
instead.
Example using an existing tokio_postgres::Config
object
use env;
use ;
use ;
async
FAQ
-
The database is unreachable. Why does the pool creation not fail?
Deadpool has identical startup and runtime behaviour and therefore the pool creation will never fail.
If you want your application to crash on startup if no database connection can be established just call
pool.get().await
right after creating the pool. -
Why are connections retrieved from the pool sometimes unuseable?
In deadpool-postgres
0.5.5
a new recycling method was implemented which will become the default in0.6
. With that recycling method the manager no longer performs a test query prior returning the connection but relies solely ontokio_postgres::Client::is_closed
instead. Under some rare circumstances (e.g. unreliable networks) this can lead totokio_postgres
not noticing a disconnect and reporting the connection as useable.The old and slightly slower recycling method can be enabled by setting
ManagerConfig::recycling_method
toRecyclingMethod::Verified
or when using theconfig
crate by settingPG.MANAGER.RECYCLING_METHOD=Verified
.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.