View Source Electric.Connection.Manager (electric v0.9.5)

Custom initialisation and reconnection logic for database connections.

This module is esentially a supervisor for database connections, implemented as a GenServer. Unlike an OTP process supervisor, it includes additional functionality:

  • adjusting connection options based on the response from the database
  • monitoring connections and initiating a reconnection procedure
  • custom reconnection logic with exponential backoff
  • starting the shape consumer supervisor tree once a database connection pool has been initialized

Your OTP application should start a singleton connection manager under its main supervision tree:

children = [
  ...,
  {Electric.Connection.Manager,
   stack_id: ...,
   connection_opts: [...],
   replication_opts: [...],
   pool_opts: [...],
   timeline_opts: [...],
   shape_cache_opts: [...]}
]

Supervisor.start_link(children, strategy: :one_for_one)

Summary

Functions

Only returns once the status is :active. If the status is alredy active it returns immediately. This is useful if you need to the connection pool to be running before proceeding.

Returns a specification to start this module under a supervisor.

Returns the version of the PostgreSQL server.

Returns the status of the connection manager.

Types

@type option() ::
  {:stack_id, atom() | String.t()}
  | {:connection_opts, Keyword.t()}
  | {:replication_opts, Keyword.t()}
  | {:pool_opts, Keyword.t()}
  | {:timeline_opts, Keyword.t()}
  | {:shape_cache_opts, Keyword.t()}
@type options() :: [option()]
@type status() :: :waiting | :starting | :active

Functions

@spec await_active(GenServer.server()) :: :ok

Only returns once the status is :active. If the status is alredy active it returns immediately. This is useful if you need to the connection pool to be running before proceeding.

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

drop_replication_slot_on_stop(server)

View Source
Link to this function

exclusive_connection_lock_acquired(server)

View Source
@spec get_pg_version(GenServer.server()) :: integer()

Returns the version of the PostgreSQL server.

@spec get_status(GenServer.server()) :: status()

Returns the status of the connection manager.

Link to this function

pg_info_looked_up(server, pg_info)

View Source
Link to this function

report_retained_wal_size(server)

View Source
@spec start_link(options()) :: GenServer.on_start()