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

# How to Deploy your First Managed Database

> Step-by-step tutorial to host a managed MongoDB, PostgreSQL, MySQL or Redis database on Square Cloud and connect to it from your application code.

## Introduction

This tutorial takes you from zero to a live, connected database in a few minutes: create the instance from the dashboard, grab its connection string, and connect to it from your own code.

### Prerequisites

* **Square Cloud Account**: Create your account through the [signup page](https://squarecloud.app/en/signup).
* **Active Standard plan or higher**: Managed databases require an **active Standard plan or higher**. Check the [available plans](/en/platform/plans) and choose the one that fits your workload.

## Step 1: Choose an engine

Square Cloud offers four managed database engines, already configured to connect and start using:

|   Engine   | Version |
| :--------: | :-----: |
| PostgreSQL |  17.x.x |
|   MongoDB  |  8.x.x  |
|    MySQL   |  9.x.x  |
|    Redis   |  7.4.x  |

This tutorial uses **PostgreSQL**, but the same dashboard flow applies to every engine above.

## Step 2: Create the database

<Steps>
  <Step title="Create a new database instance">
    Go to the [Databases](https://squarecloud.app/en/dashboard/databases) page and click on the "Create Database" button.
  </Step>

  <Step title="Setting up your database instance">
    Select **PostgreSQL** (or the engine you chose in Step 1) and fill in the required information, such as the database name and RAM.
  </Step>

  <Step title="Finish your instance creation">
    Click on the "Create" button and wait for the database to be created.
  </Step>
</Steps>

## Step 3: Get the connection string

Once your database is ready, open it from the [Databases](https://squarecloud.app/en/dashboard/databases) page. The connection details — host, port, username, password and connection URL — are shown in the database dashboard, alongside the TLS certificate you'll need to connect.

<Note>Square Cloud databases only accept SSL/TLS connections. See [how do I connect to my database](/en/services/databases#how-do-i-connect-to-my-database) for how the certificate is used by different clients.</Note>

## Step 4: Connect from your code

With the connection string in hand, connect using your language's PostgreSQL client.

<Tabs>
  <Tab title="Node.js">
    Install the [`pg`](https://www.npmjs.com/package/pg) package:

    ```bash theme={null}
    npm install pg
    ```

    Connect and verify with a simple query:

    ```javascript index.js theme={null}
    import fs from "node:fs";
    import { Client } from "pg";

    const cert = fs.readFileSync("certificate.pem").toString();

    const client = new Client({
      connectionString: process.env.DATABASE_URL, // postgresql://user:password@host:port/dbname
      ssl: { ca: cert, cert: cert, key: cert },
    });

    await client.connect();
    const result = await client.query("SELECT 1");
    console.log("Connected! Result:", result.rows[0]);
    await client.end();
    ```
  </Tab>

  <Tab title="Python">
    Install [`psycopg2`](https://pypi.org/project/psycopg2-binary/):

    ```bash theme={null}
    pip install psycopg2-binary
    ```

    Connect and verify with a simple query:

    ```python main.py theme={null}
    import os
    import psycopg2

    conn = psycopg2.connect(
        os.environ["DATABASE_URL"],  # postgresql://user:password@host:port/dbname
        sslmode="verify-ca",
        sslrootcert="certificate.pem",
        sslcert="certificate.pem",
        sslkey="certificate.pem",
    )
    cur = conn.cursor()
    cur.execute("SELECT 1")
    print("Connected! Result:", cur.fetchone())
    cur.close()
    conn.close()
    ```
  </Tab>
</Tabs>

If the query returns a result instead of raising a connection error, your application is talking to the database successfully.

<Warning>Never hardcode the connection string in your source code. Set it as an environment variable (`DATABASE_URL`) through your [configuration file](/en/getting-started/config-file) or the dashboard, so credentials never end up in your repository.</Warning>

## Your database is live

You now have a managed database running and reachable from your code. From here:

<CardGroup cols={2}>
  <Card title="Deploy an app to use it" icon="server" href="/en/tutorials/how-to-deploy-your-website">
    Host the application that connects to this database on Square Cloud.
  </Card>

  <Card title="Snapshots" icon="camera" href="/en/cli-reference/commands/database/snapshot">
    Create and restore database snapshots from the CLI.
  </Card>
</CardGroup>

## Contact us

If you continue facing **technical difficulties**, our **specialized support team** is available to assist you. [**Contact us**](https://squarecloud.app/en/support) and we'll be happy to help you resolve any issue — support quality is a big part of why developers rate Square Cloud [**4.9/5 across 402 reviews**](https://www.trustpilot.com/review/squarecloud.app) on Google and Trustpilot.
