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

# Quickstart Guide

> Get started with PeerDB in a few simple steps.

### Deploying PeerDB

We currently support deploying and testing PeerDB using our Docker Compose file.

<Info>
  {" "}

  Docker can be installed by referring to [these instructions](https://www.docker.com/products/docker-desktop).
  The `docker compose` tool should also be present. The Postgres client tools (specifically
  `psql`) are used to test the PeerDB installation.{" "}
</Info>

**Run the following commands in your terminal:**

```bash theme={null}
git clone --recursive https://github.com/PeerDB-io/peerdb.git
cd peerdb

# Run docker containers: peerdb-server, postgres as catalog, temporal.
# This might take a few minutes, so get a cup of coffee! :)
./run-peerdb.sh
```

That's it! You now have PeerDB up and running on your machine, ready to query away!

### Quickstart

<Info>
  {" "}

  The following steps assume you have PeerDB running locally. We also need `psql` installed and available on your
  PATH.
</Info>

#### Setup

This script reuses the PeerDB internal Postgres instance to setup two databases, which we can use to create two peers. It also creates some tables on both databases to use later in the quickstart. Run the following commands in your terminal:

```bash theme={null}
curl -O https://raw.githubusercontent.com/PeerDB-io/peerdb/main/quickstart_prepare_peers.sh
chmod +x quickstart_prepare_peers.sh
./quickstart_prepare_peers.sh
```

#### Creating Peers

With PeerDB running, we can create our first peers.

Head over to `localhost:3000` on your browser. This is the PeerDB Dashboard.

Clicking on **Peers** in the sidebar will take us to the **Peers** page.

Let's click on the Create Peer button at the top right to get started.

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/ui-quickstart/createpeerbutton.png?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=10f46f52e063b1f19903a2b984b87b7e" alt="create peer" width="3454" height="564" data-path="images/ui-quickstart/createpeerbutton.png" />

Now, we select the data store for which we wish to create a peer. Let's select **Postgres** and click on the **Continue** button.

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/ui-quickstart/selectpg.png?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=b2d17258914a1b48303db0fc441fc0ed" alt="select datastore" width="2304" height="914" data-path="images/ui-quickstart/selectpg.png" />

This takes to a form where we can fill in the details for the peer. Let's fill in the details of our PostgreSQL peer.

Fill in the **password** as `postgres`.

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/ui-quickstart/createpg1.png?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=917c9364d474dfcce26d96f517413ee7" alt="source peer" width="1964" height="1342" data-path="images/ui-quickstart/createpg1.png" />

PeerDB validates the connection details and if everything is correct, clicking on **Validate** should show a success message.

Finally, click on **Create** to create the peer.

We now have our **source PostgreSQL peer** ready.

Let's create the **target PostgreSQL peer** by repeating the exact same steps.

Fill in the **password** as `postgres`.

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/ui-quickstart/createpg2.png?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=a2cb8771950fb96f320c363678e2d073" alt="target peer" width="1964" height="1342" data-path="images/ui-quickstart/createpg2.png" />

Now that we have our source and target peers ready, let's move on to **creating a mirror**.

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/ui-quickstart/peersdone.png?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=ef341455a381c43f566d3b2e04c6ac83" alt="gototmirrors" width="1310" height="414" data-path="images/ui-quickstart/peersdone.png" />

Clicking on **Mirrors** in the sidebar will take us to the **Mirrors** page.

#### Real-time CDC

To kick off Change Data Capture (CDC) based streaming from source peer to target peer, let's click on **New Mirror**.

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/ui-quickstart/newmirrorbutton.png?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=6f5658c36f44011896a0e321806a4e4c" alt="newmirror" width="3444" height="412" data-path="images/ui-quickstart/newmirrorbutton.png" />

Let's select the `CDC` box, and enter the name of the mirror and the two peers.

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/ui-quickstart/mirrorpage.png?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=d1bd395a3c67d6a50cd0a50b2e6ff658" alt="mirrorform" width="1789" height="948" data-path="images/ui-quickstart/mirrorpage.png" />

Scrolling down, we can see a section to a **select the table** on our source PostgreSQL peer to sync.

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/ui-quickstart/tablemapping.png?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=d3a7cd003893c4f2a014b7fc56eb76d7" alt="selecttable" width="2380" height="464" data-path="images/ui-quickstart/tablemapping.png" />

Let's select the table we have ready - `public.test`.
Now that we've filled in all the mirror details.
Let's click on **Validate** to check if everything is set up correctly, much like we did when creating peers!

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/ui-quickstart/validatemirr.png?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=41a97ca286345981dcb3afd88db39205" alt="selecttable2" width="2380" height="956" data-path="images/ui-quickstart/validatemirr.png" />

Finally, click on **Create** to create the mirror.

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/ui-quickstart/createmirr.png?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=8af5f816e5be5d1ab5b5a2f9ec4eb0ef" alt="createmirr" width="2380" height="956" data-path="images/ui-quickstart/createmirr.png" />

Now that our CDC mirror is set up, it will automatically replicate data from the source to the target peer. Let's insert a row in the source table via PeerDB itself.

Connect to PeerDB via psql:

```bash theme={null}
psql "port=9900 host=localhost password=peerdb"
```

And now we can run the below commands.

```sql theme={null}
--- Verify that the source table has zero rows
SELECT id,c1,c2,t FROM source.public.test;
```

```sql theme={null}
--- Insert a row into the source table
INSERT INTO source.public.test(c1, c2, t) VALUES(1, 2, 'oathbringer');
```

Within a minute, the row should be replicated to the target table. Let's click the mirror link on the `Mirrors` page which we landed on after creating the mirror:

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/ui-quickstart/mirrorlink.png?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=63b52c52fc99dccb443fcd8b02f7a998" alt="mirrorlink" width="2972" height="618" data-path="images/ui-quickstart/mirrorlink.png" />

This takes to the **Mirror Overview** page. Let's click on the **Sync Status tab**, where we can see the status of the mirror and the number of rows replicated:

<img src="https://mintcdn.com/peerdb/wtgPI5cQwjI2FO0m/images/ui-quickstart/mirrorresults.png?fit=max&auto=format&n=wtgPI5cQwjI2FO0m&q=85&s=9a22c84ec0b9213325dcfce2a52a4578" alt="mirroroverview" width="3448" height="1796" data-path="images/ui-quickstart/mirrorresults.png" />

We can see that the mirror has successfully replicated the row from the source to the target peer. Let's verify this by querying the target table.

```sql theme={null}
--- CDC mirrors replicate data as-is, so the row should be identical.
SELECT id,c1,c2,t FROM target.public.test;
```

The output should look like this:

```bash theme={null}
peerdb=> SELECT id,c1,c2,t FROM target.public.test;
id | c1 | c2 |      t
----+----+----+-------------
1 |  1 |  2 | oathbringer
(1 row)
```

The above MIRROR takes care of replicating all future DML commands (`INSERT`, `UPDATE`, `DELETE`) from source to target.

### FAQ

If you have any questions about the PeerDB setup and deployment process, don't hesitate to reach out on [Slack](https://slack.peerdb.io). We're more than happy to assist and answer any questions, including:

* What is the performance I can expect during CDC and query based replication?
* How do I know my data sync is successful?
* Can I set a specific time to start my data sync?

If there are any unanswered questions, we'd love to help you get started. Feel free to ask your questions on our community [Slack](https://slack.peerdb.io) channel.

In addition to this, if you require direct access to our team for any assistance, don't hesitate to contact us to discuss our premium support offerings.
