Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To get total size of all the forests which are attached to a particular database

Tags:

marklogic

I am trying to get total size of all the forests which are attached to a particular database.

Using below code I have got the size of all individual forests, but stuck on how to achieve the solution:

for $db-id in xdmp:databases()
let $db-name := xdmp:database-name($db-id)
for $forests in xdmp:forest-status(xdmp:database-forests(xdmp:database($db-name)))
let $space := $forests//forest:device-space
let $f_name := $forests//forest:forest-name
for $stand in $forests//forest:stands
let $f_size := fn:sum($stand/forest:stand/forest:disk-size)
like image 964
Saahil Gupta Avatar asked Mar 03 '16 07:03

Saahil Gupta


People also ask

How do you determine the size of a database?

The size of the database is the space the files physically consume on disk. You can find this with: select sum(bytes)/1024/1024 size_in_mb from dba_data_files; But not all this space is necessarily allocated.

What is a database forest?

A forest is a collection of XML, JSON, text, or binary documents. Forests are created on hosts and attached to databases to appear as a contiguous set of content for query purposes. A forest can only be attached to one database at a time.

What is MarkLogic forest?

A forest also contains a separate on-disk Large Data Directory for storing large objects such as large binary documents. MarkLogic Server stores large objects separately to optimize memory usage, disk usage, and merge time. A small object is stored directly in a stand as a fragment.


1 Answers

I think you are looking for something like:

xquery version "1.0-ml";

declare namespace forest = "http://marklogic.com/xdmp/status/forest";

for $db-id in xdmp:databases()
let $db-name := xdmp:database-name($db-id)
let $db-size :=
  fn:sum(
    for $f-id in xdmp:database-forests($db-id)
    let $f-status := xdmp:forest-status($f-id)
    let $space := $f-status/forest:device-space
    let $f-name := $f-status/forest:forest-name
    let $f-size :=
      fn:sum(
        for $stand in $f-status/forest:stands/forest:stand
        let $stand-size := $stand/forest:disk-size/fn:data(.)
        return $stand-size
      )
    return $f-size
  )
order by $db-size descending
return $db-name || " = " || $db-size

HTH!

like image 181
grtjn Avatar answered Sep 19 '22 20:09

grtjn