Updated on 2024-08-20 GMT+08:00

DBE_SCHEDULER

API Description

The advanced package DBE_SCHEDULER supports more flexible creation of scheduled tasks through scheduling and programing. For details about all the supported APIs, see Table 1.

DBE_SCHEDULER supports scheduled tasks for synchronizing data between CNs. Tasks with the same name cannot be created between different CNs.

The synchronization function is not implemented in versions earlier than 505.0.0. Therefore, all synchronization APIs synchronize data only in 505.0.0 and later versions.

Before the upgrade, the system checks whether jobs with the same name exist on CNs of the source version. If jobs with the same name exist on CNs of the source version and they are created on different nodes, an error message is displayed, prompting you to delete the jobs and perform the upgrade again.

Table 1 DBE_SCHEDULER

API

Description

DBE_SCHEDULER.CREATE_JOB

Creates a scheduled task.

DBE_SCHEDULER.DROP_JOB

Deletes a scheduled task.

DBE_SCHEDULER.DROP_SINGLE_JOB

Deletes a single scheduled task.

DBE_SCHEDULER.SET_ATTRIBUTE

Sets object attributes.

DBE_SCHEDULER.RUN_JOB

Executes a scheduled task.

DBE_SCHEDULER.RUN_BACKEND_JOB

Runs a scheduled task in the backend.

DBE_SCHEDULER.RUN_FOREGROUND_JOB

Runs a scheduled task in the frontend.

DBE_SCHEDULER.STOP_JOB

Stops a scheduled task.

DBE_SCHEDULER.STOP_SINGLE_JOB

Stops a single scheduled task.

DBE_SCHEDULER.GENERATE_JOB_NAME

Generates the name of a scheduled task.

DBE_SCHEDULER.CREATE_PROGRAM

Creates a program.

DBE_SCHEDULER.DEFINE_PROGRAM_ARGUMENT

Defines program parameters.

DBE_SCHEDULER.DROP_PROGRAM

Deletes a program.

DBE_SCHEDULER.DROP_SINGLE_PROGRAM

Deletes a single program.

DBE_SCHEDULER.SET_JOB_ARGUMENT_VALUE

Sets the parameters of a scheduled task.

DBE_SCHEDULER.CREATE_SCHEDULE

Creates a schedule.

DBE_SCHEDULER.DROP_SCHEDULE

Deletes a schedule.

DBE_SCHEDULER.DROP_SINGLE_SCHEDULE

Deletes a single schedule.

DBE_SCHEDULER.CREATE_JOB_CLASS

Creates the class of a scheduled task.

DBE_SCHEDULER.DROP_JOB_CLASS

Deletes the class of a scheduled task.

DBE_SCHEDULER.DROP_SINGLE_JOB_CLASS

Deletes the class of a single scheduled task.

DBE_SCHEDULER.GRANT_USER_AUTHORIZATION

Grants special permissions to a user.

DBE_SCHEDULER.REVOKE_USER_AUTHORIZATION

Revokes special permissions from a user.

DBE_SCHEDULER.CREATE_CREDENTIAL

Creates a certificate.

DBE_SCHEDULER.DROP_CREDENTIAL

Destroys a certificate.

DBE_SCHEDULER.ENABLE

Enables an object.

DBE_SCHEDULER.ENABLE_SINGLE

Enables a single object.

DBE_SCHEDULER.DISABLE

Disables an object.

DBE_SCHEDULER.DISABLE_SINGLE

Disables a single object.

DBE_SCHEDULER.EVAL_CALENDAR_STRING

Analyzes the scheduling task period.

DBE_SCHEDULER.EVALUATE_CALENDAR_STRING

