event_scheduler

Enable the event scheduler. Possible values are ON, OFF, and DISABLED (keep the event scheduler completely deactivated, it cannot be activated run-time)

See also: System Variables for MariaDB Enterprise Server 10.6, in 10.6 CS, in 10.5 ES, in 10.5 CS, in 10.4 ES, in 10.4 CS, in 10.3 ES, in 10.3 CS, in 10.2 ES, and in 10.2 CS

USAGE

The event_scheduler system variable can be set in a configuration file:

[mariadb]
event_scheduler=ON

The event_scheduler system variable can also be set dynamically at runtime by executing SET GLOBAL:

SET GLOBAL event_scheduler=ON;

When the event_scheduler system variable is set dynamically at runtime, its value will be reset the next time the server restarts. To make the value persist on restart, set it in a configuration file too.

DETAILS

The event_scheduler system variable controls the status of the event scheduler.

  • If the event_scheduler system variable is OFF, then the event scheduler's thread will not exist, and no events will be executed.

  • If the event_scheduler system variable is ON, then the event scheduler's thread will exist, and events will be executed as scheduled.

  • If the event_scheduler system variable is DISABLED, then the event scheduler's thread will not exist, no events will be executed, and enabling the event scheduler will require the service to be restarted.

  • If the event_scheduler system variable is dynamically set to the special value ORIGINAL, then its value will revert to the value from the last service restart.

PARAMETERS

Command-line

--event_scheduler[={OFF|ON|DISABLED|ORIGINAL}]

Configuration file

Supported

Dynamic

Yes

Scope

Global

Data Type

ENUM (OFF, ON, DISABLED, ORIGINAL)

Default Value

OFF

SKYSQL

Cloud

SkySQL Topology

ES Ver

Default

AWS

HA (Primary/Replica)

10.4

OFF (choices: ON, OFF)

AWS

HA (Primary/Replica)

10.5

OFF (choices: ON, OFF)

AWS

Transactional Standalone

10.4

OFF (choices: ON, OFF)

AWS

Transactional Standalone

10.5

OFF (choices: ON, OFF)

AWS

Distributed Transactions

10.5

Not present (choices: ON, OFF)

GCP

ColumnStore

10.5

OFF (choices: ON, OFF)

GCP

ColumnStore Multi

10.5

OFF (choices: ON, OFF)

GCP

Galera

10.4

OFF (choices: ON, OFF)

GCP

Galera

10.5

OFF (choices: ON, OFF)

GCP

HA (Primary/Replica)

10.4

OFF (choices: ON, OFF)

GCP

HA (Primary/Replica)

10.5

OFF (choices: ON, OFF)

GCP

HTAP

10.5

OFF (choices: ON, OFF)

GCP

Transactional Standalone

10.4

OFF (choices: ON, OFF)

GCP

Transactional Standalone

10.5

OFF (choices: ON, OFF)

GCP

Distributed Transactions

10.5

Not present (choices: ON, OFF)

See MariaDB SkySQL documentation to learn more about the MariaDB SkySQL database as a service.

PRIVILEGES

The event_scheduler system variable requires the SUPER privilege to dynamically set its value at runtime.

EXAMPLES

Event Scheduler Thread

If the event_scheduler system variable is OFF, then the event scheduler's thread will not exist:

SHOW GLOBAL VARIABLES LIKE 'event_scheduler';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| event_scheduler | OFF   |
+-----------------+-------+
SELECT ID, STATE FROM information_schema.PROCESSLIST WHERE USER='event_scheduler';
Empty set (0.001 sec)

If the event_scheduler system variable is ON, then the event scheduler's thread will exist:

SET GLOBAL event_scheduler=ON;

SHOW GLOBAL VARIABLES LIKE 'event_scheduler';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| event_scheduler | ON    |
+-----------------+-------+
SELECT ID, STATE FROM information_schema.PROCESSLIST WHERE USER='event_scheduler';
+----+------------------------+
| ID | STATE                  |
+----+------------------------+
| 59 | Waiting on empty queue |
+----+------------------------+

Creating Events

Events can be created when the event_scheduler system variable is ON, and the event will be executed according to its specified schedule:

SHOW GLOBAL VARIABLES LIKE 'event_scheduler';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| event_scheduler | ON    |
+-----------------+-------+
CREATE OR REPLACE TABLE test.test_event_history (
   id int AUTO_INCREMENT PRIMARY KEY,
   event_ts DATETIME
);

CREATE OR REPLACE EVENT test.test_event
   ON SCHEDULE
      EVERY 1 HOUR
      STARTS CURRENT_TIMESTAMP
DO
   INSERT INTO test.test_event_history (event_ts)
      VALUES (NOW());
