> ## Documentation Index
> Fetch the complete documentation index at: https://developers.liara.ir/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a database

> Creates a database in one of your networks. To start it from a backup of another of your databases of the same type, send `backupSourceId` and `backupToRestoreName` (only for `mysql`, `mariadb`, `postgres` and `mongodb`).

Your balance must be high enough to cover the database. Your account must be verified. With `teamID`, your role needs the `database.create` permission.



## OpenAPI

````yaml /spec/dbaas.yaml post /v1/databases
openapi: 3.0.1
info:
  title: Databases
  version: 1.0.0
  description: >
    Create managed databases, connect to them, change their plans and

    settings, back them up and restore them, and read their metrics and

    events.


    Supported types: `mysql`, `mariadb`, `postgres`, `mongodb`, `redis`,

    `mssql`, `elasticsearch`, `rabbitmq` and `clickhouse`. Databases are

    created in one of your private networks (see Networks in Apps &

    Deployments).


    ## Connecting


    `GET /v1/databases/{databaseID}` returns the connection details:


    - **From apps in the same network:** `hostname` and `internalPort`.

    - **Over the public network** (if `publicNetwork` is on):
    `network.node.host`
      and `port`.
    - **Credentials:** `username` and `root_password`.


    ## Team permissions


    With `teamID`, each endpoint needs one of the database permissions it

    lists (`view`, `operate` or `manage`). A permission from your role or a

    resource permission on that database both count.
servers:
  - url: https://api.liara.ir
security:
  - bearerAuth: []
tags:
  - name: Databases
    description: Create, list, inspect and delete databases.
  - name: Configuration
    description: Plans, scaling, settings, public network, password and control panel.
  - name: Backups
    description: Back up databases, download backups and import backup files.
  - name: Metrics & Events
    description: >-
      Resource usage, lifecycle events and the progress of background
      operations.
