How Prolog Inference Diagnoses a Database: Facts, Rules and Expert Knowledge
A rules-based diagnostic engine — an expert system, such as the one behind Informix® diagnostics in DrWatson — is easier to trust once you can see how small its core idea is. Facts describe what has been observed, rules describe what those observations mean, and an inference engine applies the rules to answer questions — and to explain its answers. We start with an example anyone can follow, countries and capital cities, and then apply exactly the same ideas to database monitoring and root cause analysis.
Prolog basics: facts, rules and inference
Tell Prolog a few things we know:
capital_of(paris, france).
capital_of(berlin, germany).
capital_of(canberra, australia).
in_europe(france).
in_europe(germany).
Prolog has no idea what a capital city is, or where Europe is. It simply treats capital_of and in_europe as named relationships that we have declared to hold. These are facts: things we have stated, with no interpretation yet.
Now add a rule:
european_capital(City) :-
capital_of(City, Country),
in_europe(Country).
In English: a city is a European capital if it is the capital of a country, and that country is in Europe. Now we can ask a question:
?- european_capital(paris).
true.
We never stated that Paris is a European capital. The engine inferred it. It worked backward from the question: find a rule whose conclusion matches, put paris in place of City, then check that capital_of(paris, Country) is known (it is, with Country = france) and that in_europe(france) is known (it is). Both conditions hold, so the answer is true.
We can also ask the open question:
?- european_capital(City).
City = paris ;
City = berlin.
Canberra is missing, because we never said Australia is in Europe. But look at what happens when we ask about a city we know nothing about:
?- european_capital(rome).
false.
Rome is a European capital, yet the answer is false. That is not because Rome is not European; it is because we never gave Prolog the facts to prove it. false means “cannot be proved from what I have been told”, not “is not true”. Hold on to that, because it matters a great deal when the subject is a production database.
Three ideas are at work, and they carry straight over to the next part:
- Facts — what we have observed or stated.
- Rules — knowledge that says what combinations of facts mean. Someone knowledgeable has to supply them; Prolog does not discover them.
- Inference — the engine applying the rules to the facts to reach a conclusion nobody stated explicitly.
Applying Prolog inference to database monitoring
Instead of cities and countries, imagine we are monitoring three databases with a rules engine. The structure is identical: observations as facts, an expert’s knowledge as rules, and an engine that connects them.
1. Tell Prolog what we know
cpu_high(database1).
memory_low(database1).
cpu_high(database2).
disk_full(database3).
These are observations, not diagnoses. Database1 has high CPU usage and low available memory; Database2 has high CPU usage; Database3 has a full disk. Prolog does not inherently know what “high CPU” means operationally — it simply treats cpu_high, memory_low and disk_full as named relationships we have declared to hold.
We have supplied observations, but not yet the knowledge needed to interpret them.
2. Define the rules
overloaded(X) :-
cpu_high(X),
memory_low(X).
needs_attention(X) :-
disk_full(X).
In English: a database is overloaded if it has high CPU and low available memory; a database needs attention if its disk is full. These rules encode knowledge supplied by a database expert. Prolog has not discovered the relationships itself.
3. Ask the inference engine a question
?- overloaded(database1).
Prolog works backward from the question:
- Find a rule whose conclusion matches
overloaded(database1). - Substitute
database1for the rule's variableX. - Check whether
cpu_high(database1)is known. - Check whether
memory_low(database1)is known. - Both succeed, so the query succeeds.
true.
We never declared overloaded(database1). The engine inferred it from facts and a rule.
4. “False” does not mean “healthy”
?- overloaded(database2).
cpu_high(database2) known
memory_low(database2) not known
false.
The rule needs both conditions, so the answer is false. This does not establish that Database2 is healthy. It means only that Prolog cannot prove it is overloaded from the knowledge it was given. For a diagnostic tool this distinction matters: absence of evidence, whether a metric was never collected or simply was not high, must never be presented as a clean bill of health.
5. Combine rules to reach more useful conclusions
Add a second way to prove that a database needs attention:
needs_attention(X) :-
disk_full(X).
needs_attention(X) :-
overloaded(X).
?- needs_attention(X).
X = database3 ;
X = database1.
Database3 needs attention because its disk is full. Database1 needs attention because it is overloaded — a conclusion that was itself established by another rule. The engine is now using the conclusion of one rule to satisfy another.
6. What the engine is doing
| Concept | Meaning |
|---|---|
| Unification | Matching variables and expressions against facts or rules. |
| Backward chaining | Starting with a question and working backward to supporting facts. |
| Backtracking | Revisiting choices to find other valid solutions. |
For needs_attention(database1) the reasoning chain is:
needs_attention(database1)?
|
+-- disk_full(database1)? not known
|
+-- overloaded(database1)?
|
+-- cpu_high(database1)? yes
+-- memory_low(database1)? yes
|
+-- overloaded proved
|
+-- needs_attention proved
Because the chain is explicit, the engine can show which facts and rules supported a conclusion — something a statistical model cannot do in the same way.
That is what makes explainable diagnostics possible. A statistical or machine-learning model can say that a database looks unhealthy, but usually cannot say why in terms an engineer can check. A rules engine can: every conclusion traces back to specific observations and a specific rule an expert wrote, so the reasoning can be reviewed, challenged and corrected. For root cause analysis that traceability matters as much as the answer.
7. Where the expert's knowledge comes in
Our example assumes high CPU combined with low memory means overload. Is that always true? Not necessarily: a large batch job can legitimately consume CPU and memory without causing a problem. An expert might refine the rule:
overloaded(X) :-
cpu_high(X),
memory_low(X),
response_time_high(X).
Now all three observations are required. This separates three things that are easily confused:
- Data — the CPU, memory and response-time observations.
- Knowledge — the expert's rules for interpreting combinations of observations.
- Inference — applying those rules to reach a conclusion.
How DrWatson applies this to Informix diagnostics
DrWatson, the Oninit Informix analyser, is built on exactly this split. Collectors turn onstat output, logs and operating-system metrics into facts; a library of expert-written Prolog rules interprets them; every finding can be traced back to the facts and rules that produced it. Rules that depend on data that was not collected report that the check could not be made, rather than passing silently.
Next step: see what DrWatson checks in the DrWatson feature list, or upload an Informix collection for analysis.