# Run your database on its own server, and keep it fast

Move your data to its own server, connect and test your sites, find slow queries, size it, back it up and add a read replica.

When a busy site and its database share one server, they compete for the same memory and processors. A database server of its own keeps your sites quick: the database gets the whole machine, several website servers can share it, and you can grow each one on its own. This guide covers the whole life of such a server. It takes about 30 minutes, plus the time the new server takes to set up.

## What you need

- A website server in Fuzops with the site that will use the database.
- A way to create one more server: a connected cloud account, or a fresh server of your own. Put it in the same region as your website server, and on the same private network when your provider offers one.

## Steps

1. **Create the database server and connect your site.** Follow [Set up a separate database server and connect a site to it](https://internal.fuzops.com/docs/guides/set-up-a-separate-database-server). Fuzops creates the database and a user that may sign in only from your website server, lets only that server through, and writes the details into the site's settings. If the two servers are in different regions, or can only reach each other over the internet, Fuzops says so before you confirm.

2. **Test the connection.** On the website server's **Databases** page, under **Use a database on another server**, choose **Test the connection** beside the site. Fuzops signs in from the website server with the site's own user and shows the time it took in milliseconds. A few milliseconds is what you want; tens of milliseconds means the servers are far apart.

3. **Size the database for the whole server.** Open the database server's **Recommended settings**. On a database server, the database gets most of the memory. A database still on its own defaults is marked **Not optimized yet**: review the values (each one with its default beside it, and **needs a restart** where applying it restarts the database), then apply. See [Recommended settings](https://internal.fuzops.com/docs/recommended-settings).

4. **Find what is slow.** Open **Database health** on the database server and choose **Read now**. It shows the connections in use, the queries running now, the sizes of your databases and tables, and the slowest queries grouped by shape. Turn on **Record queries slower than (ms)** with a threshold (500 is a good start), use the site for a while, then read again. See [Database health](https://internal.fuzops.com/docs/databases#database-health).

5. **Back it up.** On the database server's **Backups** page, choose **Back up a database** for each database, with a schedule. From time to time, open a backup and choose **Put it back** › **Only check that it loads**: you then know the backup can really be loaded. See [Backups and restore](https://internal.fuzops.com/docs/backups).

6. **Encrypt the connection.** On the database server's **Databases** page, choose **Turn on encrypted connections…**, then **Require encryption** on the site's user. When the two servers talk over a public address, **Use a database on another server** already did this for Laravel sites and PostgreSQL connection addresses. **Test the connection** then says "Encrypted, and the database server's certificate was verified."

7. **Add a read replica (Business plan).** Create a second, empty database server with the same database engine and version, then on the first one open **Read replica** and choose the new server. It copies the first one all the time and answers read-only queries; if the first server is lost, **Promote this replica…** makes it a database server of its own. See [Read replica](https://internal.fuzops.com/docs/databases#read-replica).

## What you should see

- **Test the connection** says "Signed in and answered in" a few milliseconds.
- **Database health** shows the connections in use well below the limit.
- **Recommended settings** shows no **Not optimized yet** notice.
- The database's **Backups** row shows recent backups and a successful load check.
- With a replica, **Read replica** says **Copying all the time** and "Up to date" or a few seconds behind.

## If it goes wrong

**Test the connection fails with "does not answer".** The database server's list keeps the website server out, or the database is stopped. Open the database server's **Databases** page: **Who can reach this database server** must list your website server. Check that the database row on **Services** is running.

**Test the connection fails at the sign-in.** The site's user no longer has the right address or password. Open the user on the database server and check **Who can sign in**.

**A query runs for minutes and everything waits for it.** On **Database health**, open it under **Running now** and choose **Stop this query…**. The query ends with an error for whoever started it; its connection stays open.

**The read replica stopped copying.** Home tells you, with the reason. Open **Read replica** and choose **Check now**. If the first server was rebuilt or its copy was removed, remove the replication and set up a new replica.

**You want to stop using the database server for a site.** Choose **Undo…** beside the site. Its user and its address are removed, the site's settings get their earlier database lines back, and the data stays on the database server until you delete it there.
