# Database

> Browse tables, edit rows and run SQL against your app's SQLite databases, or against a PostgreSQL, MySQL, MariaDB or SQLite database the desktop app connects to. Your app's databases are off until you pass them.

The Database panel lists the tables in a database, pages through their rows, and runs SQL. It works with the SQLite databases in your app, and with PostgreSQL, MySQL, MariaDB and SQLite databases the desktop app connects to directly.

[Setting up Database in the SDK](/docs/sdk/database/)

![The Database panel with an app database selected, its tables listed on the left and the cases table open](/_astro/database-panel-light.C23gpirG_1f1E2U.webp)![The Database panel with an app database selected, its tables listed on the left and the cases table open](/_astro/database-panel-dark.DYRRJkGt_Z20VztC.webp)

The Database panel with an app database selected, its tables listed on the left and the cases table open

## Using the Database panel

### Choosing a database

Pick a database from the list at the top of the panel. Your app’s databases come first, in the order you passed them, then the direct connections you’ve added.

### Adding a connection

Click **Add connection** (**+**) beside the database list, choose an **Engine**, and fill in the connection details. **Name** is optional and defaults to `user@host/database`. For **SQLite file**, click **Browse…** to pick an existing file.

![The Add connection dialog with PostgreSQL selected and the host, port, user and database filled in](/_astro/database-add-connection-light.B8dSd_Ua_Z1RdwK7.webp)![The Add connection dialog with PostgreSQL selected and the host, port, user and database filled in](/_astro/database-add-connection-dark.CH5ma-4Y_ZwqGn9.webp)

The Add connection dialog with PostgreSQL selected and the host, port, user and database filled in

Click **Test connection** to check the details, then **Save**. To change or delete a connection, select it and click **Connection settings** beside the list.

Connections are saved on your computer. Passwords are stored in your system’s keychain, such as the macOS Keychain. To be asked for the password each time instead, check **Don’t save password, ask on connect**. See [Keychain](/docs/keychain/).

Check **Read-only** to block every write, from the grid and from SQL.

#### SSH tunnel

Under **SSH tunnel**, turn on **Connect through SSH** and enter the **SSH host**, **SSH port** and **SSH user**. Choose **Password** or **Private key** for **SSH authentication**. The server’s host key is pinned on the first connection. If it changes, connecting fails until you click **Forget** beside **Pinned host key**.

#### TLS

Under **TLS**, choose a **TLS mode**: **Disable**, **Prefer**, **Require**, **Verify CA** or **Verify full**. **Prefer** is the default. Add a **CA certificate file**, **Client certificate file** or **Client key file** if the server needs them. **Verify full** isn’t available through an SSH tunnel.

### Browsing tables

The tables are listed on the left. Views are marked **view**, and PostgreSQL tables are grouped by schema. Type in **Search tables** to filter them by name. On PostgreSQL, include the schema to search within it, as in `auth.users`.

Click **Refresh** to read the tables and the open table again.

### Browsing rows

Select a table to see its rows. More load as you scroll. On large PostgreSQL, MySQL and MariaDB tables, the row count is an estimate, shown with **\~**.

* **Order by** sorts by a column, and the button beside it switches between ascending and descending. Each column header’s menu can also sort, or pin the column to the left.
* **Columns** hides and shows columns. Drag the edge of a header to resize a column.

### Editing rows

Double-click a cell to edit it. Press `Enter` to save, or `Esc` to cancel, and click **NULL** to set it to `NULL`.

Click **Add row** to add a row. Fill in the cells, using `Tab` to move between them. A cell left empty gets the column’s default. Click **Save new row** to write it, or **Discard new row**.

To delete a row, click **Delete row** (the bin icon) at its start, then **Delete**.

Views and BLOB values can’t be edited.

* In your app

  Every table can be edited. Rows are identified by their `rowid`, or by their primary key in a `WITHOUT ROWID` table.

* Direct connection

  PostgreSQL, MySQL and MariaDB tables need a primary key to edit or delete rows. Read-only connections can’t be edited.

### Running SQL

Click **SQL** to open the editor. Table and column names autocomplete. Click **Run**, or press

`⌘`+`Enter` (`Ctrl`+`Enter` on Windows and Linux).

![The SQL editor below the grid, with a query's result shown in the grid](/_astro/database-sql-light.BHTSwqCI_Z1xW4Ne.webp)![The SQL editor below the grid, with a query's result shown in the grid](/_astro/database-sql-dark.DQ8TahkL_ZskfQe.webp)

The SQL editor below the grid, with a query's result shown in the grid

Several statements run in order and stop at the first error. The result of the last query shows in the grid, up to 1000 rows. Click **Clear** to go back to the table.

Before running a `DROP`, or an `UPDATE` or `DELETE` without a `WHERE`, the panel asks you to confirm.

* In your app

  A query can’t be cancelled once it starts.

* Direct connection

  On PostgreSQL, MySQL and MariaDB, click **Cancel** to stop a running query. A query that runs for more than 30 seconds is stopped. A query on a SQLite file can’t be cancelled.

  Caution

  Cancelling is best effort, and doesn’t roll anything back. It stops the statement that’s running and skips the rest. Statements that already finished stay applied, and so does a statement that finishes before the cancel reaches the database.

### Saving snippets

Click **Save as snippet** to keep the SQL in the editor. **SQL snippets** lists them, to insert into the editor, run, edit or delete. Snippets are shared between databases of the same type.

## Limits and Troubleshooting

* `BEGIN`, `COMMIT` and other transaction statements are refused.
* A query’s result shows at most 1000 rows.
* BLOB values show their size only and can’t be edited.
* **“Your app has disconnected”**: its databases leave the list, except the one you’re viewing, which stays until you leave the panel. Reconnect your app to bring them back.
* **“The SSH server’s host key has changed”**: if you trust the new key, click **Forget** beside **Pinned host key** in the connection’s settings, then connect again.
