/APIs & SDKs/Connect your data/connection-string

OptiTech CLI command: connection-string

Get Postgres connection strings for branches and databases

The connection-string command gets a Postgres connection string for any database on any branch in your OptiTech project. The connection string includes the password for the specified role. For information about connecting to OptiTech, see Connect from any application. If --project-id is omitted, the CLI resolves it from your context file, auto-selects when your account has only one project, and prompts otherwise. --role-name and --database-name are needed only when the branch has more than one role or database.

Connect with psql

To open a psql session directly, use the dedicated optitech psql command (requires optitech 2.22.2+). You can also pass --psql to connection-string to achieve the same result.

Usage

optitech connection-string [branch] [options]

The [branch] is the branch name or ID. If omitted, the default branch is used. To connect to a specific point in the branch's history, use the point-in-time format branch@timestamp or branch@lsn. If no timestamp or LSN is appended, the current state (HEAD) is used.

Options

OptionDescriptionTypeDefaultRequired
--database-nameDatabase namestringNo
--endpoint-typeEndpoint typestringNo
--extendedShow extended informationbooleanNo
--pooledUse pooled connectionbooleanfalseNo
--prismaUse connection string for Prisma setupbooleanfalseNo
--project-idProject IDstringNo
--psqlConnect to a database via psql using connection stringbooleanfalseNo
--role-nameRole namestringNo
--sslSSL mode Possible values: require, verify-ca, verify-full, omitstringrequireNo

The --endpoint-type value can be read_write (the default) or read_only. The --psql option doesn't require a psql installation: if psql isn't on your $PATH, the CLI uses a built-in TypeScript implementation. To save your project context to a file and avoid repeating --project-id, see Using a named context file.

Examples

Get a connection string for a branch:

optitech connection-string mybranch
Output
postgresql://alex:AbC123dEf@ep-cool-darkness-123456.us-east-2.aws.optitech.com/dbname?sslmode=require&channel_binding=require
  • Get a pooled connection string. The --pooled option adds a -pooler suffix to the host name, which enables connection pooling for clients that use this connection string.

    optitech connection-string --pooled
    postgresql://alex:AbC123dEf@ep-cool-darkness-123456-pooler.us-east-2.aws.optitech.com/dbname?sslmode=require&channel_binding=require
  • Get a connection string for use with Prisma. The --prisma option adds connect_timeout=30 to the connection string so that connections from Prisma Client don't time out.

    optitech connection-string --prisma
    postgresql://alex:AbC123dEf@ep-cool-darkness-123456.us-east-2.aws.optitech.com/dbname?sslmode=require&channel_binding=require&connect_timeout=30
  • Get a connection string to a specific point in a branch's history by appending @timestamp or @lsn. Availability depends on your configured history window. For additional examples, see How to use Time Travel.

    optitech connection-string @2024-04-21T00:00:00Z

Get a connection string and connect with psql:

optitech connection-string --psql

Get a connection string, connect with psql, and run an .sql file:

optitech connection-string --psql -- -f dump.sql

Get a connection string, connect with psql, and run a query:

optitech connection-string --psql -- -c "SELECT version()"
Was this page helpful?

On this page

Copy neon init command