---
title: Export D1 Database as SQL
---

[Skip to content](#_top)

[API Reference](https://developers.cloudflare.com/api/go)

[D1](https://developers.cloudflare.com/api/go/resources/d1)

[Database](https://developers.cloudflare.com/api/go/resources/d1/subresources/database)

Copy Markdown

Open in **Claude**Open in **ChatGPT**Open in **Cursor**

---

**Copy Markdown****View as Markdown**

# Export D1 Database as SQL

client.D1.Database.Export(ctx, databaseID, params) (\*[DatabaseExportResponse](<https://developers.cloudflare.com/api/go/resources/d1#(resource)%20d1.database%20%3E%20(model)%20DatabaseExportResponse%20%3E%20(schema)>), error)

POST/accounts/{account\_id}/d1/database/{database\_id}/export

Export the SQL contents of a D1 database and return a URL where they can be downloaded. Note: this process may take some time for larger DBs, during which your D1 will be unavailable to serve queries. To avoid blocking your DB unnecessarily, an in-progress export must be continually polled or will automatically cancel.

##### Security

<details>

<summary>API Token</summary>



The preferred authorization scheme for interacting with the Cloudflare API. <a href="https://developers.cloudflare.com/fundamentals/api/get-started/create-token/">Create a token</a>.

**Example:**<code>Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY</code>

</details>

<details>

<summary>API Email + API Key</summary>



The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

**Example:**<code>X-Auth-Email: user@example.com</code>

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

**Example:**<code>X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194</code>

</details>

##### ParametersExpand Collapse

databaseID string

D1 database identifier (UUID).

[Link to this property](<#(resource)%20d1.database%20%3E%20(method)%20export%20%3E%20(params)%20default%20%3E%20(param)%20database_id%20%3E%20(schema)>)

<details>

<summary>

params DatabaseExportParams

</summary>

AccountID param.Field\[string]

Path param: Account identifier tag.

maxLength32

<a href="#(resource)%20d1.database%20%3E%20(method)%20export%20%3E%20(params)%20default%20%3E%20(param)%20account_id">Link to this property</a>

<details>

<summary>

OutputFormat param.Field\[<a href="https://developers.cloudflare.com/api/go/resources/d1/subresources/database/methods/export#(resource)%20d1.database%20%3E%20(method)%20export%20%3E%20(params)%20default%20%3E%20(param)%20output_format%20%3E%20(schema)">DatabaseExportParamsOutputFormat</a>]

Body param: Specifies that you will poll this endpoint until the export completes

</summary>

const DatabaseExportParamsOutputFormatPolling <a href="https://developers.cloudflare.com/api/go/resources/d1/subresources/database/methods/export#(resource)%20d1.database%20%3E%20(method)%20export%20%3E%20(params)%20default%20%3E%20(param)%20output_format%20%3E%20(schema)">DatabaseExportParamsOutputFormat</a> = "polling"

<a href="#(resource)%20d1.database%20%3E%20(method)%20export%20%3E%20(params)%20default%20%3E%20(param)%20output_format%20%3E%20(schema)%20%3E%20(member)%200">Link to this property</a>

</details>

<a href="#(resource)%20d1.database%20%3E%20(method)%20export%20%3E%20(params)%20default%20%3E%20(param)%20output_format">Link to this property</a>

CurrentBookmark param.Field\[string]Optional

Body param: To poll an in-progress export, provide the current bookmark (returned by your first polling response)

<a href="#(resource)%20d1.database%20%3E%20(method)%20export%20%3E%20(params)%20default%20%3E%20(param)%20current_bookmark">Link to this property</a>

<details>

<summary>

DumpOptions param.Field\[<a href="https://developers.cloudflare.com/api/go/resources/d1/subresources/database/methods/export#(resource)%20d1.database%20%3E%20(method)%20export%20%3E%20(params)%20default%20%3E%20(param)%20dump_options%20%3E%20(schema)">DatabaseExportParamsDumpOptions</a>]Optional

Body param

</summary>

NoData boolOptional

Export only the table definitions, not their contents

<a href="#(resource)%20d1.database%20%3E%20(method)%20export%20%3E%20(params)%20default%20%3E%20(param)%20dump_options%20%3E%20(schema)%20%3E%20(property)%20no_data">Link to this property</a>

NoSchema boolOptional

Export only each table’s contents, not its definition

<a href="#(resource)%20d1.database%20%3E%20(method)%20export%20%3E%20(params)%20default%20%3E%20(param)%20dump_options%20%3E%20(schema)%20%3E%20(property)%20no_schema">Link to this property</a>

Tables \[]stringOptional

Filter the export to just one or more tables. Passing an empty array is the same as not passing anything and means: export all tables.

<a href="#(resource)%20d1.database%20%3E%20(method)%20export%20%3E%20(params)%20default%20%3E%20(param)%20dump_options%20%3E%20(schema)%20%3E%20(property)%20tables">Link to this property</a>

</details>

<a href="#(resource)%20d1.database%20%3E%20(method)%20export%20%3E%20(params)%20default%20%3E%20(param)%20dump_options">Link to this property</a>

</details>

[Link to this property](<#(resource)%20d1.database%20%3E%20(method)%20export%20%3E%20(params)%20default>)

##### ReturnsExpand Collapse

<details>

<summary>

type DatabaseExportResponse struct{…}

</summary>

AtBookmark stringOptional

The current time-travel bookmark for your D1, used to poll for updates. Will not change for the duration of the export task.

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseExportResponse%20%3E%20(schema)%20%3E%20(property)%20at_bookmark">Link to this property</a>

Error stringOptional

Only present when status = ‘error’. Contains the error message.

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseExportResponse%20%3E%20(schema)%20%3E%20(property)%20error">Link to this property</a>

Messages \[]stringOptional

Logs since the last time you polled

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseExportResponse%20%3E%20(schema)%20%3E%20(property)%20messages">Link to this property</a>

<details>

<summary>

Result DatabaseExportResponseResultOptional

Only present when status = ‘complete’

</summary>

Filename stringOptional

The generated SQL filename.

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseExportResponse%20%3E%20(schema)%20%3E%20(property)%20result%20%3E%20(property)%20filename">Link to this property</a>

SignedURL stringOptional

The URL to download the exported SQL. Available for one hour.

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseExportResponse%20%3E%20(schema)%20%3E%20(property)%20result%20%3E%20(property)%20signed_url">Link to this property</a>

</details>

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseExportResponse%20%3E%20(schema)%20%3E%20(property)%20result">Link to this property</a>

<details>

<summary>

Status DatabaseExportResponseStatusOptional

</summary>

One of the following:

const DatabaseExportResponseStatusComplete DatabaseExportResponseStatus = "complete"

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseExportResponse%20%3E%20(schema)%20%3E%20(property)%20status%20%3E%20(member)%200">Link to this property</a>

const DatabaseExportResponseStatusError DatabaseExportResponseStatus = "error"

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseExportResponse%20%3E%20(schema)%20%3E%20(property)%20status%20%3E%20(member)%201">Link to this property</a>

</details>

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseExportResponse%20%3E%20(schema)%20%3E%20(property)%20status">Link to this property</a>

Success boolOptional

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseExportResponse%20%3E%20(schema)%20%3E%20(property)%20success">Link to this property</a>

Type DatabaseExportResponseTypeOptional

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseExportResponse%20%3E%20(schema)%20%3E%20(property)%20type">Link to this property</a>

</details>

[Link to this property](<#(resource)%20d1.database%20%3E%20(model)%20DatabaseExportResponse%20%3E%20(schema)>)

### Export D1 Database as SQL

Go

HTTPTypeScriptPythonGoTerraform

```
package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/d1"
  "github.com/cloudflare/cloudflare-go/option"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  response, err := client.D1.Database.Export(
    context.TODO(),
    "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    d1.DatabaseExportParams{
      AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
      OutputFormat: cloudflare.F(d1.DatabaseExportParamsOutputFormatPolling),
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", response.AtBookmark)
}
```

200 example

```
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "at_bookmark": "at_bookmark",
    "error": "error",
    "messages": [
      "string"
    ],
    "result": {
      "filename": "filename",
      "signed_url": "signed_url"
    },
    "status": "complete",
    "success": true,
    "type": "export"
  },
  "success": true
}
```

##### Returns Examples

200 example

```
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "at_bookmark": "at_bookmark",
    "error": "error",
    "messages": [
      "string"
    ],
    "result": {
      "filename": "filename",
      "signed_url": "signed_url"
    },
    "status": "complete",
    "success": true,
    "type": "export"
  },
  "success": true
}
```