---
title: "Space and statistics: spacedb, compactdb, optimizedb, plandump, vacuumdb"
description: "Check and reclaim database space with coradb spacedb, compactdb and vacuumdb, update statistics with optimizedb and inspect plans with plandump."
url: "https://www.coradb.ai/manual/admin/admin_space.html"
markdown_url: "https://www.coradb.ai/manual/markdown/admin/admin_space.md"
product: "CoraDB"
version: "1.0"
keywords: "coradb spacedb, coradb compactdb, coradb optimizedb, coradb plandump, coradb vacuumdb, database space, update statistics, plan cache"
---

# Space and statistics: spacedb, compactdb, optimizedb, plandump, vacuumdb

## spacedb

The **coradb spacedb** utility is used to check how much space of database volumes is being used. The tool can show brief aggregated information on database space usage, or detailed descriptions of all volumes and files in use, based on its options. Information returned by the **coradb spacedb** utility includes the volume ID's, names, purpose and total/free space of each volume.

``` bash
coradb spacedb [options] database_name
```

- **coradb** : An integrated utility for the CoraDB service and database management.
- **spacedb** : A command that checks the space in the database. It executes successfully only when the database is in a stopped state.
- *database_name* : The name of the database whose space is to be checked. The path-name to the directory where the database is to be created must not be included.

The following shows \[options\] available with the **coradb spacedb** utility.

**-o, --output-file=FILE**

This option stores the result of checking the space information of *testdb* to a file named *db_output*.

``` bash
coradb spacedb -o db_output testdb
```

**-S, --SA-mode**

This option is used to access a database in standalone, which means it works without processing server; it does not have an argument. If **-S** is not specified, the system recognizes that a database is running in client/server mode.

``` bash
coradb spacedb --SA-mode testdb
```

**-C, --CS-mode**

This option is used to access a database in client/server mode, which means it works in client/server process respectively; it does not have an argument. If **-C** is not specified, the system recognize that a database is running in client/server mode by default.

``` bash
coradb spacedb --CS-mode testdb
```

**--size-unit={PAGE\|M\|G\|T\|H}**

This option specifies the size unit of the space information of the database to be one of PAGE, M(MB), G(GB), T(TB), H(print-friendly). The default value is **H**. If you set the value to H, the unit is automatically determined as follows: M if 1 MB = DB size \< 1024 MB, G if 1 GB = DB size \< 1024 GB.

``` bash
$ coradb spacedb --size-unit=H testdb

Space description for database 'testdb' with pagesize 16.0K. (log pagesize: 16.0K)

type                purpose            volume_count         used_size           free_size           total_size
PERMANENT           PERMANENT DATA                2            61.0 M             963.0 M                1.0 G
PERMANENT           TEMPORARY DATA                1            12.0 M             500.0 M              512.0 M
TEMPORARY           TEMPORARY DATA                1            40.0 M              88.0 M              128.0 M
-                   -                             4           113.0 M               1.5 G                1.6 G

Space description for all volumes:
volid               type                purpose             used_size           free_size           total_size         volume_name
    0               PERMANENT           PERMANENT DATA         60.0 M             452.0 M              512.0 M         /home1/coradb/testdb
    1               PERMANENT           PERMANENT DATA          1.0 M             51.0 M              512.0 M         /home1/coradb/testdb_x001
    2               PERMANENT           TEMPORARY DATA         12.0 M             500.0 M              512.0 M         /home1/coradb/testdb_x002
32766               TEMPORARY           TEMPORARY DATA         40.0 M              88.0 M              128.0 M         /home1/coradb/testdb_t32766

LOB space description file:/home1/coradb/lob
```

**-s, --summarize**

This option aggregates volume count, used size, free size and total size by volume types and purposes. There are three classes of volumes: permanent volumes with permanent data, permanent volumes with temporary data and temporary volume with temporary data; no temporary volumes with permanent data. Last row shows the total values for all types of volumes.

