602SQL Documentation Index  

System Triggers

System triggers are stored procedures executed automatically by the server when a certain event occurs.

System triggers have predefined names and parameters. The trigger name defines which event triggers the trigger.

All system triggers have to be stored in the _SYSEXT applications among the server stored procedures (unlike the usual triggers, that are connected to database tables). An exception to that are the _on_server_stop_appl and _on_server_start_appl procedures, which are part of a specific application. When you define a procedure working as a system trigger, you have to abide the predefined parameters count and types, otherwise the procedure won't be called.

If a system procedure calls a procedure stored in some applications, it has to add the application name as a prefix.

System Triggers Overview

PROCEDURE _on_server_start()

This procedure is called when starting a SQL server. It's called in a separate thread, so the server doesn't wait for it to end and is able to work with clients during its runtime.

If the action that has to be done on server startup is bound to a single application, it's possible to create a procedure _on_server_start_appl with the same meaning in the application.

The procedure will be run under the Config_admin group account.

PROCEDURE _on_server_stop()

This procedure is called when a SQL server is being terminated. Server won't shut down until this procedure is over.

If the action that has to be done on server termination is bound to a single application, it's possible to create a procedure _on_server_stop_appl with the same meaning in the application.

The procedure will be run under the Config_admin group account.

PROCEDURE _on_login_change(IN old_logname CHAR(31), IN new_logname CHAR(31))

This procedure is called each time a client logs in or changes its username. All client actions halt until this procedure is over. Each client should have the privilege to execute this procedure. If the client can't execute this procedure, an error occurs, but the client logs in nevertheless.

The procedure is executed with the privileges of a new user.

PROCEDURE _on_backup(IN pathname CHAR(254), IN success Boolean)

This procedure is called when the server creates a backup of its database file. The pathname parameter is the filename of the backup copy (with the full path), the success parameter is TRUE when the backup is succesful and FALSE on error.

The possible backup compressing and backup copying to another medium is postponed after this procedure is complete in an asynchronous (non-blocking) thread.

The procedure will be run under the Config_admin group account.

Security

Procedures _on_server_start, _on_server_stop, _on_backup are executed with the database configuration administrator privileges. The _on_server_start procedure may start separate threads that will make various actions for applications running on the server, the _on_server_stop procedure may terminate these threads. The _on_backup procedure may send a mail to the administrator when an error occurs.

These procedures may be create or modified by a used assigned to the Author role in the sysext application. By default, the configuration administrator group Config_admin is assigned to this role.

Disabling Procedure Execution

Procedure execution by the system events may be disabled on server startup by the command line switch -Q (for Windows server), or by the parameter -q (for Linux server). This can be useful in case that you created a procedure that causes the server to crash or to be stuck in loop.

List of topics: