In MySQL, we can use the sys.ps_is_consumer_enabled()
function to check whether a given Performance Schema consumer is enabled.
The function returns YES
or NO
, depending on whether or not the specified Performance Schema consumer is enabled. It returns NULL
if the argument is NULL
.
This function accounts for the consumer hierarchy, so a consumer is not considered enabled unless all consumers on which depends are also enabled.
Syntax
The syntax goes like this:
sys.ps_is_consumer_enabled(consumer)
Where consumer
is the name of the consumer to check.
Example
Here’s an example to demonstrate:
SELECT sys.ps_is_consumer_enabled('events_transactions_history');
Result:
YES
In this case, events_transactions_history
is enabled.
Here’s one that’s disabled:
SELECT sys.ps_is_consumer_enabled('events_stages_history');
Result:
NO
Non-Existent Consumer
If the consumer doesn’t exist, an error is returned:
SELECT sys.ps_is_consumer_enabled('homer_simpson_history');
Result:
ERROR 3047 (HY000): Invalid argument error: homer_simpson_history in function sys.ps_is_consumer_enabled.
However prior to MySQL 8.0.18, the result is NULL
when the consumer doesn’t exist.
NULL
Consumer
If the argument is NULL
, then NULL
is returned:
SELECT sys.ps_is_consumer_enabled(NULL);
Result:
NULL