要连接CockrachDB Serverless,我必须在连接字符串(?sslmode=verify-full&options=--cluster%3Dblackstack-4545)中传递一些参数。
完整连接字符串如下所示:
postgresql://blackstack:<db-password>@free-tier14.aws-us-east-1.cockroachlabs.cloud:26257/blackstack?sslmode=verify-full&options=--cluster%3Dblackstack-4545在Ruby中,如果我使用pg gem,这样的连接字符串工作得很好,但是如果我使用Sequel,它就会失败。
下面是测试代码:
require 'pg'
require 'sequel'
DATABASE_URL="postgresql://blackstack:<db-password>@free-tier14.aws-us-east-1.cockroachlabs.cloud:26257/blackstack?sslmode=verify-full&options=--cluster%3Dblackstack-4545"
conn = PG.connect(DATABASE_URL)
p conn.exec("SELECT 'Hello CockroachDB!' AS message").first
# => {"message"=>"Hello CockroachDB!"}
DB = Sequel.connect(DATABASE_URL)
p DB["SELECT 'Hello CockroachDB!' AS message"].first
# => "/home/leandro/.rvm/gems/ruby-3.1.2/gems/pg-1.3.5/lib/pg/connection.rb:637:in `async_connect_or_reset': PG::ConnectionBad: FATAL: codeParamsRoutingFailed: missing cluster identifier (Sequel::DatabaseConnectionError)"下面是命令的完整输出:
leandro@dev5:~/code/mysaas/examples/1.db$ ruby 1.connect.rb
{"message"=>"Hello CockroachDB!"}
/home/leandro/.rvm/gems/ruby-3.1.2/gems/pg-1.3.5/lib/pg/connection.rb:637:in `async_connect_or_reset': PG::ConnectionBad: FATAL: codeParamsRoutingFailed: missing cluster identifier (Sequel::DatabaseConnectionError)
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/pg-1.3.5/lib/pg/connection.rb:707:in `new'
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/adapters/postgres.rb:208:in `connect'
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/connection_pool.rb:122:in `make_new'
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/connection_pool/threaded.rb:209:in `assign_connection'
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/connection_pool/threaded.rb:139:in `acquire'
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/connection_pool/threaded.rb:91:in `hold'
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/database/connecting.rb:269:in `synchronize'
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/database/connecting.rb:278:in `test_connection'
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/database/misc.rb:175:in `initialize'
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/database/connecting.rb:57:in `new'
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/database/connecting.rb:57:in `connect'
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/core.rb:124:in `connect'
from 1.connect.rb:10:in `<main>'
/home/leandro/.rvm/gems/ruby-3.1.2/gems/pg-1.3.5/lib/pg/connection.rb:637:in `async_connect_or_reset': FATAL: codeParamsRoutingFailed: missing cluster identifier (PG::ConnectionBad)
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/pg-1.3.5/lib/pg/connection.rb:707:in `new'
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/adapters/postgres.rb:208:in `connect'
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/connection_pool.rb:122:in `make_new'
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/connection_pool/threaded.rb:209:in `assign_connection'
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/connection_pool/threaded.rb:139:in `acquire'
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/connection_pool/threaded.rb:91:in `hold'
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/database/connecting.rb:269:in `synchronize'
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/database/connecting.rb:278:in `test_connection'
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/database/misc.rb:175:in `initialize'
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/database/connecting.rb:57:in `new'
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/database/connecting.rb:57:in `connect'
from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/core.rb:124:in `connect'
from 1.connect.rb:10:in `<main>'发布于 2022-08-30 15:02:48
我自己修好了。
我使用cluster_name.db_name格式来处理下面的连接字符串。
postgresql://blackstack:<db-password>@free-tier14.aws-us-east-1.cockroachlabs.cloud:26257/blackstack-4545.blackstack?sslmode=verify-fullhttps://stackoverflow.com/questions/73515424
复制相似问题