Managing Rules

Using commands described in this topic, rules can be displayed, deleted, modified, and saved to or restored from disk. Each of the commands has a gp-wlm command-line equivalent.

Displaying Rules

Use the rule show command to see existing rules. You can show all existing rules or specify a single rule by name.

rule show { all | rule-name }

The rule show all command in this example lists all registered rules:

mdw/gpdb-cluster> rule show all
--- Name ---    ----------- Expression -----------
record_query     gpdb_record(message="all") when session_id:host:pid:usename =~ /.*/
cancel_query     pg_terminate_backend() when session_id:host:pid:runtime > 20
throttle_query       host:throttle_gpdb_query(max_cpu=20) when session_id:host:pid:current_query =~ /.*select count.*/

This example lists a single rule by name:

mdw/gpdb-cluster> rule show throttle_query
--- Name ---    ----------- Expression -----------
throttle_query   host:throttle_gpdb_query(max_cpu=20) when session_id:host:pid:current_query =~ /.*select count.*/

Deleting Rules

The rule delete command removes a rule.

rule delete rule-name

To delete all rules at once, use rule delete all:

rule delete all

If there are no rules, this command returns an error.

Modifying a Rule

Use the rule modify command to alter the expression for an existing rule. You may also remove the transient keyword from the rule declaration to convert it to a persistent rule. Conversion from persistent to transient is not currently supported.

rule modify [transient] name action-name (action-args)
when expression

This example modifies the cancel_query rule to alter the number of seconds a query runs on a host to trigger the rule from 20 to 25:

mdw/gpdb-cluster> rule modify cancel_query pg_terminate_backend() when session_id:host:pid:runtime > 25

Saving Rules to Disk

The rule dump command saves all persistent rules in the cluster to a text file, one rule per line.

rule dump path

If you do not provide the full path to the file, the file is written relative to the directory where you started the gp-wlm session. The user running gp-wlm must have permission to write the file at the specified location. If the file exists, the rule dump command overwrites it.

The following example saves rules to the /home/gpadmin/rules/20150910-1.txt file. If the /home/gpadmin/rules directory does not exist, an error is reported.

mdw/gpdb-cluster> rule dump /home/gpadmin/rules/20150910-1.txt

Importing Rules from Disk

The rule import command imports rules from a file into the active set of rules. Imported rules replace existing rules with the same names. Existing rules with names not present in the file are unchanged.

rule import path

Restoring Rules from Disk

The rule restore command restores all rules from a file, replacing any existing rules. It is equivalent to rule delete=all followed by rule import path.

rule restore path