IMSMWU/RClickhouse

Can't connect to local clickhouse

Closed this issue · 8 comments

Hi!

On a local machine in linux (docker), I deployed clickhouse via wsl2, was able to successfully connect to DBeaver (outside of docker, deployed on windows) and make a number of requests. I also connected to it via the clickhouse-client and downloaded 15 GB of data.

However, I want to connect to ClickHouse via R. My Settings:

conn <-
  DBI::dbConnect(
    drv = Clickhouse::clickhouse(),
    host = 'localhost',
    port = 8123L,
    user = 'default',
    password = ''
  )

I tried port 9000, tried ports without L, tried to write 127.0.0.1 instead of localhost - nothing works.

What do I need to do so that I can connect to ClickHouse via R?

Hi @avraam-1997 ,

you misspelled Clickhouse and instead wrote Clockhouse and also there seems to be a space inside the dbConnect call.

Most of the arguments you are giving the DBI::dbConnect function are already default values. So if all you want is establish a basic connection to the Clickhouse Server all you should have to do is this:

con <- DBI::dbConnect(RClickhouse::clickhouse())

Hope that it helps : )

Hi @avraam-1997 ,

you misspelled Clickhouse and instead wrote Clockhouse and also there seems to be a space inside the dbConnect call.

Most of the arguments you are giving the DBI::dbConnect function are already default values. So if all you want is establish a basic connection to the Clickhouse Server all you should have to do is this:

con <- DBI::dbConnect(RClickhouse::clickhouse())

Hope that it helps : )

I'm sorry, I used Google translate, and suddenly it changed the code.

In fact, the code is written correctly. Fixed the request.

So this is not a solution yet.

Please open this issue again.

Since port 8123 is the HTTP interface, it is not supposed to work. We only support the CH-native (binary) protocol, which uses port 9000. Clickhouse-client also uses the native port. Consequently, you just have to use the same configuration (e.g., host, username, password, and port). Are you sure that "default" is your user? Sounds more like the default database. Please provide both the call/configuration of clickhouse-client and the RClickhouse such that we can check it ...

image

Here is the connection to the clickhouse. Of course, I tried substituting the 9000 port in the request instead of 8123 - the result is the same: connection refused

Also the container assembly code:
docker run -d --name db-clickhouse -p 8123:8123 -p 9000:9000 --ulimit nofile=262144:262144 -v $(realpath ./ch_data):/var/lib/clickhouse/ -v $(realpath ./ch_logs):/var/log/clickhouse-server/ db-clickhouse.v-test:21.10.1

Solved a problem.

CLH was deployed in one container and RStudio in another with a separate subnet.

Created my subnet: docker network create main

I specified the connection to this subnet in the docker-compose ShinyProxy and ClickHouse:

networks:
   # https://docs.docker.com/compose/networking/#configure-the-default-network
   default:
     external: true
     name: main

Accessing the database by mask - the name of the container. http://db-clickhouse:9000

Awesome! Thanks for reporting back.

Hi @avraam-inside would this issue also arise if I'm running Rstudio in one Docker container but ClickHouse is installed natively (no Docker)?

Hi @avraam-inside would this issue also arise if I'm running Rstudio in one Docker container but ClickHouse is installed natively (no Docker)?

Hi! Of course, I'm not sure about anything, but you probably won't be able to connect to localhost. You can try to scan all possible networks inside the container and look for a ClickHouse host (to begin with). It is likely that your internet ip + port will be inside the container :9000/8123