【问题标题】:can not connect to cockroachdb invalid cluster name无法连接到 cockroachdb 无效的集群名称
【发布时间】:2021-09-02 18:58:10
【问题描述】:

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

我使用这个命令:

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

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

但集群名称是正确的。

欧元:

节点

//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

【问题讨论】:

  • 删除集群名称并把数据库名称像database: 'cluster_name.dbname'

标签: cockroachdb cockroachcloud


【解决方案1】:

我想知道外壳中的特殊字符是否存在问题。从未使用过 PowerShell,这只是一种猜测,但如果将 URL 字符串放在引号中,它会起作用吗?

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

【讨论】:

  • Okey 在终端中它现在可以工作,但不能在 nodejs 客户端上,看看我编辑的帖子
  • 对于节点连接问题的解决方案,Rohit Khurana 对您的问题的评论应该可以满足您的需求。
【解决方案2】:

尝试像这样在dbname 之前指定集群名称

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

【讨论】:

    猜你喜欢
    • 2020-05-03
    • 2020-02-08
    • 2020-04-28
    • 2021-11-23
    • 2021-09-18
    • 2020-07-12
    • 2015-10-27
    • 2018-08-23
    • 1970-01-01
    相关资源
    最近更新 更多