PosgreSQL client component. More...
#include <userver/storages/postgres/component.hpp>
Public Member Functions | |
Postgres (const ComponentConfig &, const ComponentContext &) | |
Component constructor. | |
~Postgres () override | |
Component destructor. | |
storages::postgres::ClusterPtr | GetCluster () const |
Cluster accessor for default shard number. | |
storages::postgres::ClusterPtr | GetClusterForShard (size_t shard) const |
Cluster accessor for specific shard number. | |
size_t | GetShardCount () const |
Get total shard count. | |
storages::postgres::DatabasePtr | GetDatabase () const |
Get database object. | |
void | ExtendStatistics (utils::statistics::Writer &writer) |
Reports statistics for PostgreSQL driver. | |
Public Member Functions inherited from components::LoggableComponentBase | |
LoggableComponentBase (const ComponentConfig &, const ComponentContext &) | |
LoggableComponentBase (LoggableComponentBase &&)=delete | |
LoggableComponentBase (const LoggableComponentBase &)=delete | |
~LoggableComponentBase () override=default | |
ComponentHealth | GetComponentHealth () const override |
void | OnLoadingCancelled () override |
void | OnAllComponentsLoaded () override |
void | OnAllComponentsAreStopping () override |
Static Public Member Functions | |
static yaml_config::Schema | GetStaticConfigSchema () |
Static Public Member Functions inherited from components::LoggableComponentBase | |
static yaml_config::Schema | GetStaticConfigSchema () |
Static Public Attributes | |
static constexpr auto | kDefaultMaxReplicationLag = std::chrono::seconds{60} |
static constexpr size_t | kDefaultShardNumber = 0 |
Default shard number. | |
static constexpr storages::postgres::CommandControl | kDefaultCommandControl |
Default command control. | |
PosgreSQL client component.
Provides access to a PostgreSQL cluster.
You must specify either dbalias
or conn_info
. If the component is configured with an alias, it will lookup connection data in secdist.json
You must specify blocking_task_processor
as well.
max_replication_lag
can be used to tune replication lag limit for replicas. Once the replica lag exceeds this value it will be automatically disabled. Note, however, that client-size lag detection is not precise in nature and can only provide the precision of couple seconds.
A PosgreSQL alias in secdist is described as a JSON array of objects containing a single cluster description. There are two formats of describing a cluster, the first one assigns predefined roles to DSNs, the second one is just a list of DSNs and the Postgres component takes care of discovering the cluster's topology itself.
In predefined roles format the component requires single-host connection strings.
The predefined roles format is deprecated and the support will be removed soon.
In automatic discovery format the connection strings are any valid PostgreSQL connection strings including multi-host ones with the exception of target_session_attrs
which will be ignored.
The shard_number
parameter is required in both formats and must match the index of cluster description object in the alias array.
Please see PostgreSQL documentation on connection strings.
Name | Description | Default value |
---|---|---|
dbalias | name of the database in secdist config (if available) | – |
dbconnection | connection DSN string (used if no dbalias specified) | – |
blocking_task_processor | name of task processor for background blocking operations | – |
max_replication_lag | replication lag limit for usable slaves | 60s |
min_pool_size | number of connections created initially | 4 |
max_pool_size | limit of connections count | 15 |
sync-start | perform initial connections synchronously | false |
dns_resolver | server hostname resolver type (getaddrinfo or async) | 'async' |
persistent-prepared-statements | cache prepared statements or not | true |
user-types-enabled | disabling will disallow use of user-defined types | true |
ignore_unused_query_params | disable check for not-NULL query params that are not used in query | false |
monitoring-dbalias | name of the database for monitorings | calculated from dbalias or dbconnection options |
max_prepared_cache_size | prepared statements cache size limit | 5000 |
max_statement_metrics | limit of exported metrics for named statements | 0 |
min_pool_size | number of connections created initially | 4 |
max_pool_size | maximum number of created connections | 15 |
max_queue_size | maximum number of clients waiting for a connection | 200 |
connecting_limit | limit for concurrent establishing connections number per pool (0 - unlimited) | 0 |
connlimit_mode | max_connections setup mode (manual or auto) | auto |
error-injection | artificial error injection settings, error_injection::Settings | – |
Definition at line 137 of file component.hpp.
|
inline |
Get database object.
Definition at line 163 of file component.hpp.
|
staticconstexpr |
Default command control.
Definition at line 143 of file component.hpp.
|
staticconstexpr |
Definition at line 139 of file component.hpp.
|
staticconstexpr |
Default shard number.
Definition at line 141 of file component.hpp.