Skip to main content
Version: Weekly Build

Connecting to Managed Services

Once your managed service is deployed, you can connect to it from your Codesphere workspaces. Each service lists non-sensitive connection details in their respective settings page, in the overview tab (or in the details property in the public API payload). This guide provides examples for connecting to common services.

Prerequisites

Ensure your workspace and the managed service are in the same team to allow for network access.

PostgreSQL

Codesphere provides a standard PostgreSQL service. You can connect to it using any PostgreSQL compatible client, such as psql or Node.js libraries like pg.

Connection Details

You can find these in the service details page:

  • Host/DSN: The internal hostname or full connection string with redacted password.
  • Port: 5432 (Standard PostgreSQL port).
  • Username: Defined during setup (for root user postgres or your custom username that you provided).
  • Password: The secret you provided during setup for the specified username.

You can use the psql command-line tool directly from your workspace terminal.

# Install psql
nix-env -iA nixpkgs.postgresql

# General syntax
psql "postgres://<username>@<hostname>:5432/<database>" -W

# Example
psql "postgres://[email protected]:5432/mydb" -W

Babelfish (SQL Server Compatible)

Babelfish for PostgreSQL allows it to understand the T-SQL protocol, making it compatible with SQL Server clients.

Unlike with standard PostgreSQL, Babelfish does support specifying a name for the initial database. The initial database is always named master. You can create additional databases after provisioning.

Connection Details

  • Host/DSN: The internal hostname or full connection string with redacted password.
  • Port: 1433 (Standard SQL Server port).
  • Username: postgres (you can create additional users after provisioning).
  • Password: As configured.
  • Database: Initially master.

You can use tsql (part of the FreeTDS package) to connect. Note that tsql might need to be installed in your workspace.

# Install FreeTDS
nix-env -iA nixpkgs.freetds

# Syntax
# TDSENCRYPTION=required tsql -H <hostname> -p 1433 -U <username> -D <database>

# Example:
TDSENCRYPTION=required tsql -H ms-babelfish-v1-123-my-server.ms-postgres -p 1433 -U postgres -D master

S3 (Object Storage)

The S3 Managed Service provides an S3-compatible object storage API.

Connection Details

  • Endpoint: The URL of the service (e.g., http://10.0.0.20:9000).
  • Access Key: Generated during setup.
  • Secret Key: Generated during setup.

The MinIO Client (mc) is a robust tool for interacting with S3-compatible APIs.

# 1. install
nix-env -iA nixpkgs.minio-client

# 2. Configure alias
mc alias set my-storage http://10.0.0.20:9000 "$ACCESS_KEY" "$SECRET_KEY"

# 3. List buckets
mc ls my-storage

# 4. Copy file
mc cp myfile.txt my-storage/my-bucket/

Codesphere Document DB (MongoDB compatible)

Codesphere Document DB is a document database with MongoDB compatibility. It leverages a FerretDB proxy which implements the MongoDB wire protocol as a translation layer and routes queries to a PostgreSQL database leveraging the DocumentDB extension.

Connection Details

  • Host: The internal hostname.
  • DSN: The full connection string with redacted password
  • Port: 27017 (Standard MongoDB port).
  • Username: postgres (you can create additional users after provisioning).
  • Password: As configured.
  • Auth Source: postgres

You can use mongosh to connect from your workspace terminal.

No TLS Encryption between the client and the FerretDB Proxy
# Install mongosh
nix-env -iA nixpkgs.mongosh
source ~/.nix-profile/etc/profile.d/nix.sh

# Syntax
mongosh "mongodb://<username>:<password>@<hostname>:27017/ferretdb?authSource=postgres"

# Example
db.myCollection.insertOne({ message: "Hello Codesphere!" })