## Module 1: Modifying Global Persistent System Variables

[`tidb_gc_enable`](https://docs.pingcap.com/tidb/stable/system-variables#tidb_gc_enable-new-in-v50) is one of the global persistent TiDB system variables, modify it and observe the result.

### Step 1. Log into the remote Linux

+ Open three SSH connections to your lab virtual machine, by clicking:
  + [Terminal 1](ssh://monitor1-ssh#1)
  + [Terminal 2](ssh://monitor1-ssh#2)
  + [Terminal 3](ssh://monitor1-ssh#3)

+ You will now have three active terminal sessions.

### Step 2. Connect to TiDB Server 1

- In [Terminal 1](ssh://monitor1-ssh#1), execute:

  ```bash
  ./connect-db1.sh
  ```

  ```output
  ...
  tidb:db1>
  ```

### Step 3. Create one more connection to TiDB Server 1

- In [Terminal 2](ssh://monitor1-ssh#2), execute:

  ```bash
  ./connect-db1.sh
  ```

  ```output
  ...
  tidb:db1>
  ```

### Step 4. Connect to TiDB Server 2

- In [Terminal 3](ssh://monitor1-ssh#3), execute:

  ```bash
  ./connect-db2.sh
  ```

  ```output
  ...
  tidb:db2>
  ```

### Step 5. In terminal 1, change `tidb_gc_enable` to `OFF`

+ In [Terminal 1](ssh://monitor1-ssh#1), verify the default value of `tidb_gc_enable`.

  ```sql
  SHOW SESSION VARIABLES LIKE 'tidb_gc_enable';
  ```

  ```output
  tidb:db1> SHOW SESSION VARIABLES LIKE 'tidb_gc_enable';
  +----------------+-------+
  | Variable_name  | Value |
  +----------------+-------+
  | tidb_gc_enable | ON    |
  +----------------+-------+
  1 row in set (0.00 sec)
  ```

  ```sql
  SHOW GLOBAL VARIABLES LIKE 'tidb_gc_enable';
  ```

  ```output
  tidb:db1> SHOW GLOBAL VARIABLES LIKE 'tidb_gc_enable';
  +----------------+-------+
  | Variable_name  | Value |
  +----------------+-------+
  | tidb_gc_enable | ON    |
  +----------------+-------+
  1 row in set (0.00 sec)
  ```

+ Change the value from `ON` to `OFF` globally.

  ```sql
  SET GLOBAL tidb_gc_enable=OFF;
  ```

  ```output
  tidb:db1> SET GLOBAL tidb_gc_enable=OFF;
  Query OK, 0 rows affected (0.06 sec)
  ```

### Step 6. Verify the change result from current session

  ```sql
  SHOW SESSION VARIABLES LIKE 'tidb_gc_enable';
  ```

  ```output
  tidb:db1> SHOW SESSION VARIABLES LIKE 'tidb_gc_enable';
  +----------------+-------+
  | Variable_name  | Value |
  +----------------+-------+
  | tidb_gc_enable | OFF   |
  +----------------+-------+
  1 row in set (0.00 sec)
  ```

  ```sql
  SHOW GLOBAL VARIABLES LIKE 'tidb_gc_enable';
  ```

  ```output
  tidb:db1> SHOW GLOBAL VARIABLES LIKE 'tidb_gc_enable';
  +----------------+-------+
  | Variable_name  | Value |
  +----------------+-------+
  | tidb_gc_enable | OFF   |
  +----------------+-------+
  1 row in set (0.00 sec)
  ```

### Step 7. Verify the change result from another session

- Switch to [Terminal 2](ssh://monitor1-ssh#2), execute:

  ```sql
  SHOW SESSION VARIABLES LIKE 'tidb_gc_enable';
  ```

  ```output
  tidb:db1> SHOW SESSION VARIABLES LIKE 'tidb_gc_enable';
  +----------------+-------+
  | Variable_name  | Value |
  +----------------+-------+
  | tidb_gc_enable | OFF   |
  +----------------+-------+
  1 row in set (0.01 sec)
  ```

  ```sql
  SHOW GLOBAL VARIABLES LIKE 'tidb_gc_enable';
  ```

  ```output
  tidb:db1> SHOW GLOBAL VARIABLES LIKE 'tidb_gc_enable';
  +----------------+-------+
  | Variable_name  | Value |
  +----------------+-------+
  | tidb_gc_enable | OFF   |
  +----------------+-------+
  1 row in set (0.00 sec)
  ```

### Step 8. Verify the change result from another TiDB server

- Switch to [Terminal 3](ssh://monitor1-ssh#3), execute:

  ```sql
  SHOW SESSION VARIABLES LIKE 'tidb_gc_enable';
  ```

  ```output
  tidb:db2> SHOW SESSION VARIABLES LIKE 'tidb_gc_enable';
  +----------------+-------+
  | Variable_name  | Value |
  +----------------+-------+
  | tidb_gc_enable | OFF   |
  +----------------+-------+
  1 row in set (0.01 sec)

  ```

  ```sql
  SHOW GLOBAL VARIABLES LIKE 'tidb_gc_enable';
  ```

  ```output
  tidb:db2> SHOW GLOBAL VARIABLES LIKE 'tidb_gc_enable';
  +----------------+-------+
  | Variable_name  | Value |
  +----------------+-------+
  | tidb_gc_enable | OFF   |
  +----------------+-------+
  1 row in set (0.00 sec)
  ```

### Step 9. Try to change the value of `tidb_gc_enable` on session scope

+ In any terminal, change the value of `tidb_gc_enable` on session scope.

  ```sql
  SET SESSION tidb_gc_enable=ON;
  ```

  ```output
  tidb:db2> SET SESSION tidb_gc_enable=ON;
  ERROR 1229 (HY000): Variable 'tidb_gc_enable' is a GLOBAL variable and should be set with SET GLOBAL
  ```

### Step 10. In all terminals, exit from MySQL client

  ```bash
  EXIT
  ```

### Step 11. Restart the TiDB cluster

- Switch to [Terminal 1](ssh://monitor1-ssh#1), execute the following command.

  ```bash
  tiup cluster restart tidb-test --yes
  ```

  ```output
  ...
  Restarted cluster `tidb-test` successfully
  ```

### Step 12. In all terminals, check the value of `tidb_gc_enable`

+ Verify that in [Terminal 1](ssh://monitor1-ssh#1), [Terminal 2](ssh://monitor1-ssh#2), and [Terminal 3](ssh://monitor1-ssh#3), the value of `tidb_gc_enable` is `OFF`. We use [Terminal 1](ssh://monitor1-ssh#1) as an example. You need to re-connect to TiDB servers because the previous restart disconnected your sessions.

  ```bash
  ./connect-db1.sh
  ```

  ```output
  ...
  tidb:db1>
  ```

  ```sql
  SHOW SESSION VARIABLES LIKE 'tidb_gc_enable';
  ```

  ```output
  tidb:db1> SHOW SESSION VARIABLES LIKE 'tidb_gc_enable';
  +----------------+-------+
  | Variable_name  | Value |
  +----------------+-------+
  | tidb_gc_enable | OFF   |
  +----------------+-------+
  1 row in set (0.01 sec)
  ```

  ```sql
  SHOW GLOBAL VARIABLES LIKE 'tidb_gc_enable';
  ```

  ```output
  tidb:db1> SHOW GLOBAL VARIABLES LIKE 'tidb_gc_enable';
  +----------------+-------+
  | Variable_name  | Value |
  +----------------+-------+
  | tidb_gc_enable | OFF   |
  +----------------+-------+
  1 row in set (0.00 sec)
  ```

### Step 13. In any terminal, restore `tidb_gc_enable` back to `ON`

  ```sql
  SET GLOBAL tidb_gc_enable=ON;
  ```

  ```output
  tidb:db1> SET GLOBAL tidb_gc_enable=ON;
  Query OK, 0 rows affected (0.07 sec)
  ```

### Step 14. Close all terminals

### Summary

The global persistent TiDB system variable can only be configured on a global level, and its effects will be immediately applied across all TiDB servers and sessions in the cluster.
