common_rates.limiters.postgres
The PostgreSQL backend, through common-db: every process sharing the database shares the count.
One row per scope holds its state as JSON. A reservation is one short transaction on common-db’s async pool: an advisory lock on the scope, the row and the server’s clock read under it, the decision run, the row written, the lock released with the commit. The clock is always the server’s, so two processes never disagree on now.
Classes
PostgresLimiter
Bases: BaseLimiter
Shared state in one PostgreSQL table, reached through common-db’s DBClient.
Carried state: the base’s, the config, the client and whether it is owned.
An owned client is built from the config’s connection and pool at open and
closed at close; a borrowed one is used as given and left open. Opening
proves the server answers; initialize() creates the schema and table
explicitly. Reads never create or migrate.
__init__
def __init__(config: PostgresLimiterConfig | Mapping[str, object] | None = None, *, db: DBClient | None = None) -> NoneFields and properties declared here; inherited members belong to the bases above.
BACKEND
BACKEND: str = 'postgres'db
Read-only property.
db: DBClient | NoneThe common-db client behind this limiter; None before an owned one is opened.
owns_db
Read-only property.
owns_db: booltable
Read-only property.
table: strinitialize
async def initialize() -> NoneCreate the schema and the table when absent. Explicit, never on read.