EctoCockroachExtras behaviour (ecto_cockroach_extras v0.1.0)

Copy Markdown View Source

CockroachDB cluster and database statistics for Ecto apps.

Mimics the API of ecto_psql_extras, but targets CockroachDB's own introspection surface (SHOW JOBS, SHOW CHANGEFEED JOBS, SHOW STATISTICS, SHOW CLUSTER SETTINGS, crdb_internal.*) instead of PostgreSQL catalogs/extensions that CockroachDB doesn't support.

Usage

EctoCockroachExtras.jobs(MyApp.Repo)
EctoCockroachExtras.table_statistics(MyApp.Repo, "users")
EctoCockroachExtras.query(:cluster_settings, MyApp.Repo, format: :raw)

Summary

Types

repo()

@type repo() :: module()

Callbacks

info()

@callback info() :: map()

query(args)

@callback query(args :: keyword()) :: String.t()

Functions

changefeed_jobs(repo, opts \\ [])

cluster_settings(repo, opts \\ [])

contention(repo, opts \\ [])

diagnose(repo, opts \\ [])

Run a healthcheck report combining several of the above checks.

Accepts opts[:tables] (a list of table name strings) to enable the "stale table statistics" check; without it, that check is reported as skipped.

format_value(arg)

index_sizes(repo, opts \\ [])

index_usage(repo, opts \\ [])

jobs(repo, opts \\ [])

locks(repo, opts \\ [])

queries(repo \\ nil)

@spec queries(repo() | nil) :: map()

Returns all available queries and their implementing modules.

The repo argument is accepted for API parity with ecto_psql_extras and reserved for future CockroachDB-version-conditional query selection; it is currently unused.

query(name, repo, opts \\ [])

@spec query(atom(), repo(), keyword()) :: term()

Runs the query named name on repo, in the given format.

Options

  • :format - :ascii (default) prints a formatted table and returns :ok, :raw returns the underlying %Postgrex.Result{}.
  • :args - overrides the query module's default_args.
  • :query_opts - overrides the default Ecto query options ([log: false, timeout: 30000]).

running_queries(repo, opts \\ [])

sessions(repo, opts \\ [])

table_sizes(repo, opts \\ [])

table_statistics(repo, table_name, opts \\ [])

top_queries(repo, opts \\ [])

unused_indexes(repo, opts \\ [])