can not connect to cockroachdb invalid cluster name

2.7k views Asked by At

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
2

There are 2 answers

1
Ina Tacheva On BEST ANSWER

Try specifying the Cluster Name before dbname like this

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

I wonder if there's an issue with special characters in the shell. Having never used PowerShell this is only a guess, but does it work if you put the URL string in quotes?

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