dbcritic finds problems in a database schema.
To run dbcritic, set the environment variables expected by libpq. Then invoke dbcritic with no arguments. For instance:
$ export PGHOST=localhost
$ export PGPORT=5432
$ export PGUSER=myuser
$ export PGDATABASE=mydatabase
$ dbcritic
dbcritic can be build with Nix or without Nix. To build it with Nix, simply invoke nix-build:
$ nix-build
To build it without Nix, first make sure you have installed Idris and libpq. Then invoke make:
$ make
dbcritic connects to a PostgreSQL database using the specified parameters. It then performs a series of checks and reports discovered issues. Issues may result from the cluster configuration or from the database schema.
dbcritic implements the following checks:
Check | Description |
---|---|
index_fk_ref | Check that foreign key has an index on the referencing side. |
primary_key | Check that each table has a primary key constraint. |
timestamptz | Check that columns are of type ‘timestamptz’ rather than of type ‘timestamp’. |
time_zone | Check that the ‘TimeZone’ parameter is set to a sensible value. |
dbcritic can be configured with a file .dbcriticrc in the working directory.
dbcritic will ignore any empty lines and comment lines in the file. Comment lines begin with a hash sign (#).
dbcritic can be configured to silence certain issues with silence directives. Any issue whose identifier begins with the given prefix will not be reported. Here is an example of a silence directive:
silence index_fk_ref cache_log
This will silence any issues reported by the index_fk_ref check that pertain to the cache_log table.
If any issues were reported, dbcritic exits with status code 1. If an unrecoverable error occurred, dbcritic exits with status code 2. In any other case, dbcritic exits with status code 0.
The output is quite verbose and repetitive. Experienced users may favor more compact output. This is currently not implemented.
In the check index_fk_ref, the order of the columns in the suggested index is not always correct.
There are many more opportunities for checks.