Getting connection strings

Gen 2

Getting connection strings in the UI

Follow these steps to retrieve your IBM Cloud® Databases for PostgreSQL instance connection strings:

  1. In your deployment's Overview page, scroll down to the Service endpoints section.
  2. The Service endpoints section displays tabs for available connection methods:
  • PostgreSQL – Shows the connection string, hostnames, ports, database name, authentication source, and replica set for your deployment.
  • CLI – Provides details for connecting by using the IBM CLI.

Architecture
Getting connections strings - Service endpoints PostgreSQL tab

Databases for PostgreSQL deployments no longer include a default admin user. Instead, you create a user with the 'Manager', 'Writer', or 'Reader' role using the IBM Cloud® service credential interface — via UI or CLI. This provides a username(ibm_...), password, and connection string that can be used to connect to your deployment.

Getting connection strings in the CLI

You can also find the endpoint under the CLI tab of the service endpoints.

Architecture
Getting connections strings - Service endpoints CLI tab

You can also retrieve connection strings using the Cloud Databases CLI plug-in Connection command.

The command looks like this:

ibmcloud resource service-instance <INSTANCE_NAME_OR_CRN>

For more information, see Connections command options.

Databases for PostgreSQL deployment no longer include a default admin user. Instead, customers create a user with the 'Manager', 'Writer', or 'Reader' role using the IBM Cloud® service credential interface — via UI or CLI. This provides a username(ibm_...), password, and connection string that can be used to connect to your deployment. If your deployment has only a private endpoint, you must specify --endpoint-type private or the commands return an error. The user and endpoint type is not enforced. You can use any user on your deployment with the private endpoint, which is the designated connection option.

To use the ibmcloud cdb CLI commands, you must install the Cloud Databases plug-in.

Getting connection strings in the API

To retrieve users' connection strings from the Cloud Databases API, use the Connections endpoint. To create the connection strings, ensure that the path includes the specific user and endpoint type that should be used. The user is not restricted or enforced. You have the flexibility to utilize any user available in your deployment.

The API command looks like:

curl -X GET 'https://resource-controller.cloud.ibm.com/v2/resource_instances/{id}' -H "Authorization: Bearer <IAM token>""

Remember to replace {region}, {id}, {userid}, and {endpoint_type} with the appropriate values.

Getting connection strings in the API

To retrieve user's connection strings from the API, use the /users/{userid}/connections endpoint. You must specify in the path which user and which type of endpoint (public or private) is to be used in the returned connection strings. The user and endpoint type is not enforced. You can use any user on your deployment with either endpoint (if both exist on your deployment).

curl -X GET -H "Authorization: Bearer $APIKEY" 'https://api.{region}.databases.cloud.ibm.com/v4/ibm/deployments/{id}/users/{userid}/connections/{endpoint_type}'

Connection string breakdown

The PostgreSQL section

The "PostgreSQL" tab contains information that is suited to applications that make connections to PostgreSQL.

PostgreSQL/URI connection information
Field name Index Description
Type Type of connection - for PostgreSQL, it is "URI".
Scheme Scheme for a URI - for PostgreSQL, it is "postgresql".
Path Path for a URI - for PostgreSQL, it is the database name. The default is ibmclouddb.
Authentication Username The username that you use to connect.
Authentication Password A password for the user - might be shown as $PASSWORD.
Authentication Method How authentication takes place; "direct" authentication is handled by the driver.
Hosts 0... A hostname and port to connect to.
Composed 0... A URI combining Scheme, Authentication, Host, and Path.
  • 0... indicates one or more of these entries in an array.

The CLI section

The "CLI" section contains information that is suited for connecting with psql.

PostgreSQL/cli connection information
Field name Index Description
Bin The binary to create a connection; in this case it is psql.
Composed A formatted command to establish a connection to your deployment. The command combines the Bin executable, Environment variable settings, and uses Arguments as command line parameters.
Environment A list of key/values you set as environment variables.
Arguments 0... The information that is passed as arguments to the command shown in the Bin field.
Type The type of package that uses this connection information; in this case cli.
  • 0... indicates that there might be one or more of these entries in an array.