程序在尝试打开与 ClickhouseDB 的连接时挂起?
Program hangs when trying to open a connection to ClickhouseDB?
我正在尝试从我的应用程序连接到本地 ClickhouseDB 以执行一些原始查询。当我尝试打开连接时出现问题。它从不从方法调用中 returns。
ClickhouseDB 在 docker 容器中启动。
using (ClickHouseConnection conn = connFactory.CreateConnection(new ClickHouseConnectionSettings(connectionString)))
{
var cmd = conn.CreateCommand();
cmd.CommandText = "select * from default.table_name";
conn.Open(); // it never goes past this line
using (var reader = cmd.ExecuteReader())
...
我想在 conn.Open()
之后打开一个连接并继续执行程序到执行 reader.
的下一行
注意:
如果我尝试从 python 控制台连接,绝对没有问题。
from clickhouse_driver import Client
client = Client(host='localhost')
client.execute('select * from default.table_name')
# [(4, 'four'), (5, 'five'), (1, 'one'), (2, 'two'), (3, 'three')]
更新:
连接超时后的堆栈跟踪:
System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at InhouseNamespace.ClickHouse.Impl.ProtocolFormatter.ReadBytes(Int32 i)
...
docker-compose 部署 Clickhouse。我不是 docker 专家,所以当它运行时我对数据库很满意并且我能够通过 Tabix web UI:
连接到它
version: "3.7"
services:
clickhouse:
image: yandex/clickhouse-server
ports:
- "8123:8123"
- "9000:9000"
- "9009:9009"
ulimits:
nproc: 65535
nofile:
soft: 262144
hard: 262144
client:
image: yandex/clickhouse-client
command: ['--host', 'server']
更新:
连接到非本地 CassandraDB 后,问题消失了,这意味着连接到我的本地 CassandraDb(在 docker 容器中)时出现问题。
您使用的连接字符串似乎不正确。
取出 "port" 密钥并将端口号附加到服务器(您现在已将其命名为 'host')密钥,如下所示:
"Server=127.0.0.1,8123;User=default;Password=;Database=default;Compress=True;CheckCompressedHash=False;SocketTimeout=60000000;Compressor=lz4"
谢谢,
加里
端口 8123 用作 HTTP 接口的默认端口。但是在使用时:
conn.Open();
using (var reader = cmd.ExecuteReader())
通信是通过本地 clickhouse 客户端完成的,因此必须使用端口 9000。
要解决此问题,请更改连接字符串中的端口。完整的连接字符串将如下所示:connString = "Host=127.0.0.1;Port=9000;User=default;Password=;Database=default;Compress=True;CheckCompressedHash=False;SocketTimeout=60000000;Compressor=lz4"
我正在尝试从我的应用程序连接到本地 ClickhouseDB 以执行一些原始查询。当我尝试打开连接时出现问题。它从不从方法调用中 returns。
ClickhouseDB 在 docker 容器中启动。
using (ClickHouseConnection conn = connFactory.CreateConnection(new ClickHouseConnectionSettings(connectionString)))
{
var cmd = conn.CreateCommand();
cmd.CommandText = "select * from default.table_name";
conn.Open(); // it never goes past this line
using (var reader = cmd.ExecuteReader())
...
我想在 conn.Open()
之后打开一个连接并继续执行程序到执行 reader.
注意: 如果我尝试从 python 控制台连接,绝对没有问题。
from clickhouse_driver import Client
client = Client(host='localhost')
client.execute('select * from default.table_name')
# [(4, 'four'), (5, 'five'), (1, 'one'), (2, 'two'), (3, 'three')]
更新: 连接超时后的堆栈跟踪:
System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at InhouseNamespace.ClickHouse.Impl.ProtocolFormatter.ReadBytes(Int32 i)
...
docker-compose 部署 Clickhouse。我不是 docker 专家,所以当它运行时我对数据库很满意并且我能够通过 Tabix web UI:
连接到它version: "3.7"
services:
clickhouse:
image: yandex/clickhouse-server
ports:
- "8123:8123"
- "9000:9000"
- "9009:9009"
ulimits:
nproc: 65535
nofile:
soft: 262144
hard: 262144
client:
image: yandex/clickhouse-client
command: ['--host', 'server']
更新: 连接到非本地 CassandraDB 后,问题消失了,这意味着连接到我的本地 CassandraDb(在 docker 容器中)时出现问题。
您使用的连接字符串似乎不正确。
取出 "port" 密钥并将端口号附加到服务器(您现在已将其命名为 'host')密钥,如下所示:
"Server=127.0.0.1,8123;User=default;Password=;Database=default;Compress=True;CheckCompressedHash=False;SocketTimeout=60000000;Compressor=lz4"
谢谢, 加里
端口 8123 用作 HTTP 接口的默认端口。但是在使用时:
conn.Open();
using (var reader = cmd.ExecuteReader())
通信是通过本地 clickhouse 客户端完成的,因此必须使用端口 9000。
要解决此问题,请更改连接字符串中的端口。完整的连接字符串将如下所示:connString = "Host=127.0.0.1;Port=9000;User=default;Password=;Database=default;Compress=True;CheckCompressedHash=False;SocketTimeout=60000000;Compressor=lz4"