This Python example uses the psycopg2 library for connecting to Timescale Cloud PostgreSQL.

from psycopg2.extras import RealDictCursor
import psycopg2

uri = "postgres://tsdbadmin:[email protected]:20985/defaultdb?sslmode=require"

db_conn = psycopg2.connect(uri)
c = db_conn.cursor(cursor_factory=RealDictCursor)

c.execute("SELECT 1 = 1")
result = c.fetchone()

Node.js example

This example uses the node-postgres library.

var pg = require('pg');

var config = {
    database: "defaultdb",
    host: "",
    password: "nr0dfnswz36xs9pi",
    port: 20985,
    ssl: "require",
    user: "tsdbadmin",

var client = new pg.Client(config);

client.connect(function (err) {
    if (err)
        throw err;
    client.query('SELECT 1 AS value', [], function (err, result) {
        if (err)
            throw err;

        client.end(function (err) {
            if (err)
                throw err;

This example uses the Sequelize library.


  • pg-native package installed.
  • Service CA certificate, which you can download from the Timescale Cloud console's service page by clicking the "view CA certificate" button.
const Sequelize = require('sequelize');

const database = 'defaultdb';
const username = 'tsdbadmin';
const password = 'nr0dfnswz36xs9pi';
const host = '';
const port = 20985;
const sslrootcert = '/path/to/ca.pem';

const sequelize = new Sequelize(database, username, password, {
  dialect: 'postgres',
  native: true,
  ssl: true,
  dialectOptions: {
    ssl: {
      sslmode: 'verify-ca',

sequelize.query('SELECT 1 AS value')
  .then(([results, metadata]) => console.log(results));

C# example

This C# example uses the Npgsql driver for connecting to Timescale Cloud PostgreSQL. 

using Npgsql;
using System;

namespace tsdb
    class Program
        static void Main(string[] args)
            NpgsqlConnection conn = new NpgsqlConnection(";User Id=tsdbadmin;Password=nr0dfnswz36xs9pi;Database=defaultdb;Port=20985;SSLMode=Require;Trust Server Certificate=true");

            // This will return 1333332, can be any query you wish
            NpgsqlCommand command = new NpgsqlCommand("SELECT 666666*2::BIGINT", conn);
            Int64 count = (Int64)command.ExecuteScalar();

            Console.Write("{0}\n", count);

Java example

You'll need to download the service CA certificate from the Timescale Cloud console's service page by clicking the "view CA certificate" button.

package pg;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

public final class Connect {
  public static void main(String[] args) {
    Properties props = new Properties();
    props.put("jdbc.url", "jdbc:postgresql://");
    props.put("user", "tsdbadmin");
    props.put("password", "nr0dfnswz36xs9pi");
    props.put("ssl", "true");
    props.put("sslmode", "verify-ca");
    props.put("sslrootcert", "/path/to/ca.pem");

    try {
      Connection c = DriverManager.getConnection(props.getProperty("jdbc.url"), props);
    } catch (Exception e) {

Maven dependency for PostgreSQL JDBC driver (You can also download the latest driver from


AWS Elastic Beanstalk

When using an AWS Elastic Beanstalk application to connect & use a TimescaleDB service hosted in Timescale Cloud, you will need to make the database connection private key for the SSL certificate available to your application. AWS provides a way to store private keys securely in AWS S3 and make those keys available to your application during deployment. Refer to the AWS Elastic Beanstalk documentation for more information.

Did this answer your question?