To connect a CockrachDB Serverless, I have to pass some parameters in the connection string (?sslmode=verify-full&options=--cluster=blackstack-4545
).
The full connection string looks like this:
postgresql://blackstack:<db-password>@free-tier14.aws-us-east-1.cockroachlabs.cloud:26257/blackstack?sslmode=verify-full&options=--cluster=blackstack-4545
From Ruby, such a connection string works fine if I use the pg
gem, but it fails if I use Sequel
.
Here is the testing code:
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=blackstack-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)"
Here is the full output of the command:
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>'
CodePudding user response:
I fixed it my self.
I worked with the below connection string using the format cluster_name.db_name instead.
postgresql://blackstack:<db-password>@free-tier14.aws-us-east-1.cockroachlabs.cloud:26257/blackstack-4545.blackstack?sslmode=verify-full