> ## Documentation Index
> Fetch the complete documentation index at: https://porter-mintlify-1ef385fa.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# porter datastore connect

> Create a secure local tunnel to connect to Porter-provisioned Postgres and Redis datastores for local debugging and database administration

`porter datastore connect` creates a secure tunnel to connect to Porter-provisioned datastores from your local machine.

## Prerequisites

* You've logged in to the Porter CLI after running [porter auth login](/standard/cli/command-reference/porter-auth)
* You're connected to the correct project by running [porter config set-project](/standard/cli/command-reference/porter-config)
* You have a Porter-provisioned datastore (PostgreSQL, Redis, etc.)

***

## Usage

```bash theme={null}
porter datastore connect [DATASTORE_NAME] [flags]
```

**Options:**

| Flag                  | Description                                                                                              |
| --------------------- | -------------------------------------------------------------------------------------------------------- |
| `-p, --port`          | Local port for the tunnel (default: 8122)                                                                |
| `-e, --endpoint-type` | Endpoint to connect to: `primary` (read-write, default) or `replica` (read-only)                         |
| `--show-credentials`  | Show the datastore username, password, and example connection commands in the output (hidden by default) |

***

## Examples

<CodeGroup>
  ```bash Connect to datastore theme={null}
  porter datastore connect my-postgres
  ```

  ```bash Custom port theme={null}
  porter datastore connect my-postgres --port 5433
  ```

  ```bash Read-only replica theme={null}
  porter datastore connect my-postgres --endpoint-type replica
  ```

  ```bash Show credentials theme={null}
  porter datastore connect my-postgres --show-credentials
  ```
</CodeGroup>

***

## Hiding credentials

By default, `porter datastore connect` hides the datastore username and password from the terminal output to prevent accidental credential leakage (for example, via screenshots, shared terminals, or pasted logs). The tunnel host, port, and database name are still printed so you can connect with a client that already has the credentials configured.

When you need to view the credentials — for example, to copy them into a database client for the first time — pass `--show-credentials`:

```bash theme={null}
porter datastore connect my-postgres --show-credentials
```

With `--show-credentials`, the output also includes an example `psql` or `redis-cli` command pre-filled with the connection details.

***

## Connecting to your datastore

While the tunnel is running, connect using your preferred client in a separate terminal:

<CodeGroup>
  ```bash PostgreSQL theme={null}
  psql -h 127.0.0.1 -p 8122 -U postgres -d postgres
  ```

  ```bash Redis theme={null}
  redis-cli -p 8122 -a [YOUR_DATASTORE_PASSWORD] --tls
  ```
</CodeGroup>

<Info>
  The tunnel stays open until you press `CTRL-C`. Keep the terminal open while you need access to the datastore.
</Info>

<Warning>
  Credentials shown with `--show-credentials` are sensitive. Avoid running the command in shared sessions, recorded terminals, or screen-shared environments where the output could be captured.
</Warning>