``` bash
$ coradb spacedb -s testdb

Space description for database 'testdb' with pagesize 16.0K. (log pagesize: 16.0K)

type                purpose            volume_count         used_size           free_size           total_size
PERMANENT           PERMANENT DATA                2            61.0 M             963.0 M                1.0 G
PERMANENT           TEMPORARY DATA                1            12.0 M             500.0 M              512.0 M
TEMPORARY           TEMPORARY DATA                1            40.0 M              88.0 M              128.0 M
-                   -                             4           113.0 M               1.5 G                1.6 G
```

**-p, --purpose**

This option shows detailed information on the purpose of stored data. The information includes number of files, used size, size of file tables, reserved sectors size and total size.

``` text
Space description for database 'testdb' with pagesize 16.0K. (log pagesize: 16.0K)

Detailed space description for files:
data_type           file_count           used_size          file_table_size     reserved_size       total_size
INDEX                       17               0.3 M                    0.3 M            16.5 M           17.0 M
HEAP                        28               7.6 M                    0.4 M            26.0 M           34.0 M
SYSTEM                       8               0.4 M                    0.1 M             7.5 M            8.0 M
TEMP                        10               0.0 M                    0.2 M            49.8 M           50.0 M
-                           63               8.2 M                    1.0 M            99.8 M          109.0 M
```


## compactdb

The **coradb compactdb** utility is used to secure unused space of the database volume. In case the database server is not running (offline), you can perform the job in standalone mode. In case the database server is running, you can perform it in client-server mode.