Analyzes the scheduling task period.

  • DBE_SCHEDULER.CREATE_JOB

    Creates a scheduled task and synchronize it to all CNs.

    The prototypes of the DBE_SCHEDULER.CREATE_JOB function are as follows:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    -- Scheduled tasks of an inline schedule and a program.
    DBE_SCHEDULER.CREATE_JOB(
    job_name TEXT,
    job_type TEXT,
    job_action TEXT,
    number_of_arguments INTEGER             DEFAULT 0,
    start_date TIMESTAMP WITH TIME ZONE     DEFAULT NULL,
    repeat_interval TEXT                    DEFAULT NULL,
    end_date TIMESTAMP WITH TIME ZONE       DEFAULT NULL,
    job_class TEXT            DEFAULT 'DEFAULT_JOB_CLASS',
    enabled BOOLEAN                         DEFAULT FALSE,
    auto_drop BOOLEAN                       DEFAULT TRUE,
    comments TEXT                           DEFAULT NULL,
    credential_name TEXT                    DEFAULT NULL,
    destination_name TEXT                   DEFAULT NULL
    )
    
    -- Reference the created scheduled tasks of the schedule and the program.
    DBE_SCHEDULER.CREATE_JOB(
    job_name TEXT,
    program_name TEXT,
    schedule_name TEXT,
    job_class TEXT            DEFAULT 'DEFAULT_JOB_CLASS',
    enabled BOOLEAN                         DEFAULT FALSE,
    auto_drop BOOLEAN                       DEFAULT TRUE,
    comments TEXT                           DEFAULT NULL,
    job_style TEXT                          DEFAULT 'REGULAR',
    credential_name TEXT                    DEFAULT NULL,
    destination_name TEXT                   DEFAULT NULL
    )
    
    -- Reference the created program and the scheduled task of the inline schedule.
    DBE_SCHEDULER.CREATE_JOB(
    job_name text,
    program_name TEXT,
    start_date TIMESTAMP WITH TIME ZONE     DEFAULT NULL,
    repeat_interval TEXT                    DEFAULT NULL,
    end_date TIMESTAMP WITH TIME ZONE       DEFAULT NULL,
    job_class TEXT            DEFAULT 'DEFAULT_JOB_CLASS',
    enabled BOOLEAN                         DEFAULT FALSE,
    auto_drop BOOLEAN                       DEFAULT TRUE,
    comments TEXT                           DEFAULT NULL,
    job_style TEXT                          DEFAULT 'REGULAR',
    credential_name TEXT                    DEFAULT NULL,
    destination_name TEXT                   DEFAULT NULL
    )
    
    -- Reference the created schedule and the scheduled task of the inline program.
    DBE_SCHEDULER.CREATE_JOB(
    job_name TEXT,
    schedule_name TEXT,
    job_type TEXT,
    job_action TEXT,
    number_of_arguments INTEGER             DEFAULT 0,
    job_class TEXT             DEFAULT 'DEFAULT_JOB_CLASS',
    enabled BOOLEAN                         DEFAULT FALSE,
    auto_drop BOOLEAN                       DEFAULT TRUE,
    comments TEXT                           DEFAULT NULL,
    credential_name TEXT                    DEFAULT NULL,
    destination_name TEXT                   DEFAULT NULL
    )
    

    The scheduled task created through DBE_SCHEDULER does not conflict with the scheduled task in DBE_TASK.

    The scheduled task created by DBE_SCHEDULER generates the corresponding job_id. However, the job_id is meaningless.

    For the create API, the validity of input parameter types is not verified. Successful creation does not mean successful execution. You can query the execution status of the current task in the pg_job system catalog.

    Table 2 Parameters for DBE_SCHEDULER.CREATE_JOB

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    job_name

    TEXT

    IN

    No

    Name of a scheduled task.

    job_type

    TEXT

    IN

    No

    Inline program type of a scheduled task. The options are as follows:
    • 'PLSQL_BLOCK': fast anonymous stored procedure.
    • 'STORED_PROCEDURE': stored procedure that is saved.
    • 'EXTERNAL_SCRIPT': external script.

    job_action

    TEXT

    IN

    No

    Content executed by an inline program of a scheduled task.

    number_of_arguments

    INTEGER

    IN

    No

    Number of inline program parameters of a scheduled task.

    program_name

    TEXT

    IN

    No

    Name of the program referenced by a scheduled task.

    start_date

    TIMESTAMP WITH TIME ZONE

    IN

    Yes

    Inline scheduling start time of a scheduled task.

    repeat_interval

    TEXT

    IN

    Yes

    Inline scheduling period of a scheduled task.

    end_date

    TIMESTAMP WITH TIME ZONE

    IN

    Yes

    Inline scheduling expiration time of a scheduled task.

    schedule_name

    TEXT

    IN

    No

    Name of the schedule referenced by a scheduled task.

    job_class

    TEXT

    IN

    No

    Class name of a scheduled task.

    enabled

    BOOLEAN

    IN

    No

    Status of a scheduled task.

    auto_drop

    BOOLEAN

    IN

    No

    Automatic deletion of a scheduled task.

    comments

    TEXT

    IN

    Yes

    Comments.

    job_style

    TEXT

    IN

    No

    Behavior pattern of a scheduled task. Only 'REGULAR' is supported.

    credential_name

    TEXT

    IN

    Yes

    Certificate name of a scheduled task.

    destination_name

    TEXT

    IN

    Yes

    Target name of a scheduled task. Currently, only 'CCN' (case-insensitive) is supported. Tasks whose destination_name is set to CCN can be executed only on the central coordinator. Otherwise, the original processing logic is used.

    Example:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    gaussdb=# CALL DBE_SCHEDULER.create_program('program1', 'STORED_PROCEDURE', 'select pg_sleep(1);', 3, false, 'test');
     create_program 
    ----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.create_schedule('schedule1', NULL, 'sysdate', NULL, 'test');
     create_schedule 
    -----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.create_job(job_name=>'job1', program_name=>'program1', schedule_name=>'schedule1');
     create_job 
    ------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_job('job1', true, false, 'STOP_ON_FIRST_ERROR');
     drop_job 
    ----------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_schedule('schedule1');
     drop_schedule 
    ---------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_program('program1', false);
     drop_program 
    --------------
    
    (1 row)
    

    To create a scheduled task of the EXTERNAL_SCRIPT type, the administrator must assign related permissions and certificates and the user who starts the database must have the read permission on the external script.

  • DBE_SCHEDULER.DROP_JOB

    Deletes a scheduled task. The operation is performed only when the task is synchronized.

    The prototype of the DBE_SCHEDULER.DROP_JOB function is as follows:

    1
    2
    3
    4
    5
    6
    DBE_SCHEDULER.drop_job(
    job_name text,
    force boolean                           default false,
    defer boolean                           default false,
    commit_semantics text      default 'STOP_ON_FIRST_ERROR'
    )
    

    DBE_SCHEDULER.DROP_JOB can specify one or more tasks, or specify a task class to delete a scheduled task.

    Table 3 Parameters for DBE_SCHEDULER.DROP_JOB

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    job_name

    TEXT

    IN

    No

    Name or class of a scheduled task. You can specify one or more scheduled tasks. If you specify multiple scheduled tasks, separate them with commas (,).

    force

    BOOLEAN

    IN

    No

    Specifies whether to delete a scheduled task.
    • TRUE: The current scheduled task is stopped and then deleted.
    • FALSE: The scheduled task fails to be deleted if it is running.

    defer

    BOOLEAN

    IN

    No

    Specifies whether to delete a scheduled task.
    • TRUE: A scheduled task can be deleted after it is complete.
    • FALSE: The scheduled task cannot be executed and is deleted.

    commit_semantics

    TEXT

    IN

    No

    Commit rules:
    • 'STOP_ON_FIRST_ERROR': The deletion operation performed before the first error is reported is committed.
    • 'TRANSACTIONAL': Transaction-level commit. The deletion operation performed before an error is reported will be rolled back.
    • 'ABSORB_ERRORS': The system attempts to bypass an error and commit the deletion operation that is performed successfully.
    Example:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    gaussdb=# CALL DBE_SCHEDULER.create_program('program1', 'STORED_PROCEDURE', 'select pg_sleep(1);', 3, false, 'test');
     create_program 
    ----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.create_schedule('schedule1', NULL, 'sysdate', NULL, 'test');
     create_schedule 
    -----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.create_job(job_name=>'job1', program_name=>'program1', schedule_name=>'schedule1');
     create_job 
    ------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_job('job1', true, false, 'STOP_ON_FIRST_ERROR');
     drop_job 
    ----------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_schedule('schedule1');
     drop_schedule 
    ---------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_program('program1', false);
     drop_program 
    --------------
    
    (1 row)
    

    The TRANSACTIONAL option in commit_semantic takes effect only when force is set to false.

  • DBE_SCHEDULER.DROP_SINGLE_JOB

    Deletes a scheduled task. The operation is performed only when the task is synchronized.

    The prototype of the DBE_SCHEDULER.DROP_SINGLE_JOB function is as follows:

    1
    2
    3
    4
    5
    DBE_SCHEDULER.drop_single_job(
    job_name text,
    force boolean                           default false,
    defer boolean                           default false
    )
    
    Table 4 Parameters for DBE_SCHEDULER.DROP_SINGLE_JOB

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    job_name

    TEXT

    IN

    No

    Specifies the name of a scheduled task or scheduled task class.

    force

    BOOLEAN

    IN

    No

    Specifies whether to delete a scheduled task.
    • TRUE: The current scheduled task is stopped and then deleted.
    • FALSE: The scheduled task fails to be deleted if it is running.

    defer

    BOOLEAN

    IN

    No

    Specifies whether to delete a scheduled task.
    • TRUE: A scheduled task can be deleted after it is complete.
    • FALSE: The scheduled task cannot be executed and is deleted.

    Example:

    gaussdb=# CALL DBE_SCHEDULER.create_program('program1', 'STORED_PROCEDURE', 'select pg_sleep(1);', 0, false, 'test');
     create_program 
    ----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.create_job('job1', 'program1', '2021-07-20', 'interval ''3 minute''', '2121-07-20', 'DEFAULT_JOB_CLASS', false, false,'test', 'style', NULL, NULL);
     create_job 
    ------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_single_job('job1', false, false);
     drop_single_job 
    -----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_program('program1', false);
     drop_program 
    --------------
    
    (1 row)
  • DBE_SCHEDULER.SET_ATTRIBUTE

    Modifies the attributes of a scheduled task.

    The prototypes of the DBE_SCHEDULER.SET_ATTRIBUTE function are as follows:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    DBE_SCHEDULER.set_attribute(
    name                    text,
    attribute               text,
    value                   boolean
    )
    
    DBE_SCHEDULER.set_attribute(
    name                    text,
    attribute               text,
    value                   text
    )
    
    DBE_SCHEDULER.set_attribute(
    name                    text,
    attribute               text,
    value                   timestamp
    )
    
    DBE_SCHEDULER.set_attribute(
    name                    text,
    attribute               text,
    value                   timestamp with time zone
    )
    
    DBE_SCHEDULER.set_attribute(
    name text,
    attribute text,
    value text,
    value2 text                             default NULL
    )
    

    name specifies any object in DBE_SCHEDULER.

    Table 5 Parameters for DBE_SCHEDULER.SET_ATTRIBUTE

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    name

    TEXT

    IN

    No

    Object name.

    attribute

    TEXT

    IN

    No

    Attribute name.

    value

    BOOLEAN/DATE/TIMESTAMP/TIMESTAMP WITH TIME ZONE/TEXT

    IN

    No

    Attribute value. The options are as follows:

    • Scheduled-task-related: job_type, job_action, number_of_arguments, start_date, repeat_interval, end_date, ob_class, enabled, auto_drop, comments, credential_name, destination_name, program_name, schedule_name, and job_style.
    • Program-related: program_action, program_type, number_of_arguments, and comments.
    • Scheduling-related: start_date, repeat_interval, end_date, and comments.

    value2

    TEXT

    IN

    Yes

    Additional attribute value. Reserved parameter bit. Currently, the target attribute with extra attribute values is not supported.

    Example:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    gaussdb=# CALL DBE_SCHEDULER.create_program('program1', 'STORED_PROCEDURE', 'select pg_sleep(1);', 3, false, 'test');
     create_program 
    ----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.set_attribute('program1', 'number_of_arguments', 0);
     set_attribute 
    ---------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.set_attribute('program1', 'program_type', 'STORED_PROCEDURE');
     set_attribute 
    ---------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_program('program1', false);
     drop_program 
    --------------
    
    (1 row)
    

    Do not use DBE_SCHEDULER.SET_ATTRIBUTE to leave the parameters empty.

    The object name cannot be changed using DBE_SCHEDULER.SET_ATTRIBUTE.

    Inline objects cannot be changed by DBE_SCHEDULER.SET_ATTRIBUTE.

  • DBE_SCHEDULER.RUN_JOB

    Executes a scheduled task.

    The prototype of the DBE_SCHEDULER.RUN_JOB function is as follows:

    1
    2
    3
    4
    DBE_SCHEDULER.run_job(
    job_name text,
    use_current_session boolean             default true
    )
    

    DBE_SCHEDULER.RUN_JOB is used to run scheduled tasks immediately. It is independent of the scheduling of scheduled tasks and can even run at the same time.

    Table 6 Parameters for DBE_SCHEDULER.RUN_JOB

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    job_name

    TEXT

    IN

    No

    Name of a scheduled task. You can specify one or more scheduled tasks. If you specify multiple scheduled tasks, separate them with commas (,).

    use_current_session

    BOOLEAN

    IN

    No

    Specifies whether to run a scheduled task.
    • TRUE: Use the current session to check whether the scheduled task can run properly.
    • FALSE: Start the scheduled task in the background. The execution result is recorded in logs.
    Example:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    gaussdb=# SELECT dbe_scheduler.create_job('job1','PLSQL_BLOCK','begin insert into test1 values(12); end;',0,null,null,null,'DEFAULT_JOB_CLASS',false,false,null,null,null);
     create_job 
    ------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.run_job('job1', false);
     run_job 
    ---------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_job('job1', true, false, 'STOP_ON_FIRST_ERROR');
     drop_job 
    ----------
    
    (1 row)
    

    Currently, use_current_session applies only to scheduled tasks whose job_type is set to EXTERNAL_SCRIPT.

  • DBE_SCHEDULER.RUN_BACKEND_JOB

    Runs a scheduled task in the backend.

    The prototype of the DBE_SCHEDULER.RUN_BACKEND_JOB function is as follows:

    1
    2
    3
    DBE_SCHEDULER.run_backend_job(
    job_name text
    )
    
    Table 7 Parameters for DBE_SCHEDULER.RUN_BACKEND_JOB

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    job_name

    text

    IN

    No

    Name of a scheduled task.

    Example:

    gaussdb=# SELECT dbe_scheduler.create_job('job1','PLSQL_BLOCK','begin insert into test1 values(12); end;',0,null,null,null,'DEFAULT_JOB_CLASS',false,false,null,null,null);
     create_job 
    ------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.run_backend_job('job1');
     run_backend_job 
    -----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_job('job1', true, false, 'STOP_ON_FIRST_ERROR');
     drop_job 
    ----------
    
    (1 row)
  • DBE_SCHEDULER.RUN_FOREGROUND_JOB

    Executes a scheduled task in the current session.

    Only external tasks can be executed.

    Return value: text

    The prototype of the DBE_SCHEDULER.RUN_FOREGROUND_JOB function is as follows:

    1
    2
    3
    DBE_SCHEDULER.run_foreground_job(
    job_name text
    )return text
    
    Table 8 Parameters for DBE_SCHEDULER.RUN_FOREGROUND_JOB

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    job_name

    TEXT

    IN

    No

    Name of a scheduled task.

    Example:

    gaussdb=# create user test1 identified by '*********';
    NOTICE:  The encrypted password contains MD5 ciphertext, which is not secure.
    CREATE ROLE
    gaussdb=# select DBE_SCHEDULER.create_credential('cre_1', 'test1', '*********');
     create_credential 
    -------------------
    
    (1 row)
    
    gaussdb=# select DBE_SCHEDULER.create_job(job_name=>'job1', job_type=>'EXTERNAL_SCRIPT', job_action=>'/usr/bin/pwd', enabled=>true, auto_drop=>false, credential_name => 'cre_1');
     create_job 
    ------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.run_foreground_job('job1');
      run_foreground_job
    ---------------------------------
     Host key verification failed.\r+
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_job('job1', true, false, 'STOP_ON_FIRST_ERROR');
     drop_job 
    ----------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_credential('cre_1', false);
     drop_credential 
    -----------------
    
    (1 row)
    
    gaussdb=# drop user test1;
    DROP ROLE
  • DBE_SCHEDULER.STOP_JOB

    Stops a scheduled task.

    The prototype of the DBE_SCHEDULER.STOP_JOB function is as follows:

    1
    2
    3
    4
    5
    DBE_SCHEDULER.stop_job(
    job_name text,
    force boolean                           default false,
    commit_semantics text                   default 'STOP_ON_FIRST_ERROR'
    )
    
    Table 9 Parameters for DBE_SCHEDULER.STOP_JOB

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    job_name

    TEXT

    IN

    No

    Name or class of a scheduled task. You can specify one or more scheduled tasks. If you specify multiple scheduled tasks, separate them with commas (,).

    force

    BOOLEAN

    IN

    No

    Specifies whether to delete a scheduled task.
    • TRUE: The scheduler sends a termination signal to end the task thread immediately.
    • FALSE: The scheduler attempts to use the interrupt signal to terminate the scheduled task thread.

    commit_semantics

    TEXT

    IN

    No

    Commit rules:
    • 'STOP_ON_FIRST_ERROR': The interrupt operation performed before the first error is reported is committed.
    • 'ABSORB_ERRORS': The system attempts to bypass an error and commit the interrupt operation that is performed successfully.

    Example:

    gaussdb=# SELECT dbe_scheduler.create_job('job1','PLSQL_BLOCK','begin insert into test1 values(12); end;',0,null,null,null,'DEFAULT_JOB_CLASS',false,false,null,null,null);
     create_job 
    ------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.stop_job('job1', true, 'STOP_ON_FIRST_ERROR');
     stop_job 
    ----------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_job('job1', true, false, 'STOP_ON_FIRST_ERROR');
     drop_job 
    ----------
    
    (1 row)
  • DBE_SCHEDULER.STOP_SINGLE_JOB

    Stops a single scheduled task.

    The prototype of the DBE_SCHEDULER.STOP_SINGLE_JOB function is as follows:

    1
    2
    3
    4
    DBE_SCHEDULER.stop_single_job(
    job_name text,
    force boolean                           default false
    )
    
    Table 10 Parameters for DBE_SCHEDULER.STOP_SINGLE_JOB

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    job_name

    TEXT

    IN

    No

    Specifies the name of a scheduled task or scheduled task class.

    force

    BOOLEAN

    IN

    No

    Specifies whether to delete a scheduled task.
    • TRUE: The scheduler sends a termination signal to end the task thread immediately.
    • FALSE: The scheduler attempts to use the interrupt signal to terminate the scheduled task thread.

    Example:

    gaussdb=# SELECT dbe_scheduler.create_job('job1','PLSQL_BLOCK','begin insert into test1 values(12); end;',0,null,null,null,'DEFAULT_JOB_CLASS',false,false,null,null,null);
     create_job 
    ------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.stop_single_job('job1', true);
     stop_single_job 
    -----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_job('job1', true, false, 'STOP_ON_FIRST_ERROR');
     drop_job 
    ----------
    
    (1 row)
  • DBE_SCHEDULER.GENERATE_JOB_NAME

    Generates the name of a scheduled task.

    The prototype of the DBE_SCHEDULER.GENERATE_JOB_NAME function is as follows:

    1
    2
    3
    DBE_SCHEDULER.generate_job_name(
    prefix text                             default 'JOB$_'
    )return text
    
    Table 11 Parameters for DBE_SCHEDULER.GENERATE_JOB_NAME

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    prefix

    TEXT

    IN

    No

    Prefix of the generated name. The default value is 'JOB$_'. Scheduled tasks that are repeatedly executed are named as follows:

    job$_1, job$_2, job$_3 ...

    Example:

    gaussdb=# CALL DBE_SCHEDULER.generate_job_name();
     generate_job_name 
    -------------------
     JOB$_1
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.generate_job_name();
     generate_job_name 
    -------------------
     JOB$_2
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.generate_job_name('job');
     generate_job_name 
    -------------------
     job3
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.generate_job_name('job');
     generate_job_name 
    -------------------
     job4
    (1 row)
    

    When DBE_SCHEDULER.GENERATE_JOB_NAME is executed for the first time, a temporary sequence is created in public to store the sequence number of the current name. A common user does not have the create permission in public. Therefore, if a common user calls the function for the first time in the current database, the function fails to be called. In this case, you need to grant the create permission in public to the common user or call the API as a user with the create permission to create a temporary sequence.

  • DBE_SCHEDULER.CREATE_PROGRAM

    Creates a program and synchronizes it to all CNs.

    The prototype of the DBE_SCHEDULER.CREATE_PROGRAM function is as follows:

    1
    2
    3
    4
    5
    6
    7
    8
    DBE_SCHEDULER.create_program(
    program_name text,
    program_type text,
    program_action text,
    number_of_arguments integer             default 0,
    enabled boolean                         default false,
    comments text                           default NULL
    )
    
    Table 12 Parameters for DBE_SCHEDULER.CREATE_PROGRAM

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    program_name

    TEXT

    IN

    No

    Name of a program.

    program_type

    TEXT

    IN

    No

    Program type. The options are as follows:
    • 'PLSQL_BLOCK': fast anonymous stored procedure.
    • 'STORED_PROCEDURE': stored procedure that is saved.
    • 'EXTERNAL_SCRIPT': external script.

    program_action

    TEXT

    IN

    No

    Program operation.

    number_of_arguments

    INTEGER

    IN

    No

    Number of parameters used by the program.

    enabled

    BOOLEAN

    IN

    No

    Specifies whether the program is enabled.

    comments

    TEXT

    IN

    Yes

    Comments.

    Example:

    gaussdb=# CALL DBE_SCHEDULER.create_program('program1', 'STORED_PROCEDURE', 'select pg_sleep(1);', 3, false, 'test');
     create_program 
    ----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_program('program1', false);
     drop_program 
    --------------
    
    (1 row)
  • DBE_SCHEDULER.DEFINE_PROGRAM_ARGUMENT

    Defines program parameters. The operation is performed only when the program is synchronized.

    An API with the default value default_value will not convert characters to lowercase letters by default. In this version, characters are case sensitive.

    The prototype of the DBE_SCHEDULER.DEFINE_PROGRAM_ARGUMENT function is as follows:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    DBE_SCHEDULER.define_program_argument(
    program_name text,
    argument_position integer,
    argument_name text                      default NULL,
    argument_type text,
    out_argument boolean                    default false
    )
    
    -- With a default value --
    DBE_SCHEDULER.define_program_argument(
    program_name text,
    argument_position integer,
    argument_name text                      default NULL,
    argument_type text,
    default_value text,
    out_argument boolean                    default false
    )
    
    Table 13 Parameters for DBE_SCHEDULER.DEFINE_PROGRAM_ARGUMENT

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    program_name

    TEXT

    IN

    No

    Name of a program.

    argument_position

    INTEGER

    IN

    No

    Parameter location.

    argument_name

    TEXT

    IN

    No

    Parameter name.

    argument_type

    TEXT

    IN

    No

    Parameter type.

    default_value

    TEXT

    IN

    No

    Default value.

    out_argument

    BOOLEAN

    IN

    No

    Reserved parameter.

    Example:

    gaussdb=# CALL DBE_SCHEDULER.create_program('program1', 'STORED_PROCEDURE', 'select pg_sleep(1);', 2, false, 'test');
    create_program 
    ----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.define_program_argument('program1', 1, 'pa1', 'type1', false);
     define_program_argument 
    -------------------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.define_program_argument('program1', 1, 'pa1', 'type1', 'value1', false);
     define_program_argument 
    -------------------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_program('program1', false);
     drop_program 
    --------------
    
    (1 row)
  • DBE_SCHEDULER.DROP_PROGRAM

    Deletes a program. The operation is performed only when the program is synchronized.

    The prototype of the DBE_SCHEDULER.DROP_PROGRAM function is as follows:

    1
    2
    3
    4
    DBE_SCHEDULER.drop_program(
    program_name text,
    force boolean                           default false
    )
    
    Table 14 Parameters for DBE_SCHEDULER.DROP_PROGRAM

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    program_name

    TEXT

    IN

    No

    Name of a program.

    force

    BOOLEAN

    IN

    No

    Specifies whether to delete a program.
    • TRUE: Before a program is deleted, all jobs that use the program are disabled.
    • FALSE: The program cannot be referenced by any job. Otherwise, an error is sent.

    Example:

    gaussdb=# CALL DBE_SCHEDULER.create_program('program1', 'STORED_PROCEDURE', 'select pg_sleep(1);', 2, false, 'test');
    create_program 
    ----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_program('program1', false);
     drop_program 
    --------------
    
    (1 row)
    
  • DBE_SCHEDULER.DROP_SINGLE_PROGRAM

    Deletes a single program. The operation is performed only when the program is synchronized.

    The prototype of the DBE_SCHEDULER.DROP_SINGLE_PROGRAM function is as follows:

    1
    2
    3
    4
    DBE_SCHEDULER.drop_single_program(
    program_name text,
    force boolean                           default false
    )
    
    Table 15 Parameters for DBE_SCHEDULER.DROP_SINGLE_PROGRAM

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    program_name

    TEXT

    IN

    No

    Name of a program.

    force

    BOOLEAN

    IN

    No

    Specifies whether to delete a program.
    • TRUE: Before a program is deleted, all jobs that use the program are disabled.
    • FALSE: The program cannot be referenced by any job. Otherwise, an error is sent.

    Example:

    gaussdb=# CALL DBE_SCHEDULER.create_program('program1', 'STORED_PROCEDURE', 'select pg_sleep(1);', 2, false, 'test');
    create_program 
    ----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_single_program('program1', false);
     drop_single_program 
    ---------------------
    
    (1 row)
    
  • DBE_SCHEDULER.SET_JOB_ARGUMENT_VALUE

    Sets the parameters of a scheduled task. The argument_value can be left empty. The operation is performed only when the task is synchronized.

    The prototype of the DBE_SCHEDULER.SET_JOB_ARGUMENT_VALUE function is as follows:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    DBE_SCHEDULER.set_job_argument_value(
    job_name text,
    argument_position integer,
    argument_value text
    )
    
    DBE_SCHEDULER.set_job_argument_value(
    job_name text,
    argument_name text,
    argument_value text
    )
    
    Table 16 Parameters for DBE_SCHEDULER.SET_JOB_ARGUMENT_VALUE

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    job_name

    TEXT

    IN

    No

    Name of a scheduled task.

    argument_position

    INTEGER

    IN

    No

    Parameter location.

    argument_name

    TEXT

    IN

    Yes

    Parameter name.

    argument_value

    TEXT

    IN

    Yes

    Parameter value.

    Example:

    gaussdb=# CALL dbe_scheduler.create_job('job1','EXTERNAL_SCRIPT','begin insert into test1 values(12); end;',2,null,null,null,'DEFAULT_JOB_CLASS',false,false,null,null,null);
     create_job 
    ------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.set_job_argument_value('job1', 1, 'value1');
     set_job_argument_value 
    ------------------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_job('job1', true, false, 'STOP_ON_FIRST_ERROR');
     drop_job 
    ----------
    
    (1 row)
  • DBE_SCHEDULER.CREATE_SCHEDULE

    Creates a schedule and synchronizes it to all CNs.

    The prototype of the DBE_SCHEDULER.CREATE_SCHEDULE function is as follows:

    1
    2
    3
    4
    5
    6
    7
    DBE_SCHEDULER.create_schedule(
    schedule_name text,
    start_date timestamp with time zone     default NULL,
    repeat_interval text,
    end_date timestamp with time zone       default NULL,
    comments text                           default NULL
    )
    
    Table 17 Parameters for DBE_SCHEDULER.CREATE_SCHEDULE

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    schedule_name

    TEXT

    IN

    No

    Name of a schedule.

    start_date

    TIMESTAMP WITH TIME ZONE

    IN

    Yes

    Start time of a schedule.

    repeat_interval

    TEXT

    IN

    No

    Repetition frequency of a schedule.

    end_date

    TIMESTAMP WITH TIME ZONE

    IN

    Yes

    End time of a schedule.

    comments

    TEXT

    IN

    Yes

    Comments.

    Example:

    gaussdb=# CALL DBE_SCHEDULER.create_schedule('schedule1', sysdate, 'sysdate + 3 / (24 * 60 * 60)', null, 'test1');
     create_schedule 
    -----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.create_schedule('schedule2', sysdate, 'FREQ=DAILY; BYHOUR=6;', null, 'test1');
     create_schedule 
    -----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.create_schedule('schedule3', sysdate, 'FREQ=DAILY; BYHOUR=6;');
     create_schedule 
    -----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_schedule('schedule1');
     drop_single_schedule 
    ----------------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_schedule('schedule2', false);
     drop_single_schedule 
    ----------------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_schedule('schedule3', true);
     drop_single_schedule 
    ----------------------
    
    (1 row)
  • DBE_SCHEDULER.DROP_SCHEDULE

    Deletes a schedule. The operation is performed only when the schedule is synchronized.

    The prototype of the DBE_SCHEDULER.DROP_SCHEDULE function is as follows:

    1
    2
    3
    4
    DBE_SCHEDULER.drop_schedule(
    schedule_name text,
    force boolean                           default false
    )
    
    Table 18 Parameters for DBE_SCHEDULER.DROP_SCHEDULE

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    schedule_name

    TEXT

    IN

    No

    Name of a schedule.

    force

    BOOLEAN

    IN

    No

    Specifies whether to delete a schedule.
    • true: Any jobs or windows that use this schedule are disabled before the schedule is deleted.
    • false: The schedule cannot be referenced by any job or window. Otherwise, an error occurs.

    Example:

    gaussdb=# CALL DBE_SCHEDULER.create_schedule('schedule1', sysdate, 'sysdate + 3 / (24 * 60 * 60)', null, 'test1');
     create_schedule 
    -----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.create_schedule('schedule2', sysdate, 'FREQ=DAILY; BYHOUR=6;', null, 'test1');
     create_schedule 
    -----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.create_schedule('schedule3', sysdate, 'FREQ=DAILY; BYHOUR=6;');
     create_schedule 
    -----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_schedule('schedule1');
     drop_single_schedule 
    ----------------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_schedule('schedule2', false);
     drop_single_schedule 
    ----------------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_schedule('schedule3', true);
     drop_single_schedule 
    ----------------------
    
    (1 row)
    
  • DBE_SCHEDULER.DROP_SINGLE_SCHEDULE

    Deletes a single schedule. The operation is performed only when the schedule is synchronized.

    The prototype of the DBE_SCHEDULER.DROP_SINGLE_SCHEDULE function is as follows:

    1
    2
    3
    4
    DBE_SCHEDULER.drop_single_schedule(
    schedule_name text,
    force boolean                           default false
    )
    
    Table 19 Parameters for DBE_SCHEDULER.DROP_SINGLE_SCHEDULE

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    schedule_name

    TEXT

    IN

    No

    Name of a schedule.

    force

    BOOLEAN

    IN

    No

    Specifies whether to delete a schedule.
    • TRUE: Any jobs or windows that use this schedule are disabled before the schedule is deleted.
    • FALSE: The schedule cannot be referenced by any job or window. Otherwise, an error occurs.

    Example:

    gaussdb=# CALL DBE_SCHEDULER.create_schedule('schedule1', sysdate, 'sysdate + 3 / (24 * 60 * 60)', null, 'test1');
     create_schedule 
    -----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.create_schedule('schedule2', sysdate, 'FREQ=DAILY; BYHOUR=6;', null, 'test1');
     create_schedule 
    -----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.create_schedule('schedule3', sysdate, 'FREQ=DAILY; BYHOUR=6;');
     create_schedule 
    -----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_single_schedule('schedule1');
     drop_single_schedule 
    ----------------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_single_schedule('schedule2', false);
     drop_single_schedule 
    ----------------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_single_schedule('schedule3', true);
     drop_single_schedule 
    ----------------------
    
    (1 row)
  • DBE_SCHEDULER.CREATE_JOB_CLASS

    Creates a scheduled task class and synchronizes it to all CNs.

    The prototype of the DBE_SCHEDULER.CREATE_JOB_CLASS function is as follows:

    1
    2
    3
    4
    5
    6
    7
    8
    DBE_SCHEDULER.create_job_class(
    job_class_name text,
    resource_consumer_group text            default NULL,
    service text                            default NULL,
    logging_level integer                   default 0,
    log_history integer                     default NULL,
    comments text                           default NULL
    )
    
    Table 20 Parameters for DBE_SCHEDULER.CREATE_JOB_CLASS

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    job_class_name

    TEXT

    IN

    No

    Name of a scheduled task class.

    resource_consumer_group

    TEXT

    IN

    Yes

    Inline resource consumer group of a scheduled task class.

    service

    TEXT

    IN

    Yes

    Inline database service of a scheduled task class.

    logging_level

    INTEGER

    IN

    No

    Number of scheduled task records.

    log_history

    INTEGER

    IN

    Yes

    Number of days for storing scheduled task records.

    comments

    TEXT

    IN

    Yes

    Comments.

    Example:

    gaussdb=# CALL DBE_SCHEDULER.create_job_class(job_class_name => 'jc1', resource_consumer_group => '123');
     create_job_class 
    ------------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_job_class('jc1', false);
     drop_job_class 
    ----------------
    
    (1 row)
  • DBE_SCHEDULER.DROP_JOB_CLASS

    Deletes the class of a scheduled task. The operation is performed only when the scheduled task class is synchronized.

    The prototype of the DBE_SCHEDULER.DROP_JOB_CLASS function is as follows:

    1
    2
    3
    4
    DBE_SCHEDULER.drop_job_class(
    job_class_name text,
    force boolean                           default false
    )
    
    Table 21 Parameters for DBE_SCHEDULER.DROP_JOB_CLASS

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    job_class_name

    TEXT

    IN

    No

    Name of a scheduled task class.

    force

    BOOLEAN

    IN

    No

    Specifies whether to delete a scheduled task class.
    • TRUE: Jobs of this class will be disabled, and another class will be set as the default class. Only when such setting is successful, this class will be deleted.
    • FALSE: The class to be deleted cannot be referenced by any job. Otherwise, an error occurs.

    Example:

    gaussdb=# CALL DBE_SCHEDULER.create_job_class(job_class_name => 'jc1', resource_consumer_group => '123');
     create_job_class 
    ------------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_job_class('jc1', false);
     drop_job_class 
    ----------------
    
    (1 row)
    
  • DBE_SCHEDULER.DROP_SINGLE_JOB_CLASS

    Deletes the class of a single scheduled task. The operation is performed only when the scheduled task class is synchronized.

    The prototype of the DBE_SCHEDULER.DROP_SINGLE_JOB_CLASS function is as follows:

    1
    2
    3
    4
    DBE_SCHEDULER.drop_single_job_class(
    job_class_name text,
    force boolean                           default false
    )
    
    Table 22 Parameters for DBE_SCHEDULER.DROP_SINGLE_JOB_CLASS

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    job_class_name

    TEXT

    IN

    No

    Name of a scheduled task class.

    force

    BOOLEAN

    IN

    No

    Specifies whether to delete a scheduled task class.
    • TRUE: Jobs of this class will be disabled, and another class will be set as the default class. Only when such setting is successful, this class will be deleted.
    • FALSE: The class to be deleted cannot be referenced by any job. Otherwise, an error occurs.

    Example:

    gaussdb=# CALL DBE_SCHEDULER.create_job_class(job_class_name => 'jc1', resource_consumer_group => '123');
     create_job_class 
    ------------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_single_job_class('jc1', false);
     drop_single_job_class 
    -----------------------
    
    (1 row)
  • DBE_SCHEDULER.GRANT_USER_AUTHORIZATION

    Grants the scheduled task permissions to the database user. The user who calls this function must have the SYSADMIN permission. Then, it is synchronized to all CNs.

    The prototype of the DBE_SCHEDULER.GRANT_USER_AUTHORIZATION function is as follows:

    1
    2
    3
    4
    DBE_SCHEDULER.grant_user_authorization(
    username                text,
    privilege               text
    )
    
    Table 23 Parameters for DBE_SCHEDULER.GRANT_USER_AUTHORIZATION

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    username

    TEXT

    IN

    No

    Database username.

    privilege

    TEXT

    IN

    No

    Scheduled task permission.

    Example:

    gaussdb=# create user user1 password '1*s*****';
    NOTICE:  The encrypted password contains MD5 ciphertext, which is not secure.
    CREATE ROLE
    gaussdb=# CALL DBE_SCHEDULER.grant_user_authorization('user1', 'create job');
     grant_user_authorization 
    --------------------------
    
    (1 row)
    gaussdb=# drop user user1;
    DROP ROLE
  • DBE_SCHEDULER.REVOKE_USER_AUTHORIZATION

    Revokes the scheduled task permissions from the database user. The user who calls this function must have the SYSADMIN permission. The operation is performed only when the permission granting is synchronized.

    The prototype of the DBE_SCHEDULER.REVOKE_USER_AUTHORIZATION function is as follows:

    1
    2
    3
    4
    DBE_SCHEDULER.revoke_user_authorization(
    username                text,
    privilege               text
    )
    
    Table 24 Parameters for DBE_SCHEDULER.REVOKE_USER_AUTHORIZATION

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    username

    TEXT

    IN

    No

    Database username.

    privilege

    TEXT

    IN

    No

    Scheduled task permission.

    Example:

    gaussdb=# create user user1 password '1*s*****';
    NOTICE:  The encrypted password contains MD5 ciphertext, which is not secure.
    CREATE ROLE
    gaussdb=# CALL DBE_SCHEDULER.grant_user_authorization('user1', 'create job');
     grant_user_authorization 
    --------------------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.revoke_user_authorization('user1', 'create job');
     revoke_user_authorization 
    ---------------------------
    
    (1 row)
    gaussdb=# drop user user1;
    DROP ROLE
  • DBE_SCHEDULER.CREATE_CREDENTIAL

    Creates an authorization certificate. The user who calls this function must have the SYSADMIN permission. Then, it is synchronized to all CNs.

    The prototype of the DBE_SCHEDULER.CREATE_CREDENTIAL function is as follows:

    1
    2
    3
    4
    5
    6
    7
    8
    DBE_SCHEDULER.create_credential(
    credential_name         text,
    username                text,
    password                text            default NULL,
    database_role           text            default NULL,
    windows_domain          text            default NULL,
    comments                text            default NULL
    )
    
    Table 25 Parameters for DBE_SCHEDULER.CREATE_CREDENTIAL

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    credential_name

    TEXT

    IN

    No

    Name of the authorization certificate.

    username

    TEXT

    IN

    No

    Database username.

    password

    TEXT

    IN

    Yes

    User password.

    database_role

    TEXT

    IN

    Yes

    Database system permission.

    windows_domain

    TEXT

    IN

    Yes

    Domain to which a Windows user belongs.

    comments

    TEXT

    IN

    Yes

    Comments.

    Example:

    gaussdb=# CALL DBE_SCHEDULER.create_credential('cre_1', 'user1', '');
     create_credential 
    -------------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_credential('cre_1', false);
     drop_credential 
    -----------------
    
    (1 row)

    The password parameter of DBE_SCHEDULER.CREATE_CREDENTIAL must be set to NULL or '******'. This parameter is used only for compatibility and does not indicate any actual meaning. Do not use the OS username corresponding to the installation user to create a certificate.

  • DBE_SCHEDULER.DROP_CREDENTIAL

    Destroys an authorization certificate. The user who calls this function must have the SYSADMIN permission. The operation is performed only when the certificate is synchronized.

    The prototype of the DBE_SCHEDULER.DROP_CREDENTIAL function is as follows:

    1
    2
    3
    4
    DBE_SCHEDULER.drop_credential(
    credential_name         text,
    force boolean default false
    )
    
    Table 26 Parameters for DBE_SCHEDULER.DROP_CREDENTIAL

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    credential_name

    TEXT

    IN

    No

    Name of the authorization certificate.

    force

    BOOLEAN

    IN

    No

    Specifies whether to delete the authorization certificate.
    • TRUE: The certificate will be deleted no matter whether it is referenced by any job.
    • FALSE: No job can reference the certificate. Otherwise, an error occurs.

    Example:

    gaussdb=# CALL DBE_SCHEDULER.create_credential('cre_1', 'user1', '');
     create_credential 
    -------------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_credential('cre_1', false);
     drop_credential 
    -----------------
    
    (1 row)
  • DBE_SCHEDULER.ENABLE

    Enables objects and synchronizes them to all CNs.

    The prototype of the DBE_SCHEDULER.ENABLE function is as follows:

    1
    2
    3
    4
    DBE_SCHEDULER.enable(
    name text,
    commit_semantics text                   default 'STOP_ON_FIRST_ERROR'
    )
    
    Table 27 Parameters for DBE_SCHEDULER.ENABLE

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    name

    TEXT

    IN

    No

    Object name. You can specify one or more objects. If you specify multiple objects, separate them with commas (,).

    commit_semantics

    TEXT

    IN

    No

    Commit rules. The following types are supported:
    • 'STOP_ON_FIRST_ERROR': The enabling operation performed before the first error is reported is committed.
    • 'TRANSACTIONAL': Transaction-level commit. The enabling operation performed before an error is reported will be rolled back.
    • 'ABSORB_ERRORS': The system attempts to bypass an error and commit the enabling operation that is performed successfully.

    Example:

    gaussdb=# CALL dbe_scheduler.create_job('job1','PLSQL_BLOCK','begin insert into test1 values(12); end;',0,null,null,null,'DEFAULT_JOB_CLASS',false,false,null,null,null);
    lse, 'test');
     create_job 
    ------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.create_program('program1', 'stored_procedure', 'insert into tb_job_test(key) values(null);', 0, false, '');
     create_program 
    ----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.enable('job1');
     enable 
    --------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.enable('program1', 'STOP_ON_FIRST_ERROR');
     enable 
    --------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_job('job1', true, false, 'STOP_ON_FIRST_ERROR');
     drop_job 
    ----------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_program('program1', false);
     drop_program 
    --------------
    
    (1 row)
  • DBE_SCHEDULER.ENABLE_SINGLE

    Enables a single object and synchronizes it to all CNs.

    The prototype of the DBE_SCHEDULER.ENABLE_SINGLE function is as follows:

    1
    2
    3
    DBE_SCHEDULER.enable_single(
    name text
    )
    
    Table 28 Parameters for DBE_SCHEDULER.ENABLE_SINGLE

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    name

    TEXT

    IN

    No

    Object name.

    Example:

    gaussdb=# CALL dbe_scheduler.create_job('job1','PLSQL_BLOCK','begin insert into test1 values(12); end;',0,null,null,null,'DEFAULT_JOB_CLASS',false,false,null,null,null);
    lse, 'test');
     create_job 
    ------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.enable_single('job1');
     enable_single 
    ---------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_job('job1', true, false, 'STOP_ON_FIRST_ERROR');
     drop_job 
    ----------
    
    (1 row)
  • DBE_SCHEDULER.DISABLE

    Disables multiple objects. The value of name is a character string separated by commas (,). Each character string separated by commas (,) is an object. Operations are synchronized only when operation synchronization is enabled.

    The prototype of the DBE_SCHEDULER.DISABLE function is as follows:

    1
    2
    3
    4
    5
    DBE_SCHEDULER.disable(
    name text,
    force boolean                           default false,
    commit_semantics text                   default 'STOP_ON_FIRST_ERROR'
    )
    
    Table 29 Parameters for DBE_SCHEDULER.DISABLE

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    name

    TEXT

    IN

    No

    Object name.

    force

    BOOLEAN

    IN

    No

    Specifies whether to disable an object.
    • TRUE: The object is disabled regardless of whether other objects depend on it.
    • FALSE: No object can depend on the object. Otherwise, an error occurs.

    commit_semantics

    TEXT

    IN

    No

    Commit rules. The following types are supported:
    • 'STOP_ON_FIRST_ERROR': The disabling operation performed before the first error is reported is committed.
    • 'TRANSACTIONAL': Transaction-level commit. The disabling operation performed before an error is reported will be rolled back.
    • 'ABSORB_ERRORS': The system attempts to bypass an error and commit the disabling operation that is performed successfully.

    Example:

    gaussdb=# CALL dbe_scheduler.create_job('job1','PLSQL_BLOCK','begin insert into test1 values(12); end;',0,null,null,null,'DEFAULT_JOB_CLASS',false,false,null,null,null);
     create_job 
    ------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.create_program('program1', 'stored_procedure', 'insert into tb_job_test(key) values(null);', 0, false, '');
     create_program 
    ----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.disable('job1');
     disable 
    ---------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.disable('program1', false, 'STOP_ON_FIRST_ERROR');
     disable 
    ---------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_job('job1', true, false, 'STOP_ON_FIRST_ERROR');
     drop_job 
    ----------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_program('program1', false);
     drop_program 
    --------------
    
    (1 row)
  • DBE_SCHEDULER.DISABLE_SINGLE

    Disables a single object. Operations are synchronized only when operation synchronization is enabled.

    The prototype of the DBE_SCHEDULER.DISABLE_SINGLE function is as follows:

    1
    2
    3
    4
    DBE_SCHEDULER.disable_single(
    name text,
    force boolean                           default false
    )
    
    Table 30 Parameters for DBE_SCHEDULER.DISABLE_SINGLE

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    name

    TEXT

    IN

    No

    Object name.

    force

    BOOLEAN

    IN

    No

    Specifies whether to disable an object.
    • TRUE: The object is disabled regardless of whether other objects depend on it.
    • FALSE: No object can depend on the object. Otherwise, an error occurs.

    Example:

    gaussdb=# CALL dbe_scheduler.create_job('job1','PLSQL_BLOCK','begin insert into test1 values(12); end;',0,null,null,null,'DEFAULT_JOB_CLASS',false,false,null,null,null);
     create_job 
    ------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.disable_single('job1', false);
     disable_single 
    ----------------
    
    (1 row)
    
    gaussdb=# CALL DBE_SCHEDULER.drop_job('job1', true, false, 'STOP_ON_FIRST_ERROR');
     drop_job 
    ----------
    
    (1 row)
  • DBE_SCHEDULER.EVAL_CALENDAR_STRING

    Analyzes the scheduling task period.

    Return type: timestamp with time zone

    The prototype of the DBE_SCHEDULER.EVAL_CALENDAR_STRING function is as follows:

    1
    2
    3
    4
    5
    DBE_SCHEDULER.evaluate_calendar_string(
    IN calendar_string text,
    IN start_date timestamp with time zone,
    IN return_date_after timestamp with time zone
    )return timestamp with time zone
    
    Table 31 Parameters for DBE_SCHEDULER.EVAL_CALENDAR_STRING

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    calendar_string

    TEXT

    IN

    No

    Date string of a scheduled task.

    start_date

    TIMESTAMP WITH TIME ZONE

    IN

    No

    Start time of a scheduled task.

    return_date_after

    TIMESTAMP WITH TIME ZONE

    IN

    No

    Date when a scheduled task is returned.

    Example:

    gaussdb=# CALL DBE_SCHEDULER.eval_calendar_string('FREQ=DAILY; BYHOUR=6;', sysdate, sysdate);
      eval_calendar_string  
    ------------------------
     2023-09-15 06:47:24+08
    (1 row)
    
  • DBE_SCHEDULER.EVALUATE_CALENDAR_STRING

    Analyzes the scheduling task period.

    Return type: timestamp with time zone

    The prototype of the DBE_SCHEDULER.EVALUATE_CALENDAR_STRING function is as follows:

    1
    2
    3
    4
    5
    6
    DBE_SCHEDULER.evaluate_calendar_string(
    IN calendar_string text,
    IN start_date timestamp with time zone,
    IN return_date_after timestamp with time zone,
    OUT next_run_date timestamp with time zone
    )return timestamp with time zone
    
    Table 32 Parameters for DBE_SCHEDULER.EVALUATE_CALENDAR_STRING

    Parameter

    Type

    Input/Output Parameter

    Can Be Empty

    Description

    calendar_string

    TEXT

    IN

    No

    Date string of a scheduled task.

    start_date

    TIMESTAMP WITH TIME ZONE

    IN

    No

    Start time of a scheduled task.

    return_date_after

    TIMESTAMP WITH TIME ZONE

    IN

    No

    Date when a scheduled task is returned.

    next_run_date

    TIMESTAMP WITH TIME ZONE

    OUT

    No

    The next date when a scheduled task is returned.

    Example:

    gaussdb=# CREATE OR REPLACE PROCEDURE pr1(calendar_str text) as
    DECLARE
        start_date        timestamp with time zone;
        return_date_after timestamp with time zone;
        next_run_date     timestamp with time zone;
    BEGIN
        start_date := '2003-2-1 10:30:00.111111+8'::timestamp with time zone;
        return_date_after := start_date;
        DBE_SCHEDULER.evaluate_calendar_string(
            calendar_str,
            start_date, return_date_after, next_run_date);
        DBE_OUTPUT.PRINT_LINE('next_run_date: ' || next_run_date);
        return_date_after := next_run_date;
    END;
    /
    CREATE PROCEDURE
    
    gaussdb=# CALL pr1('FREQ=hourly;INTERVAL=2;BYHOUR=6,10;BYMINUTE=0;BYSECOND=0');
    next_run_date: 2003-02-02 06:00:00+08
     pr1 
    -----
    
    (1 row)