SELECT * FROM test.test_event_history;
+----+---------------------+
| id | event_ts            |
+----+---------------------+
|  1 | 2020-02-26 01:38:48 |
+----+---------------------+

Receiving Warnings when Off

When the event_scheduler system variable is OFF, most event-related operations will raise a warning with the ER_UNKNOWN_ERROR error code:

SHOW GLOBAL VARIABLES LIKE 'event_scheduler';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| event_scheduler | OFF   |
+-----------------+-------+
CREATE OR REPLACE EVENT test.test_event
   ON SCHEDULE
      EVERY 1 HOUR
      STARTS CURRENT_TIMESTAMP
DO
   INSERT INTO test.test_event_history (event_ts)
      VALUES (NOW());

SHOW WARNINGS;
+---------+------+----------------------------------------------------------------------------------+
| Level   | Code | Message                                                                          |
+---------+------+----------------------------------------------------------------------------------+
| Warning | 1105 | Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it. |
+---------+------+----------------------------------------------------------------------------------+

Receiving Errors when Disabled

When the event_scheduler system variable is DISABLED, most event-related operations will raise an error with the ER_EVENTS_DB_ERROR error code:

SHOW GLOBAL VARIABLES LIKE 'event_scheduler';
+-----------------+----------+
| Variable_name   | Value    |
+-----------------+----------+
| event_scheduler | DISABLED |
+-----------------+----------+
CREATE OR REPLACE EVENT test.test_event
   ON SCHEDULE
      EVERY 1 HOUR
      STARTS CURRENT_TIMESTAMP
DO
   INSERT INTO test.test_event_history (event_ts)
      VALUES (NOW());
ERROR 1577 (HY000): Cannot proceed, because event scheduler is disabled

Reverting to Original Startup Value

If the event_scheduler system variable is dynamically set to the special value ORIGINAL, then its value will revert to the value from the last service restart. This may be useful if you believe that its value was unintentionally changed.

Let's say that the MariaDB service was restarted:

$ sudo systemctl restart mariadb

Then the following demonstrates how the special value ORIGINAL can be used to revert any changes to the event_scheduler system variable:

SHOW GLOBAL VARIABLES LIKE 'event_scheduler';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| event_scheduler | OFF   |
+-----------------+-------+
SET GLOBAL event_scheduler=ON;

SHOW GLOBAL VARIABLES LIKE 'event_scheduler';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| event_scheduler | ON    |
+-----------------+-------+
SET GLOBAL event_scheduler=ORIGINAL;

SHOW GLOBAL VARIABLES LIKE 'event_scheduler';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| event_scheduler | OFF   |
+-----------------+-------+

Dynamically Resetting Global Value to Default

The global value of the event_scheduler system variable can be dynamically reset to the default value by setting it to DEFAULT:

SET GLOBAL event_scheduler=ON;

SHOW GLOBAL VARIABLES LIKE 'event_scheduler';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| event_scheduler | ON    |
+-----------------+-------+
SET GLOBAL event_scheduler=DEFAULT;

SHOW GLOBAL VARIABLES LIKE 'event_scheduler';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| event_scheduler | OFF   |
+-----------------+-------+

Invalid Value for Variable

If a user tries to set the event_scheduler system variable to an invalid value, then the operation will fail with the ER_WRONG_VALUE_FOR_VAR error code:

SET GLOBAL event_scheduler=-1;
ERROR 1231 (42000): Variable 'event_scheduler' can't be set to the value of '-1'

Invalid Type for Variable

If a user tries to set the event_scheduler system variable to an invalid argument, then the operation will fail with the ER_WRONG_TYPE_FOR_VAR error code:

SET GLOBAL event_scheduler='';
ERROR 1232 (42000): Incorrect argument type to variable 'event_scheduler'
SET GLOBAL event_scheduler='infinity';
ERROR 1232 (42000): Incorrect argument type to variable 'event_scheduler'

CHANGE HISTORY

Release Series

History

10.6 Enterprise

  • Present starting in MariaDB Enterprise Server 10.6.4-1.

10.6 Community

  • Present starting in MariaDB Community Server 10.6.0.

10.5 Enterprise

  • Present starting in MariaDB Enterprise Server 10.5.3-1.

10.5 Community

  • Present starting in MariaDB Community Server 10.5.0.

10.4 Enterprise

  • Present starting in MariaDB Enterprise Server 10.4.6-1.

10.4 Community

  • Present starting in MariaDB Community Server 10.4.0.

10.3 Enterprise

  • Present starting in MariaDB Enterprise Server 10.3.16-1.

10.3 Community

  • Present starting in MariaDB Community Server 10.3.0.

10.2 Enterprise

  • Present starting in MariaDB Enterprise Server 10.2.25-1.

10.2 Community

  • Present starting in MariaDB Community Server 10.2.0.

EXTERNAL REFERENCES