> **Note:**
> The **coradb compactdb** utility secures the space being taken by OIDs of deleted objects and by class changes. When an object is deleted, the space taken by its OID is not immediately freed because there might be other objects that refer to the deleted one.
>
> Therefore, when you make a table to reuse OIDs, it is recommended to use a REUSE_OID option as below.
>
> ``` sql
> CREATE TABLE tbl REUSE_OID
> (
>     id INT PRIMARY KEY,
>     b VARCHAR
> );
> ```
>
> However, a table with a REUSE_OID option cannot be referred by the other table. That is, this table cannot be used as a type of the other table.
>
> ``` sql
> CREATE TABLE reuse_tbl (a INT PRIMARY KEY) REUSE_OID;
> CREATE TABLE tbl_1 ( a reuse_tbl);
> ```
>
> ``` text
> ERROR: The class 'reuse_tbl' is marked as REUSE_OID and is non-referable. Non-referable classes can't be the domain of an attribute and their instances' OIDs cannot be returned.
> ```
>
> To see details of REUSE_OID, please refer to [REUSE_OID](https://www.coradb.ai/manual/sql/schema/table_stmt.html#reuse_oid).


Reference to the object deleted during compacting is displayed as **NULL**, which means this can be reused by OIDs.

``` bash
coradb compactdb [options] database_name [class_name], class_name2, ...]
```

- **coradb**: An integrated utility for the CoraDB service and database management.
- **compactdb**: A command that compacts the space of the database so that OIDs assigned to deleted data can be reused.
- *database_name*: The name of the database whose space is to be compacted. The path name to the directory where the database is to be created must not be included.
- *class_name_list*: You can specify the list of tables names that you want to compact space after a database name; the **-i** option cannot be used together. If you use the lists on client/server mode, it skips securing space taken by objects such as catalog, delete files and tracker, etc.

**-I**, **-c**, **-d**, **-p** options are applied in client/server mode only.

The following shows \[options\] available with the **coradb compactdb** utility.

**-v, --verbose**

You can output messages that shows which class is currently being compacted and how many instances have been processed for the class by using the **-v** option.

``` bash
coradb compactdb -v testdb
```

**-S, --SA-mode**

This option specifies to compact used space in standalone mode while database server is not running; no argument is specified. If the **-S** option is not specified, system recognizes that the job is executed in client/server mode.

``` bash
coradb compactdb --SA-mode testdb
```

**-C, --CS-mode**

This option specifies to compact used space in client/server mode while database server is running; no argument is specified. Even though this option is omitted, system recognizes that the job is executed in client/server mode.

**-i, --input-class-file=FILE**

You can specify an input file name that contains the table name with this option. Write one table name in a single line; invalid table name is ignored. Note that you cannot specify the list of the table names after a database name in case of you use this option. If you use this option on client/server mode, it skips securing space taken by objects such as catalog, delete files and tracker, etc.

The following options can be used in client/server mode only.

**-p, --pages-commited-once=NUMBER**

You can specify the number of maximum pages that can be committed once with this option. The default value is 10, the minimum value is 1, and the maximum value is 10. The less option value is specified, the more concurrency is enhanced because the value for class/instance lock is small; however, it causes slowdown on operation, and vice versa.

``` bash
coradb compactdb --CS-mode -p 10 testdb tbl1, tbl2, tbl5
```

**-d, --delete-old-repr**

You can delete an existing table representation (schema structure) from catalog with this option. Generally you'd better keep the existing table representation because schema updating cost will be saved when you keep the status as referring to the past schema for the old records.

**-I, --Instance-lock-timeout=NUMBER**

You can specify a value of instance lock timeout with this option. The default value is 2 (seconds), the minimum value is 1, and the maximum value is 10. The less option value is specified, the more operation speeds up. However, the number of instances that can be processed becomes smaller, and vice versa.

**-c, --class-lock-timeout=NUMBER**

You can specify a value of instance lock timeout with this option. The default value is 10 (seconds), the minimum value is 1, and the maximum value is 10. The less option value is specified, the more operation speeds up. However, the number of tables that can be processed becomes smaller, and vice versa.


## vacuumdb

**coradb vacuumdb** removes the old row versions and index entries left behind by updates and deletes (see [MVCC and VACUUM](https://www.coradb.ai/manual/sql/transaction_mvcc.html)). The database server normally does this continuously in the background; vacuumdb runs the same cleanup on demand for a stopped database.

```text
coradb vacuumdb [option] database_name
```

| Option | Meaning |
|---|---|
| **-S**, **--SA-mode** | Standalone mode: the database server must be stopped |
| **-C**, **--CS-mode** | Client-server mode; currently not available (`Vacuumdb is temporary not available for client-server mode`) |

```bash
coradb server stop testdb
coradb vacuumdb -S testdb
```

The SQL statement **VACUUM** does the same in a standalone corasql session (`corasql -S`).


## optimizedb

Updates statistical information such as the number of objects, the number of pages to access, and the distribution of attribute values.

``` bash
coradb optimizedb [option] database_name
```

- **coradb**: An integrated utility for the CoraDB service and database management.
- **optimizedb**: Updates the statistics information, which is used for cost-based query optimization of the database. If the option is specified, only the information of the specified class is updated.
- *database_name*: The name of the database whose cost-based query optimization statistics are to be updated.

The following shows \[option\] available with the **coradb optimizedb** utility.

**-n, --class-name**

The following example shows how to update the query statistics information of the given class by using the **-n** option.

``` bash
coradb optimizedb -n event_table testdb
```

The following example shows how to update the query statistics information of all classes in the database.

``` bash
coradb optimizedb testdb
```


## plandump

The **coradb plandump** utility is used to display information on the query plans stored (cached) on the server.

``` bash
coradb plandump [options] database_name 
```

- **coradb**: An integrated utility for the CoraDB service and database management.
- **plandump**: A utility that displays the query plans stored in the current cache of a specific database.
- *database_name*: The name of the database where the query plans are to be checked or dropped from its server cache.

If no option is used, it checks the query plans stored in the cache.

``` bash
coradb plandump testdb
```

The following shows \[options\] available with the **coradb plandump** utility.

**-d, --drop**

This option drops the query plans stored in the cache.

``` bash
coradb plandump -d testdb
```

**-o, --output-file=FILE**

This option stores the results of the query plans stored in the cache to a file.

``` bash
coradb plandump -o output.txt testdb
```
