1

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
localdata01
  • 587
  • 7
  • 17

2 Answers2

3

Try specifying the Cluster Name before dbname like this

cockroach sql --url postgres://username@cloud-host:26257/**clustername.defaultdb**?sslmode=require
raiyan22
  • 1,043
  • 10
  • 20
  • solved a `Error: pq: codeParamsRoutingFailed: missing cluster identifier` for connecting to a cockroachlabs.cloud cluster – ddelange Feb 01 '23 at 10:20
2

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";
paulkernfeld
  • 2,171
  • 1
  • 16
  • 16