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 using the Single Host template.

# 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", 
      "template": "Single Host",
      "options": { 
          "commit": "remote:1", 
          "backoff.reqMinUptime":"30000",
      "groupOptions": { 
          "SMs": {"journal-max-directory-entries": "500"}, 
          "TEs": {"verbose": "sql-statements"} },
      "tagConstraints": { 
          "SMs": {"Storefront": "ex:"}, 
          "TEs": {"Storefront": "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"

Template

You must specify the template name for the "template" parameter.

Example:

"template": "Single Host"

This should be entered exactly as one of the following four strings (case-sensitive):

Single Host
Minimally Redundant
Multi Host
Region distributed

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" }

This corresponds to settings in the Default Database Options panel in the Automation Console (see Creating Databases Using Automation Console).

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".

This corresponds to the settings in the Process Group Options panel of the Automation Console (see Creating Databases Using Automation Console).

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" }

See Template Variables for other template variable settings. Note: The enforcer will start a maximum of one TE and one SM per database per host.

Host Tag Constraints

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

Example:

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

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