# Change Memory Limits

> **📝 Note**: If you increase the amount of memory available to SingleStore, you must also ensure that your license covers the new amount  Refer to [Determining capacity and usage for your license](https://docs.singlestore.com/db/v9.1/user-and-cluster-administration/maintain-your-cluster/setting-or-replacing-a-license/determining-capacity-and-usage-for-your-license.md) for more information.

## Overview

The [maximum\_table\_memory](https://docs.singlestore.com/db/v9.1/user-and-cluster-administration/maintain-your-cluster/managing-memory/maximum-table-memory.md) and [maximum\_memory](https://docs.singlestore.com/db/v9.1/user-and-cluster-administration/maintain-your-cluster/managing-memory/maximum-memory.md) engine variable values are based on a host's memory capacity at the time SingleStore is deployed. These values can be updated via SQL, Toolbox, or defined in the `memsql.cnf` file of each node. Note that these engine variables have no impact on licensing.

If Toolbox is used to [optimize for NUMA](https://docs.singlestore.com/db/v9.1/reference/singlestore-tools-reference/sdb-admin-commands/optimize.md), then these values are not automatically updated when a host's memory capacity changes. Toolbox sets a value of `maximum_memory` in the `memsql.cnf` file and, if memory is later added to the host, the `memsqld` process will not pick it up. Refer to [Configuring SingleStore for NUMA](https://docs.singlestore.com/db/v9.1/reference/configuration-reference/cluster-configuration/configuring-singlestore-for-numa.md) for more information.

If Toolbox is not used to optimize for NUMA, the database engine sets the value of `maximum_memory`, which is based on the amount of memory at the time the `memsqld` process is started. If memory is later added to the host, the `memsqld` process will pick it up when it's restarted.

In some cases, you may wish to change the memory limit for each node after deploying SingleStore. If you opt to do so, please note the following:

* Decrease the `maximum_table_memory` value before decreasing the `maximum_memory` value.

  If `maximum_memory` is set to a value below `maximum_table_memory`, the value of `maximum_table_memory` is automatically decreased as well, to the extent possible. If Alloc\_table\_memory  (viewable via `SHOW STATUS EXTENDED LIKE 'Alloc_table_memory';)` is sufficiently high, then `maximum_table_memory` *may* be set to an atypically higher value than 90% of `maximum_memory`, which is the default.
* When decreasing the `maximum_table_memory` value, ensure that the value of the Alloc\_table\_memory  summary variable does not exceed the new `maximum_table_memory` value. If attempted, an error will occur and the value will not be set.
* By default, `maximum_memory` is set to 90% of the physical memory on the host, or physical memory minus 10GB, whichever value is greater. SingleStore does not recommend exceeding either of these two limits when setting the `maximum_memory` value.
* When decreasing the `maximum_memory` value, ensure that the value of the Total\_server\_memory summary variable (also viewable via `SHOW STATUS EXTENDED LIKE 'Total_server_memory';`) does not exceed the new `maximum_memory` value. If attempted, an error will occur and the value will not be set.
* Do not set the `maximum_memory` value less than 1GB.

SingleStore recommends that each leaf node is allocated an equal amount of CPU and RAM. Refer to [Calculating Memory Allocation per Host in a Cluster](https://docs.singlestore.com/db/v9.1/user-and-cluster-administration/high-availability-and-disaster-recovery/replicating-data-across-clusters/calculating-memory-allocation-per-host-in-a-cluster.md) for more information.

## Example

The following example illustrates how to update the values of the `maximum_table_memory` and `maximum_memory` variables after adding memory to an 8 GB (8192 MB) virtual machine, or “host,” with an instance of SingleStore non-Docker [cluster-in-a-box,](https://docs.singlestore.com/db/v9.1/deploy/linux.md) which consists of one Master Aggregator node and one leaf node.

Note that you must restart the affected nodes after increasing or decreasing these values.

1. Use the following command to obtain the node IDs from the `MEMSQL_ID` column.
   ```shell
   sdb-admin list-nodes
   ```

2. You can view the current `maximum_table_memory` and `maximum_memory` values of each node by running the following Toolbox commands.

   **Master Aggregator**
   ```shell
   sdb-admin describe-node --property Variables.maximum_table_memory --memsql-id <Master_Aggregator_MEMSQL_ID>

   ```
   ```output

   6014
   ```
   ```shell
   sdb-admin describe-node --property Variables.maximum_memory --memsql-id <Master_Aggregator_MEMSQL_ID>

   ```
   ```output

   7038
   ```
   **Leaf Node**
   ```shell
   sdb-admin describe-node --property Variables.maximum_table_memory --memsql-id <leaf_node_MEMSQL_ID>

   ```
   ```output

   6014
   ```
   ```shell
   sdb-admin describe-node --property Variables.maximum_memory --memsql-id <leaf_node_MEMSQL_ID>

   ```
   ```output

   7038
   ```

3. If you later add an additional 2 GB (2048 MB) of RAM to this host, run the following command to update the memory limits and optimize other related settings.
   ```shell
   sdb-admin optimize
   ```
   This command will automatically reset these memory limits based on the host's memory capacity, and new values will be reflected for both `maximum_table_memory` and `maximum_memory`.

   **Master Aggregator**
   ```shell
   sdb-admin describe-node --property Variables.maximum_table_memory --memsql-id <Master_Aggregator_MEMSQL_ID>

   ```
   ```output

   7829
   ```
   ```shell
   sdb-admin describe-node --property Variables.maximum_memory --memsql-id <Master_Aggregator_MEMSQL_ID>

   ```
   ```output

   8853
   ```
   **Leaf Node**
   ```shell
   sdb-admin describe-node --property Variables.maximum_table_memory --memsql-id <leaf_node_MEMSQL_ID>

   ```
   ```output

   7829
   ```
   ```shell
   sdb-admin describe-node --property Variables.maximum_memory --memsql-id <leaf_node_MEMSQL_ID>

   ```
   ```output

   8853
   ```

4. To pin the Master Aggregator and leaf node's `maximum_memory` at 8 GB (8192 MB), which will allow other applications to use the remaining memory, run the following commands.

   1. First, decrease the `maximum_table_memory` value:

      **Master Aggregator**
      ```shell
      sdb-admin update-config --key maximum_table_memory --value 7209 --memsql-id <Master_Aggregator_MEMSQL_ID>
      ```
      **Leaf Node**
      ```shell
      sdb-admin update-config --key maximum_table_memory --value 7209 --memsql-id <leaf_node_MEMSQL_ID>
      ```

   2. Next, decrease the `maximum_memory` value:

      **Master Aggregator**
      ```shell
      sdb-admin update-config --key maximum_memory --value 8192 --memsql-id <Master_Aggregator_MEMSQL_ID>
      ```
      **Leaf Node**
      ```shell
      sdb-admin update-config --key maximum_memory --value 8192 --memsql-id <leaf_node_MEMSQL_ID>
      ```

5. Restart the cluster.
   ```shell
   sdb-admin restart-node --all
   ```

## View Variable Values

You can confirm that the nodes reflect these new values via a variety of methods.

## Query the Information Schema

```sql
USE information_schema
SELECT * FROM mv_nodes;

```

```output

+----+-----------+------+------+---------------+---------------------+
| ID | IP_ADDR   | PORT | TYPE | MAX_MEMORY_MB | MAX_TABLE_MEMORY_MB |
+----+-----------+------+------+---------------+---------------------+
|  2 | 127.0.0.1 | 3307 | LEAF |          8192 |                7209 |
|  1 | 127.0.0.1 | 3306 | MA   |          8192 |                7209 |
+----+-----------+------+------+---------------+---------------------+
```

**Note**: Columns have been removed to highlight the max\_memory\_mb and the max\_table\_memory\_mb columns.

## Query the Variables

```sql
SELECT @@global.maximum_table_memory;

```

```output

+-------------------------------+
| @@global.maximum_table_memory |
+-------------------------------+
|                          7209 |
+-------------------------------+
```

```sql
SELECT @@global.maximum_memory;

```

```output

+-------------------------+
| @@global.maximum_memory |
+-------------------------+
|                    8192 |
+-------------------------+
```

## Use Toolbox

**Master Aggregator**

```shell
sdb-admin describe-node --property Variables.maximum_table_memory --memsql-id <Master_Aggregator_MEMSQL_ID>

```

```output

7209
```

```shell
sdb-admin describe-node --property Variables.maximum_memory --memsql-id <Master_Aggregator_MEMSQL_ID>

```

```output

8192
```

**Leaf Node**

```shell
sdb-admin describe-node --property Variables.maximum_table_memory --memsql-id <leaf_node_MEMSQL_ID>

```

```output

7209
```

```shell
sdb-admin describe-node --property Variables.maximum_memory --memsql-id <leaf_node_MEMSQL_ID>

```

```output

8192
```

## View the memsql.cnf File

> **📝 Note**: Node configuration folders typically reside in `/var/lib/memsql/`.As the node subfolder names are GUIDs, you can determine which subfolder corresponds to which node by viewing the port number in the `memsql`.cnf file of each subfolder.Refer [memsql.cnf](https://docs.singlestore.com/db/v9.1/reference/configuration-reference/engine-variables/memsql-cnf.md) for more information.

**Master Aggregator**

```shell
cat /var/lib/memsql/<Master_Aggregator_MEMSQL_ID>/memsql.cnf | grep maximum_table_memory

```

```output

maximum_table_memory = 7209
```

```shell
cat /var/lib/memsql/<Master_Aggregator_MEMSQL_ID>/memsql.cnf | grep maximum_memory

```

```output

maximum_memory = 8192
```

**Leaf Node**

```shell
cat /var/lib/memsql/<leaf_node_MEMSQL_ID>/memsql.cnf | grep maximum_table_memory

```

```output

maximum_table_memory = 7209
```

```shell
cat /var/lib/memsql/<leaf_node_MEMSQL_ID>/memsql.cnf | grep maximum_memory

```

```output

maximum_memory = 8192
```

## Related Resources

* Deploy a SingleStore [cluster-in-a-box ](https://docs.singlestore.com/db/v9.1/deploy/linux.md)for testing and development
* Learn more about the [memsql.cnf](https://docs.singlestore.com/db/v9.1/reference/configuration-reference/engine-variables/memsql-cnf.md) file
* [Calculating Memory Allocation per Host in a Cluster](https://docs.singlestore.com/db/v9.1/user-and-cluster-administration/high-availability-and-disaster-recovery/replicating-data-across-clusters/calculating-memory-allocation-per-host-in-a-cluster.md)
* [Determining capacity and usage for your license](https://docs.singlestore.com/db/v9.1/user-and-cluster-administration/maintain-your-cluster/setting-or-replacing-a-license/determining-capacity-and-usage-for-your-license.md)
* Learn more about updating the `maximum_table_memory` variable to address the [“Maximum Table Memory” error](https://docs.singlestore.com/db/v9.1/user-and-cluster-administration/maintain-your-cluster/managing-memory/addressing-the-maximum-table-memory-error.md)

***

Modified at: March 8, 2024

Source: [/db/v9.1/user-and-cluster-administration/maintain-your-cluster/managing-memory/change-memory-limits/](https://docs.singlestore.com/db/v9.1/user-and-cluster-administration/maintain-your-cluster/managing-memory/change-memory-limits/)

(An index of the documentation is available at /llms.txt)
