# The `api/db/<db_name>/stat` Resource

> The `api/db/<db_name>/stat` resource displays database statistics for the specified database.

> ### For an overview see page eXtremeDB Web Service Resources

> In order to enable access to the eXtremeDB Web Services, the REST server must be started. When using xSQL to start the REST server, the `rest` section must appear in the configuration file. For example:

>         database_name : xsqldb,
>         database_size : 100m,

>         perfmon : {
>             database_size : 64m
>         },

>         rest : {
>             port : 8083
>         }

> (Note that here the `perfmon` section indicates that the eXtremeDB Performance Monitor is to be enabled, and the rest parameter `addr` is omitted which allows the REST server to accept incoming connections on all available network interfaces. See page xSQL Web Services REST Parameters for further information).

> With the REST server started (listening on port 8083) for this xSQL configuration, the ``db` resource` request would display the following:

>         {
>             "databases":

>             [

>                 "xsqldb",

>                 "eXDB_perf"

>             ]

>         }

> To view the database statistics for the `eXDB_perf` database, the following http request

>         http://localhost:8083/api/db/eXDB_perf/stat

> would display the following:

>         {
>             "mem":
>             {
>                 "free_pages": 499728,
>                 "total_pages": 522689,
>                 "page_size": 128
>             },
>             "classes":
>             [
>                 {
>                     "table_name": "Node",
>                     "objects_num": 0,
>                     "versions_num": 0,
>                     "core_pages": 0,
>                     "blob_pages": 0,
>                     "seq_pages": 0,
>                     "core_space": 0,
>                     "indexes":
>                     [
>                         {
>                             "type": 128,
>                             "type_s":
>                             [
>                                 "MCO_IDXST_TYPE_MEM",
>                                 "MCO_IDXST_NATURE_BTREE",
>                                 "MCO_IDXST_FEATURE_OPTIMIZED",
>                                 "MCO_IDXST_FUNCTION_REGULAR"
>                             [
>                             "plabel": "Node.no_idx",
>                             "keys_num": 0,
>                             "pages_num": 1,
>                             "avg_cmp": 1,
>                             "max_cmp": 1,
>                             "btree":
>                             {
>                                 "levels_num": 0,
>                                 "duplicates_num": 0
>                             }
>                         }
>                     ]
>                 },
>                 {
>                     "table_name": "eXDBDatabase",
>                     "objects_num": 1,
>                     "versions_num": 1,
>                     "core_pages": 1,
>                     "blob_pages": 0,
>                     "seq_pages": 0,
>                     "core_space": 128,
>                     "indexes":
>                     [
>                         {
>                             "type": 128,
>                             "type_s":
>                             [
>                                 "MCO_IDXST_TYPE_MEM",
>                                 "MCO_IDXST_NATURE_BTREE",
>                                 "MCO_IDXST_FEATURE_OPTIMIZED",
>                                 "MCO_IDXST_FUNCTION_REGULAR"
>                             [
>                             "plabel": "eXDBDatabase.no_idx",
>                             "keys_num": 1,
>                             "pages_num": 1,
>                             "avg_cmp": 1,
>                             "max_cmp": 1,
>                             "btree":
>                             {
>                                 "levels_num": 0,
>                                 "duplicates_num": 0
>                             }
>                         }
>                     ]
>                 },
>                 {
>                     "table_name": "PerfCounter",
>                     "objects_num": 33,
>                     "versions_num": 33,
>                     "core_pages": 33,
>                     "blob_pages": 0,
>                     "seq_pages": 0,
>                     "core_space": 4224,
>                     "indexes":
>                     [
>                         {
>                             "type": 144,
>                             "type_s":
>                             [
>                                 "MCO_IDXST_TYPE_MEM",
>                                 "MCO_IDXST_NATURE_BTREE",
>                                 "MCO_IDXST_FEATURE_UNIQUE",
>                                 "MCO_IDXST_FEATURE_OPTIMIZED",
>                                 "MCO_IDXST_FUNCTION_REGULAR"
>                             [
>                             "plabel": "PerfCounter.no_idx",
>                             "keys_num": 33,
>                             "pages_num": 4,
>                             "avg_cmp": 2,
>                             "max_cmp": 2,
>                             "btree":
>                             {
>                                 "levels_num": 1,
>                                 "duplicates_num": 0
>                             }
>                         }
>                     ]
>                 },
>                 {
>                     "table_name": "PerfReading",
>                     "objects_num": 270,
>                     "versions_num": 270,
>                     "core_pages": 540,
>                     "blob_pages": 0,
>                     "seq_pages": 0,
>                     "core_space": 69120,
>                     "indexes":
>                     [
>                         {
>                             "type": 128,
>                             "type_s":
>                             [
>                                 "MCO_IDXST_TYPE_MEM",
>                                 "MCO_IDXST_NATURE_BTREE",
>                                 "MCO_IDXST_FEATURE_OPTIMIZED",
>                                 "MCO_IDXST_FUNCTION_REGULAR"
>                             [
>                             "plabel": "PerfReading.rec_idx",
>                             "keys_num": 270,
>                             "pages_num": 23,
>                             "avg_cmp": 3,
>                             "max_cmp": 3,
>                             "btree":
>                             {
>                                 "levels_num": 2,
>                                 "duplicates_num": 0
>                             }
>                         },
>                         {
>                             "type": 128,
>                             "type_s":
>                             [
>                                 "MCO_IDXST_TYPE_MEM",
>                                 "MCO_IDXST_NATURE_BTREE",
>                                 "MCO_IDXST_FEATURE_OPTIMIZED",
>                                 "MCO_IDXST_FUNCTION_REGULAR"
>                             [
>                             "plabel": "PerfReading.stamp_idx",
>                             "keys_num": 270,
>                             "pages_num": 23,
>                             "avg_cmp": 3,
>                             "max_cmp": 3,
>                             "btree":
>                             {
>                                 "levels_num": 2,
>                                 "duplicates_num": 0
>                             }
>                         }
>                     ]
>                 },
>                 {
>                     "table_name": "PerfTimingReading",
>                     "objects_num": 270,
>                     "versions_num": 270,
>                     "core_pages": 1080,
>                     "blob_pages": 0,
>                     "seq_pages": 0,
>                     "core_space": 138240,
>                     "indexes":
>                     [
>                         {
>                             "type": 128,
>                             "type_s":
>                             [
>                                 "MCO_IDXST_TYPE_MEM",
>                                 "MCO_IDXST_NATURE_BTREE",
>                                 "MCO_IDXST_FEATURE_OPTIMIZED",
>                                 "MCO_IDXST_FUNCTION_REGULAR"
>                             [
>                             "plabel": "PerfTimingReading.rec_idx",
>                             "keys_num": 270,
>                             "pages_num": 23,
>                             "avg_cmp": 3,
>                             "max_cmp": 3,
>                             "btree":
>                             {
>                                 "levels_num": 2,
>                                 "duplicates_num": 0
>                             }
>                         },
>                         {
>                             "type": 128,
>                             "type_s":
>                             [
>                                 "MCO_IDXST_TYPE_MEM",
>                                 "MCO_IDXST_NATURE_BTREE",
>                                 "MCO_IDXST_FEATURE_OPTIMIZED",
>                                 "MCO_IDXST_FUNCTION_REGULAR"
>                             [
>                             "plabel": "PerfTimingReading.stamp_idx",
>                             "keys_num": 270,
>                             "pages_num": 23,
>                             "avg_cmp": 3,
>                             "max_cmp": 3,
>                             "btree":
>                             {
>                                 "levels_num": 2,
>                                 "duplicates_num": 0
>                             }
>                         }
>                     ]
>                 }
>             ]
>         }

> To view the database statistics for a simple persistent database, the following http request

>         http://localhost:8083/api/db/diskdb/stat

> where xSQL is started with the following config file:

>         database_name : diskdb,
>         database_size    :  20m,
>         cache_size : 10m,

>         database_filename: "diskdb.dbs", # database file name, string
>         log_filename     : "diskdb.log", # log file name, string

>         runtime_configuration : {
>             debug_library : false,
>             disk_support : true,
>             shared_memory : false,
>             transaction_manager : mursiw
>         },
>         rest : {
>             port : 8083
>         },

>         schema : "
>         #define uint2     unsigned<2>

>         declare database  locatedb;
>         class Employee
>         {
>             string name;
>             uint2 dept_no;

>             unique tree<name> Iname;
>             tree<dept_no>     Idept;
>         };
>         ",

>         db_params: {
>             mem_page_size : 512,
>             disk_page_size : 8192
>         },

>         sql_trace : false,
>         sql_port : 5500,
>         sql_statements : "INSERT INTO Employee(name, dept_no) VALUES (['Luke Skywalker', 'Han Solo', 'Darth Vader'], [1,1,2]);"

> would display the following statistics:

>         {
>             "mem":
>             {
>                 "free_pages": 39513,
>                 "total_pages": 39564,
>                 "page_size": 512
>             },

>             "disk":
>             {
>                 "data_file_size": 147456,
>                 "log_file_size": 4,
>                 "used_database_size": 148992,

>                 "cache":
>                 {
>                     "connection_cache_hits": 0,
>                     "cache_hits": 0,
>                     "cache_misses": 15,
>                     "allocated_pages": 1246,
>                     "used_pages": 13,
>                     "pinned_pages": 10,
>                     "modified_pages": 0,
>                     "dirty_pages": 0,
>                     "copied_pages": 0,
>                     "write_delayed_pages": 0,
>                     "subsequent_reads": 12
>                 }
>             },

>             "classes":
>             [
>                 {
>                     "table_name": "Employee",
>                     "objects_num": 3,
>                     "versions_num": 3,
>                     "core_pages": 3,
>                     "blob_pages": 0,
>                     "core_space": 1536,
>                     "indexes":
>                     [
>                         {
>                             "type": 128,
>                             "type_s":
>                             [
>                                 "MCO_IDXST_TYPE_MEM",
>                                 "MCO_IDXST_NATURE_BTREE",
>                                 "MCO_IDXST_FEATURE_UNIQUE",
>                                 "MCO_IDXST_FEATURE_OPTIMIZED",
>                                 "MCO_IDXST_FUNCTION_REGULAR"
>                             [
>                             "plabel": "Employee.Iname",
>                             "keys_num": 3,
>                             "pages_num": 1,
>                             "avg_cmp": 1,
>                             "max_cmp": 1,
>                             "btree":
>                             {
>                                 "levels_num": 0,
>                                 "duplicates_num": 0
>                             }
>                         },
>                         {
>                             "type": 128,
>                             "type_s":
>                             [
>                                 "MCO_IDXST_TYPE_MEM",
>                                 "MCO_IDXST_NATURE_BTREE",
>                                 "MCO_IDXST_FEATURE_OPTIMIZED",
>                                 "MCO_IDXST_FUNCTION_REGULAR"
>                             [
>                             "plabel": "Employee.Idept_",
>                             "keys_num": 3,
>                             "pages_num": 1,
>                             "avg_cmp": 1,
>                             "max_cmp": 1,
>                             "btree":
>                             {
>                                 "levels_num": 0,
>                                 "duplicates_num": 0
>                             }
>                         }
>                     ]
>                 }
>             ]
>         }

> ## Database Statistics

> ### mem

> The `mem` section displays the following statistics:

> free_pages | The amount of memory available in bytes
> total_pages | The total amount of memory in used by the database
> page_size | The size of each memory page

> ### classes

> The `classes` section displays the following statistics for each class in the database schema:

> table_name | The name of the database class (table)
> objects_num | The total number of objects (rows) of this class (table)
> versions_num | The total number of `MVCC` versions of the objects
> core_pages | The number of pages used for all data except blobs
> blob_pages | The number of pages used by blobs
> seq_pages | The number of pages used by sequences
> core_space | The total number of bytes, not counting blobs
> indexes | An array of index statistics (see below)

> ### indexes array

> type | The index type flags; this numeric value is a combination of `MCO_IDXST_*` constants defined in the `mco.h` header file
> type_s | The array of strings representing the `type` flags (above)
> plabel | The index label
> keys_num | The number of keys in the index
> pages_num | The number of pages used by the index
> avg_cmp | The average number of comparisons needed to locate an element
> max_cmp | The maximum number of comparisons needed to locate an element
> btree | For `btree` indexes only:
> levels_num | The tree height
> duplicates_num | The number of duplicates
> kdtree | For `kdtree` indexes only:
> levels_num | The tree height
> hash | For `hash` indexes only:
> avg_chain_length | The average number of keys in a basket
> max_chain_length | The number maximum number of keys in a basket
> table_size | The size of the hash table
> chains_num | The number of chains
> ptree | For `ptree` indexes only:
> levels_num | The tree height
> duplicates_num | The number of duplicates
> rtree | For `rtree` indexes only:
> levels_num | The tree height
> duplicates_num | The number of duplicates
> meta | For `meta` indexes only:
> disk_pages_num | The number of disk pages

> ## Persistent Database Statistics

> For persistent databases, the following additional sections are displayed:

> ### disk

> The `disk` section displays the following statistics:

> data_file_size | The total size of the database storage
> log_file_size | The total size of the database log file
> used_database_size | Size of the used part of database storage
> cache | The cache section statistics are described below

> ### cache

> The `cache` section displays the following disk cache statistics:

> connection_cache_hits | The number of connection cache hits since the database was opened
> cache_hits | The number of disk manager cache hits since the database was opened
> cache_misses | The number of disk manager cache misses
> allocated_pages | The disk manager cache size in pages
> used_pages | The number of used pages in the disk cache
> pinned_pages | The number of pinned pages; i.e. pages that can't be swapped out
> modified_pages | The number of pages in the cache modified by active transactions
> dirty_pages | The number of dirty pages
> copied_pages | The number of copies of original pages
> write_delayed_pages | The number of write delayed pages
> subsequent_reads | The number of reads of sequentially located pages