---
title: "open_database_connection"
description: "Generated reference for the management action open_database_connection: its description, access metadata, payload contract, and registration status."
slug: /reference/actions/open-database-connection
order: 45
visibility: public
redirects_from: []
---

# open\_database\_connection

Generated automatically from the [published contract sources](/cloud/reference/about/#contract-sources).

A script calls this action over HTTPS at `POST https://tzcloud.dev.turnzero.ai/v1/open_database_connection`, with a bearer credential and the action's payload as the JSON body. An MCP connection lists this action as the tool `tzcloud_open_database_connection`.

OAuth access tokens and minted tokens, including the turnzero command's computer token, are bearer credentials. The action determines which kinds, scopes and grants it accepts ([Sign-in, sessions, and tokens](/cloud/concepts/sign-in-sessions-and-tokens/)).

**Build metadata:** Registered in this build. Registration describes the default dispatcher in this build. It does not guarantee that a caller has the required credential or grant, that a tool is listed for that connection, or that the required service is configured.

## Contract description

Request a one\-hour connection to your application's production database for tools such as `pg_restore`, `pg_dump` or `psql`\. Call when the owner asks to use a PostgreSQL tool against production\. The approved tool can read, change or delete data in that application's production database\. Returns 202 with a pending action and a link the account owner opens in a browser to approve the request\. A decline or expiry changes nothing\. After approval, use the pending action ID in `turnzero db connect --grant <id> -- <tool> [args]`\. A new approval for the same application ends its previous connection\.

## More about this action

The `application` argument identifies your application's production database\. Pass `request_id` to make a repeat safe while its pending action is live\. The same account and `request_id` return that action while it is requested, approved or executing\. After it ends, the identifier starts a new request\.

The 202 response gives `pending_action` and `approval_url`\. Give the person the link to approve or decline in a browser\. Read `read_approval_status` with `pending_action.id`\. On completion, the outcome gives `application`, `connection` and `detail`\. `connection` contains its `id`, the UTC expiry `expires_at` and the full `relay` address\.

Run `turnzero db connect --grant <id> -- <tool> [args]` using the pending action's ID for `<id>`\. The command waits for approval and starts the PostgreSQL tool as a child process\. The command prints no password\. Use tools such as `pg_restore` to import, `pg_dump` to export, or `psql` to connect interactively\.

The connection lasts up to an hour from approval\. It ends at `expires_at`, when the command ends the grant, or when a newer approval replaces it\. A production database move, a move of the application between cells, or application deletion also ends it\. If a platform release cuts the connection short, request a new connection and run the tool again\.

An account suspension can also end the connection\. If it did, request a new approval after the account is active again\.

If opening a replacement fails after the previous grant ends, the previous grant stays ended\. Check `read_approval_status` for the replacement's outcome\.

For development, connect directly with the development database credential\.

`database_not_provisioned` means the application has no production database\. `database_move_in_flight` means a production database move or a move of the application between cells is unfinished\. Both are 409 responses\. With `destructive_class_required`, reconnect under a credential with the destructive class\.

## Access and action metadata

```json
{
  "name": "open_database_connection",
  "resource": "application",
  "tier": "destructive",
  "surface": "tzcloud",
  "addresses": [
    "tzcloud"
  ],
  "product": "cloud",
  "summary": "Request a time-limited connection to your application's production database for standard PostgreSQL tools. Returns 202 with a pending action for browser approval. Approval opens one connection for up to an hour and ends any existing connection for the application. A decline or expiry changes nothing.",
  "annotations": {
    "readOnlyHint": false,
    "destructiveHint": true,
    "openWorldHint": true
  }
}
```

## MCP catalog entry

```json
{
  "name": "open_database_connection",
  "title": "Open a production database connection",
  "tier": "destructive",
  "scenario": "API-L0-32",
  "summary": "Request a one-hour connection to your application's production database for tools such as `pg_restore`, `pg_dump` or `psql`. Call when the owner asks to use a PostgreSQL tool against production. The approved tool can read, change or delete data in that application's production database. Returns 202 with a pending action and a link the account owner opens in a browser to approve the request. A decline or expiry changes nothing. After approval, use the pending action ID in `turnzero db connect --grant <id> -- <tool> [args]`. A new approval for the same application ends its previous connection.",
  "owners": [
    "API-L0-32"
  ]
}
```

## request

| JSON pointer | Description and constraints |
|---|---|
| "" \(root\) | Type: object<br>Required fields: \["application"\] |
| /<wbr>properties/<wbr>application | Your account's application ID from `list_applications`\. The connection is for its production database\.<br><br>Type: string |
| /<wbr>properties/<wbr>request\_id | An optional string you choose\. While the same account's earlier pending action is requested, approved or executing, repeating this value returns that action\. After it ends, the same value starts a new action\. Omit this member to create a new request each time\.<br><br>Type: string |

## response

| JSON pointer | Description and constraints |
|---|---|
| "" \(root\) | The 202 response with the pending action and its approval link\. Read its outcome with `read_approval_status`\. A decline or expiry changes nothing\.<br><br>Type: object<br>Required fields: \["contract\_version","pending\_action","approval\_url"\] |
| /<wbr>properties/<wbr>contract\_version | Required value: 1 |
| /<wbr>properties/<wbr>reference | The short reference the platform recorded your call under: ten lowercase hexadecimal characters, the value in the call’s record row\. Quote it when you report the call\.<br><br>Type: string<br>Pattern: ^\[0\-9a\-f\]\{10\}$ |
| /<wbr>properties/<wbr>pending\_action | The pending action for browser approval\. A completed outcome gives the production database connection\. A failed outcome gives the refusal\.<br><br> |
| /<wbr>properties/<wbr>pending\_action/<wbr>allOf/<wbr>0 | $ref: \#/shapes/pending\_action |
| /<wbr>properties/<wbr>pending\_action/<wbr>allOf/<wbr>1 | Type: object |
| /<wbr>properties/<wbr>pending\_action/<wbr>allOf/<wbr>1/<wbr>properties/<wbr>outcome | The outcome of the approved action, with the application, its time\-limited production connection and the next step\.<br><br>Type: \["object","null"\] |
| /<wbr>properties/<wbr>pending\_action/<wbr>allOf/<wbr>1/<wbr>properties/<wbr>outcome/<wbr>properties/<wbr>application | The ID of the application whose production database the connection reaches\.<br><br>Type: string |
| /<wbr>properties/<wbr>pending\_action/<wbr>allOf/<wbr>1/<wbr>properties/<wbr>outcome/<wbr>properties/<wbr>connection | The approved production database connection\. Use the pending action ID in `turnzero db connect --grant <id>`, and use `expires_at` to see when it expires\.<br><br>Type: object<br>Required fields: \["id","expires\_at","relay"\] |
| /<wbr>properties/<wbr>pending\_action/<wbr>allOf/<wbr>1/<wbr>properties/<wbr>outcome/<wbr>properties/<wbr>connection/<wbr>properties/<wbr>id | The ID of the approved database connection\.<br><br>Type: string |
| /<wbr>properties/<wbr>pending\_action/<wbr>allOf/<wbr>1/<wbr>properties/<wbr>outcome/<wbr>properties/<wbr>connection/<wbr>properties/<wbr>expires\_at | The UTC instant when the connection's grant expires, one hour after approval\.<br><br>Type: string<br>Format: date\-time |
| /<wbr>properties/<wbr>pending\_action/<wbr>allOf/<wbr>1/<wbr>properties/<wbr>outcome/<wbr>properties/<wbr>connection/<wbr>properties/<wbr>relay | The full WebSocket address of the approved connection's relay\.<br><br>Type: string |
| /<wbr>properties/<wbr>pending\_action/<wbr>allOf/<wbr>1/<wbr>properties/<wbr>outcome/<wbr>properties/<wbr>detail | Gives the command route and when the connection ends\.<br><br>Type: string |
| /<wbr>properties/<wbr>approval\_url | The link the person opens in a browser to approve or decline this request\.<br><br>Type: string |
| /<wbr>properties/<wbr>detail | Explains the browser approval and points to `read_approval_status` for the outcome\.<br><br>Type: string |

## Complete payload contract

```json
{
  "request": {
    "type": "object",
    "required": [
      "application"
    ],
    "properties": {
      "application": {
        "type": "string",
        "description": "Your account's application ID from `list_applications`. The connection is for its production database."
      },
      "request_id": {
        "type": "string",
        "description": "An optional string you choose. While the same account's earlier pending action is requested, approved or executing, repeating this value returns that action. After it ends, the same value starts a new action. Omit this member to create a new request each time."
      }
    }
  },
  "response": {
    "type": "object",
    "description": "The 202 response with the pending action and its approval link. Read its outcome with `read_approval_status`. A decline or expiry changes nothing.",
    "required": [
      "contract_version",
      "pending_action",
      "approval_url"
    ],
    "properties": {
      "contract_version": {
        "const": 1
      },
      "reference": {
        "type": "string",
        "pattern": "^[0-9a-f]{10}$",
        "description": "The short reference the platform recorded your call under: ten lowercase hexadecimal characters, the value in the call’s record row. Quote it when you report the call."
      },
      "pending_action": {
        "allOf": [
          {
            "$ref": "#/shapes/pending_action"
          },
          {
            "type": "object",
            "properties": {
              "outcome": {
                "type": [
                  "object",
                  "null"
                ],
                "description": "The outcome of the approved action, with the application, its time-limited production connection and the next step.",
                "properties": {
                  "application": {
                    "type": "string",
                    "description": "The ID of the application whose production database the connection reaches."
                  },
                  "connection": {
                    "type": "object",
                    "required": [
                      "id",
                      "expires_at",
                      "relay"
                    ],
                    "description": "The approved production database connection. Use the pending action ID in `turnzero db connect --grant <id>`, and use `expires_at` to see when it expires.",
                    "properties": {
                      "id": {
                        "type": "string",
                        "description": "The ID of the approved database connection."
                      },
                      "expires_at": {
                        "type": "string",
                        "format": "date-time",
                        "description": "The UTC instant when the connection's grant expires, one hour after approval."
                      },
                      "relay": {
                        "type": "string",
                        "description": "The full WebSocket address of the approved connection's relay."
                      }
                    }
                  },
                  "detail": {
                    "type": "string",
                    "description": "Gives the command route and when the connection ends."
                  }
                }
              }
            }
          }
        ],
        "description": "The pending action for browser approval. A completed outcome gives the production database connection. A failed outcome gives the refusal."
      },
      "approval_url": {
        "type": "string",
        "description": "The link the person opens in a browser to approve or decline this request."
      },
      "detail": {
        "type": "string",
        "description": "Explains the browser approval and points to `read_approval_status` for the outcome."
      }
    }
  }
}
```

## Shared contracts

- [Refusals](/cloud/reference/refusals/): every refusal, by surface, with its cause and its remedy
- [schemas/wire\_error\.schema\.json](/cloud/reference/sources/schemas/wire-error-schema/)
- [schemas/wire\_errors\.json](/cloud/reference/sources/schemas/wire-errors/)
- [schemas/action\_payloads\.json](/cloud/reference/sources/schemas/action-payloads/) (includes shared shapes)
- [management\_api\_contract\.md](/cloud/reference/sources/management-api-contract/)
