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

# AlloyDB

> Connect to a private AlloyDB instance, including read pools, through a bqto port forward, and use psql with the PGHOST and PGPORT variables.

bqto connects to AlloyDB instances through private services access (PSA) or Private Service
Connect (PSC). Read pools work too. This service is in the free bqto.

## Connect

```sh theme={null}
bqto connect --service alloydb --project my-project --instance REGION/CLUSTER/INSTANCE
```

`--instance` takes the region, the cluster, and the instance, separated by `/`.

bqto gives you a port forward. The local port is the port of the instance plus 10000, so 5432
becomes 15432. With managed connection pooling, the local port is 16432.

## Clients

Use `psql`. With `-- CMD`, the command gets `PGHOST` and `PGPORT`:

```sh theme={null}
bqto connect --service alloydb --project my-project --instance REGION/CLUSTER/INSTANCE \
  --no-input -- sh -c 'psql -U app -c "select 1"'
```

The database login is separate from bqto. bqto carries no database password.

## What it needs

* The API `alloydb.googleapis.com` in the service project.
* The role `roles/alloydb.viewer` in the service project, together with the roles that every
  session needs. See [Permissions](https://docs.bqto.dev/reference/permissions.md).

## Connection logs

To match a connection in the database to a session, turn on the connection log of the instance.
This flag comes from Google's documentation and was not tested live.

```sh theme={null}
gcloud alloydb instances update INSTANCE --cluster CLUSTER --region REGION --project $PROJECT \
  --database-flags=log_connections=on
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.