View Source Medic.Checks.Postgres (Medic v1.8.8)

Checks that Postgres is running, and is set up correctly.

examples

Examples

{Check.Postgres, :running?},
{Check.Postgres, :correct_version_running?},
{Check.Postgres, :role_exists?},
{Check.Postgres, :correct_data_directory?},
{Check.Postgres, :database_exists?, ["my_db"]}

environment-variables

Environment variables

Medic uses psql in order to connect to Postgres for its checks. When using a non-standard configuration, such as database port, consider setting environment variables such as PGPORT (in .envrc or .envrc.local) to configure psql if possible.

These environment variables are documented in libpq's documentation.

Link to this section Summary

Functions

Checks that the running instance of Postgres has the expected data directory.

Checks that the running Postgres database matches the version defined in ASDF's .tool-versions file.

Checks that the named database exists in the running Postgres instance.

Checks that a user has been created in the running instance. This check defaults to the username postgres if not explicitly given.

Checks whether Postgres is running, by attempting to list all databases.

Link to this section Functions

Link to this function

correct_data_directory?(path_or_opts \\ "./priv/postgres/data")

View Source
@spec correct_data_directory?(Path.t() | list()) :: Medic.Check.check_return_t()

Checks that the running instance of Postgres has the expected data directory.

If run with no arguments, this expects that the data directory is located at ./priv/postgres/data within the current project.

If run with one argument, the argument can be:

  • A path to the data directory, or
  • A keyword list with one or more of the following keys:
    • data_directory: the path to the data directory
    • remedy: the remedy as a string
    • username: username to use when calling psql

usage

Usage

{Medic.Checks.Postgres, :correct_data_directory?}
{Medic.Checks.Postgres, :correct_data_directory?, ["/path/to/data/directory"]}
{Medic.Checks.Postgres, :correct_data_directory?, [data_directory: "/path/to/data/directory", username: "postgres"]}
{Medic.Checks.Postgres, :correct_data_directory?, [data_directory: "/path/to/data/directory", remedy: "bin/dev/db-restart"]}
Link to this function

correct_version_running?(opts \\ [])

View Source

Checks that the running Postgres database matches the version defined in ASDF's .tool-versions file.

Options:

  • remedy: the remedy as a string
Link to this function

database_exists?(database_name, opts \\ [])

View Source

Checks that the named database exists in the running Postgres instance.

usage

Usage

{Medic.Checks.Postgres, :database_exists?, ["my_db_dev"]}
{Medic.Checks.Postgres, :database_exists?, ["my_db_dev", username: "postgres"]}
{Medic.Checks.Postgres, :database_exists?, ["my_db_dev", remedy: "mix ecto.reset"]}
Link to this function

role_exists?(username \\ "postgres")

View Source
@spec role_exists?(binary()) :: Medic.Check.check_return_t()

Checks that a user has been created in the running instance. This check defaults to the username postgres if not explicitly given.

usage

Usage

{Medic.Checks.Postgres, :role_exists?}
{Medic.Checks.Postgres, :role_exists?, ["postgres"]}
@spec running?(list()) :: Medic.Check.check_return_t()

Checks whether Postgres is running, by attempting to list all databases.

Options:

  • remedy: the remedy as a string
  • username: username to use when calling psql