Skip to content

CREATE SPACE Syntax

CREATE SPACE [IF NOT EXISTS] <space_name>
   [(partition_num = <part_num>, replica_factor = <raft_copy>, charset = <charset>, collate = <collate>)]

This statement creates a new space with the given name. SPACE is a region that provides physically isolated graphs in Nebula Graph. An error occurs if the database exists.

IF NOT EXISTS

You can use the If NOT EXISTS keywords when creating spaces. This keyword automatically detects if the corresponding space exists. If it does not exist, a new one is created. Otherwise, no space is created.

NOTE: The space existence detection here only compares the space name (excluding properties).

Space Name

  • space_name

    The name uniquely identifies the space in a cluster. The rules for the naming are given in Schema Object Names

Customized Space Options

When creating a space, the following four customized options can be given:

  • partition_num

    partition_num specifies the number of partitions in one replica. The default value is 100. It is usually 5 times the number of hard disks in the cluster.

  • replica_factor

    replica_factor specifies the number of replicas in the cluster. The default replica factor is 1. The suggested number is 3 in cluster. It is usually 3 in production. Due to the majority voting principle, it must set to be odd.

  • charset

    charset is short for character set. A character set is a set of symbols and encodings. The default value is utf8.

  • collate

    A collation is a set of rules for comparing characters in a character set. The default value is utf8_bin.

However, if no option is given, Nebula Graph will create the space with the default partition number, replica factor, charset and collate.

Example

nebula> CREATE SPACE my_space_1; -- create space with default partition number and replica factor
nebula> CREATE SPACE my_space_2(partition_num=10); -- create space with default replica factor
nebula> CREATE SPACE my_space_3(replica_factor=1); -- create space with default partition number
nebula> CREATE SPACE my_space_4(partition_num=10, replica_factor=1);

Checking Partition Distribution

On some large clusters, due to the different startup time, the partition distribution may be unbalanced. You can check the machine and distribution by the following command (SHOW HOSTS).

nebula> SHOW HOSTS;
================================================================================================
| Ip            | Port  | Status | Leader count | Leader distribution | Partition distribution |
================================================================================================
| 192.168.8.210 | 34600 | online | 13           | test: 13            | test: 37               |
------------------------------------------------------------------------------------------------
| 192.168.8.210 | 34900 | online | 12           | test: 12            | test: 38               |
------------------------------------------------------------------------------------------------

If all the machines are online status, but the partition distribution is unbalanced, you can use the following command (BALANCE LEADER) to redistribute the partitions.

nebula> BALANCE LEADER;

Details see SHOW HOSTS and BALANCE.


Last update: April 8, 2021