A newer version of this documentation is available.

View Latest

Getting System Information

  • concept
    +
    N1QL has a system catalog that stores metadata about a database. The system catalog is a namespace called system.

    There is a keyspace for each type of artifact. The keyspace names are plural in order to avoid conflicting with N1QL keywords.

    Logical Hierarchy

    N1QL has the following artifacts:

    • Datastores

      Datastores are similar to sites. A datastore is a database deployment, for example, a server cluster, cloud service, or mobile installation. It is analogous to a relation database instance.

    • Namespaces

      Namespaces are similar to pools. A namespace is a unit of authorization, resource allocation, and tenancy. It is analogous to a relational database or schema.

    • Keyspaces

      Keyspaces map to buckets in Couchbase Server. A keyspace is a set of documents that may vary in structure. It is a unit of authorization and resource allocation. It is analogous to a relational database table.

    • Indexes

      An index on a keyspace. It is analogous to a relational database index. Types of indexes include b-tree (ForestDB or MOI) and view indexes.

    • Dual

      The dual keyspace has been added for evaluating constant expressions. It contains a single entry with no attributes.

    Querying Datastores

    You can query datastores using the SELECT statement as follows:

    SELECT * FROM system:datastores

    The query returns the following attributes:

    • id: string (id for the datastore)

    • url: string (URL for the datastore instance)

    Querying Namespaces

    You can query namespaces using the SELECT statement as follows:

    SELECT * FROM system:namespaces

    The query returns the following attributes:

    • id: string (id for the namespace)

    • name: string (name for the namespace)

    • datastore_id: string (id for the datastore to which the namespace belongs)

    Querying Keyspaces

    You can query keyspaces using the SELECT statement as follows:

    SELECT * FROM system:keyspaces

    The query returns the following attributes:

    • id: string (id for the keyspace)

    • name: string (name for the keyspace)

    • namespace_id: string (id for the namespace to which the keyspace belongs)

    • datastore_id: string (id for the datastore to which the keyspace belongs)

    Querying Indexes

    You can query indexes using the SELECT statement as follows:

    SELECT * FROM system:indexes

    The query returns the following attributes:

    • id: string (id for the index)

    • name: string (name for the index)

    • index_key: array of strings (list of index keys)

    • using: string (type of index, for example, gsi)

    • state: string (state of index, for example, online)

    • keyspace_id: string (id for the keyspace to which the index belongs)

    • namespace_id: string (id for the namespace to which the index belongs)

    • datastore_id: string (id for the datastore to which the index belongs)

    Querying Dual

    You can use dual to evaluate constant expressions.

    SELECT 2+5 FROM system:dual

    The query returns the result of the expression, 7 in this case.