Creating Databases Using REST API

Creating a database via the NuoDB REST API is also possible. See REST API Reference.

Below, we create a database called db1

# show hosts
curl -u domainuser:domainpassword -X GET  \
    -H "Accept: application/json" \
    -H "Content-type: application/json" \
    http://localhost:8888/api/1/hosts/
  
# create database
curl -u domain:bruin -X POST \
    -H "Accept: application/json" \
    -H "Content-type: application/json" \
    -d '{ "name": "db1", 
      "username": "dba", 
      "password": "goalie", 
      
      "options": { 
          "commit": "remote:1", 
          "backoff.reqMinUptime":"30000",
      "groupOptions": { 
          "SMs": {"journal-max-directory-entries": "500"}, 
          "TEs": {"verbose": "sql-statements"} },
      "tagConstraints": { 
          "SMs": {"Demo": "ex:"}, 
          "TEs": {"Demo": "ex:"} }
      "variables": { "HOST": "82808d4d-d85d-4c99-bfe3-e5f76ec71bb5"} }' \
    http://localhost:8888/api/1/databases

The Basics

You must specify the database name for the "name" parameter, the DBA user name for the "username" parameter, and the DBA password for the "password" parameter.

Example:

"name": "db1", "username": "dba", "password": "goalie"

Host and Region

The host should be given as the value in the key/value template variable "HOST". Template variables are described below. This is only required if you are using the Single Host template. The HOST variable needs to be set to the ID for the host in the domain (available via http://hostname:port/api/1/hosts/). The region should be given as the value in the key/value template variable REGION. This is only required if you are using the Minimally Redundant or Multi Host template. A Region distributed database will run in all regions, hence no host nor region selection is required.

Example:

"variables": { "HOST": "82808d4d-d85d-4c99-bfe3-e5f76ec71bb5", "REGION": "us-east-1" }

A list of regions can be found at at http://hostname:port/api/1/regions.

Default Database Options

You may specify one or more key/value pairs that represent database level options, that is, database options that will apply to all processes in the database.

Example:

"options": { "commit": "remote:1", "mem": "2g" }

Process Group Database Options

You may specify database options that only apply to certain process groups, that is, only to transaction engines ("TEs") or storage managers ("SMs").

Example:

"groupOptions": { 
    "SMs": {"journal-max-directory-entries": "500"}, 
    "TEs": {"verbose": "sql-statements"} },

Here we are saying that all storage managers should have the journal-max-directory-entries set to 500 and all transaction engines should have the verbose logging option set to sql-statements. Process groups can optionally be refined by specifying a region, as in "REGION1.TEs" and "REGION2.TEs".

Process Scale-out Requirements

Like host and region, process scale-out requirements are also specified with template variables (variables parameter). They are: SM_MIN, SM_MAX, TE_MIN, and TE_MAX.

Example:

"variables": { "SM_MIN": "2", "SM_MAX": "3" }

Host Tag Constraints

Host tag constraints are specified with the tagConstraints parameter. Tag constraints can be specified per process group.

Example:

"tagConstraints": { "SMs": {"Test": "ex:"}, "TEs": {"Test: "ex:"} }

Again, process groups can optionally be refined by specifying a region, as in "REGION1.TEs" and "REGION2.TEs".