无法连接到 cockroachdb 无效的集群名称

问题描述

为什么我无法通过 powershell 连接到 cockroachdb?

我使用这个命令:

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

我收到以下错误:无效的集群名称 08004

但集群名称是正确的。

€:

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'
  })

得到这个错误

CodeParamsRoutingFailed: rejected by BackendConfigFromParams: Invalid cluster name

解决方法

我想知道 shell 中的特殊字符是否有问题。从未使用过 PowerShell 这只是一个猜测,但如果将 URL 字符串放在引号中是否有效?

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