# `Electric.Connection.Manager`
[🔗](https://github.com/electric-sql/electric/tree/%40core/sync-service%401.6.2/packages/sync-service/lib/electric/connection/manager.ex#L1)

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 database connection pools
    have been initialized

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

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

    Supervisor.start_link(children, strategy: :one_for_one)

# `option`

```elixir
@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()}
```

# `options`

```elixir
@type options() :: [option()]
```

# `status`

```elixir
@type status() :: :waiting | :starting | :active
```

# `admin_pool`

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `connection_pool_ready`

# `connection_resolver_ready`

# `drop_replication_slot_on_stop`

# `name`

# `pg_info_obtained`

# `pg_system_identified`

# `ping`

# `pool_name`

# `pool_name`

# `pool_sizes`

# `replication_client_created_new_slot`

# `replication_client_lock_acquired`

# `replication_client_lock_acquisition_failed`

# `replication_client_ready_to_stream`

# `replication_client_started`

# `replication_client_streamed_first_message`

# `snapshot_pool`

# `start_link`

```elixir
@spec start_link(options()) :: GenServer.on_start()
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