paths:
  /v1/databases:
    post:
      tags:
        - Databases
      summary: Create a database
      description: >-
        Creates a database in one of your networks. To start it from a backup of
        another of your databases of the same type, send `backupSourceId` and
        `backupToRestoreName` (only for `mysql`, `mariadb`, `postgres` and
        `mongodb`).


        Your balance must be high enough to cover the database. Your account
        must be verified. With `teamID`, your role needs the `database.create`
        permission.
      operationId: createDatabase
      parameters:
        - $ref: '#/components/parameters/TeamID'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - hostname
                - type
                - planID
                - network
                - bundlePlanID
              properties:
                hostname:
                  type: string
                  minLength: 3
                  maxLength: 50
                  pattern: ^[a-z0-9][a-z0-9\-]+[a-z0-9]$
                  description: >-
                    The database's name, also its hostname inside the network.
                    Lowercase letters, digits and hyphens; not all digits, and
                    not `localhost`.
                type:
                  $ref: '#/components/schemas/DatabaseType'
                version:
                  type: string
                  description: >-
                    One of the version `value`s for this type from `GET
                    /v1/databases/versions`. Defaults to the newest.
                planID:
                  $ref: '#/components/schemas/DatabasePlanID'
                bundlePlanID:
                  $ref: '#/components/schemas/BundlePlanID'
                network:
                  type: string
                  pattern: ^[0-9a-fA-F]{24}$
                  description: ID of one of your networks.
                publicNetwork:
                  type: boolean
                  default: true
                  description: >-
                    Make the database reachable from the internet. Ignored if
                    the bundle plan doesn't allow it.
                options:
                  $ref: '#/components/schemas/CreateOptions'
                backupSourceId:
                  type: string
                  pattern: ^[0-9a-fA-F]{24}$
                  description: >-
                    ID of the database whose backup to start from. Send together
                    with `backupToRestoreName`.
                backupToRestoreName:
                  type: string
                  maxLength: 100
                  description: >-
                    The backup's `name` from `GET
                    /v1/databases/{databaseID}/backups` of the source database.
            example:
              hostname: my-db
              type: postgres
              version: '17.10'
              planID: small-g2
              bundlePlanID: standard
              network: '000000000000000000000160'
              publicNetwork: false
              options:
                pgvector: true
      responses:
        '200':
          description: The database is being created.
          content:
            application/json:
              schema:
                type: object
                properties:
                  databaseID:
                    type: string
              example:
                databaseID: '000000000000000000000300'
        '400':
          description: >-
            The body or `teamID` is invalid; `network` is missing
            (`network_is_required`); `planID` isn't one of the plans listed here
            (`g1_plan_unavailable`); the bundle plan isn't available; or the
            backup can't be used (wrong type, or backups aren't supported for
            this type).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                statusCode: 400
                error: Bad Request
                message: network_is_required
                data: null
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/NotEnoughBalance'
        '403':
          description: >-
            The PostgreSQL version is deprecated, your account isn't verified
            (`account_verification_required`), or, with `teamID`, you aren't a
            member (`team_not_found`) or your role lacks `database.create`
            (`no_permission`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: The network, the backup source database or the backup doesn't exist.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                statusCode: 404
                error: Not Found
                message: Network not found
                data: null
        '409':
          description: The hostname is already used by one of your databases or apps.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                statusCode: 409
                error: Conflict
                message: Conflict
                data: null
components:
  parameters:
    TeamID:
      name: teamID
      in: query
      required: false
      description: >-
        Run the request in the context of a team you belong to, instead of your
        personal account.
      schema:
        $ref: '#/components/schemas/ObjectID'
      example: '000000000000000000000002'
  schemas:
    DatabaseType:
      type: string
      enum:
        - mysql
        - mariadb
        - postgres
        - mongodb
        - redis
        - mssql
        - elasticsearch
        - rabbitmq
        - clickhouse
    DatabasePlanID:
      type: string
      description: >-
        The database's resource plan. `small-g2` and `medium-g2` don't support
        `mssql` or `clickhouse`, and `small-g2` doesn't support `elasticsearch`.
        See Liara's pricing page for what each plan includes.
      enum:
        - small-g2
        - medium-g2
        - standard-base-g2
        - standard-pro-g2
        - pro-g2
        - pro-plus-g2
        - pro-max-g2
    BundlePlanID:
      type: string
      description: >-
        The bundle plan, which sets backups, metrics retention, editable
        settings and public network access.
      enum:
        - basic
        - standard
        - pro
    CreateOptions:
      type: object
      description: >
        Type-specific options:


        - `mysql`, `mariadb`: `rootPassword` (otherwise one is generated),
        `defaultDBName`, `eventScheduler` (`ON` or `OFF`)

        - `mongodb`: `standaloneReplicaSet` (boolean, default `false`)

        - `postgres`: `postgis`, `pgvector` (booleans, default `false`)

        - `mssql`: `FTS` (full-text search, boolean, default `false`)
      properties:
        rootPassword:
          type: string
        defaultDBName:
          type: string
        eventScheduler:
          type: string
          enum:
            - 'ON'
            - 'OFF'
        standaloneReplicaSet:
          type: boolean
        postgis:
          type: boolean
        pgvector:
          type: boolean
        FTS:
          type: boolean
    Error:
      type: object
      description: Standard error body.
      properties:
        statusCode:
          type: integer
        error:
          type: string
          description: HTTP status text.
        message:
          type: string
          description: What went wrong.
        data:
          type: object
          nullable: true
          description: >-
            Extra details. When present, `code` is a stable, machine-readable
            error code.
          properties:
            code:
              type: string
    ObjectID:
      type: string
      pattern: ^[0-9a-fA-F]{24}$
      description: 24-character hexadecimal ID.
    AuthError:
      type: object
      description: Error body returned when the API token is rejected.
      properties:
        error:
          type: string
  responses:
    Unauthorized:
      description: The API token is missing, invalid or expired.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/AuthError'
          example:
            error: Unauthorized.
    NotEnoughBalance:
      description: Your balance is too low.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            statusCode: 402
            error: Payment Required
            message: Not enough balance.
            data: null
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: 'Send your API token as `Authorization: Bearer <api-token>`.'

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.