Medic.Checks.Postgres (Medic v2.0.2)
View SourceChecks that Postgres is running, and is set up correctly.
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
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.
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.
Functions
@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 directoryremedy: the remedy as a stringusername: username to use when calling psql
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"]}
Checks that the running Postgres database matches the version defined
in ASDF's .tool-versions file.
Options:
remedy: the remedy as a string
Checks that the named database exists in the running Postgres instance.
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"]}
@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
{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 stringusername: username to use when calling psql