cockroachdbcockroachcloud

can not connect to cockroachdb invalid cluster name


Why I cant connect to cockroachdb via powershell ?

I use this command:

cockroach sql --url postgres://username@cloud-host:26257/defaultdb?sslmode=require&options=--cluster=clustername;

I get the following error:

Invalid clustername 08004

but the clustername is the right one.

Nodejs

//For secure connection:
// const fs = require('fs');
const { Pool } = require("pg");

// Configure the database connection.

const config = {
  user: "xxxxx",
  password: "xxxx",
  cluster_name: "xxxx",
  host: "xxxx",
  database: "wxxx",
  port: 26257,
  ssl: {
    rejectUnauthorized: false,
  },
  //For secure connection:
  /*ssl: {
        ca: fs.readFileSync('/certs/ca.crt')
            .toString()
    }*/
};

// Create a connection pool

const pool = new Pool(config);

router.get('/', async (req, res) => {
  const client = await pool.connect();
  const d = await client.query('CREATE TABLE test (id INT, name VARCHAR, desc VARCHAR);');
  console.log(d);
  return res.json({
    message: 'BOSY'
  })

Get this error:

CodeParamsRoutingFailed: rejected by BackendConfigFromParams: Invalid cluster name

Solution

  • Try specifying the Cluster Name before dbname like this

    cockroach sql --url postgres://username@cloud-host:26257/**clustername.defaultdb**?sslmode=require