【问题标题】:Can't INSERT INTO ClickHouse DB due to Insufficient permissions: /var/lib/clickhouse/data/由于权限不足,无法插入 ClickHouse 数据库:/var/lib/clickhouse/data/
【发布时间】:2021-03-26 04:32:48
【问题描述】:

我通过 docker-compose 在容器中创建了 ClickHouse DB 的实例:

version: '3'

services:
  ch:
    image: yandex/clickhouse-server
    restart: on-failure
    volumes:
      - '/mnt/c/DevTools/source/storm/clickhouse_setup/data/ch:/var/lib/clickhouse/'
      - './ch_configs:/etc/clickhouse-server/'
    ports:
      - 9000:9000
      - 8123:8123
    ulimits:
      nofile: 262144
    
  client:
    image: yandex/clickhouse-client
    volumes:
      - './client-config.xml:/etc/clickhouse-client/config.xml'

我可以访问它并找到我创建的数据库,但是当我运行时

INSERT INTO simple_people (id, first_name, last_name) VALUES(1,'david','lo')

我收到以下回复:

Query id: 46ef1af8-5728-425e-87f5-511f7e0e79d1
Received exception from server (version 20.12.3):
Code: 1000. DB::Exception: Received from ch:9000. DB::Exception: Access to file denied: insufficient permissions: /var/lib/clickhouse/data/registry/simple_people/tmp_insert_1_2_2_0.
1 rows in set. Elapsed: 0.068 sec.

如何获得 INSERT INTO 权限?

注意事项:

我运行没有问题:

SELECT * FROM simple_people

我在 WSL:Ubuntu-20.04

【问题讨论】:

  • 您好,请不要张贴您的代码图片。您可以在代码块前后使用 3 个反引号将代码插入帖子中。
  • 尝试为当前用户授予对包含数据的文件夹的写入权限:chmod -R u=rw ./data/ch
  • @vladimir 感谢您的意见。我运行命令 chmod -R u=rw ./data/ch 没有问题,但它仍然不允许我访问该文件。

标签: docker docker-compose clickhouse


【解决方案1】:

我直接在没有 docker 的 Windows server 2019 上的 WSL Ubuntu 18.04 上安装了 clickhouse,但遇到了同样的问题。在我的情况下,我试图将数据插入到具有 ClickHouse 存储策略设置的表中,以便所有数据都存储在 /mnt/f/clickhouse 中(Windows 上的 F:\clickhouse)。我得到的错误是:

DB::Exception: Access to file denied: insufficient permissions: /mnt/f/clickhouse/store/1e6/1e69cad8-25a1-4ec5-ab5b-fb32d73b7c8c/tmp_insert_all_2_2_0

该问题的解决方法是启用 WSL 上的元数据功能,该功能通过重新挂载启用该功能的 F: 驱动器在 linux 和 windows 之间同步权限。如果 clickhouse 文件夹已经存在,则重新创建它。

sudo umount /mnt/f
sudo mount -t drvfs F: /mnt/f -o metadata

额外信息

如果您对如何在 clickhouse 上设置存储策略以选择数据位置有任何疑问。以下是我的 /etc/clickhouse-server/config.d/storage.xml 的内容

<yandex>
  <storage_configuration>
    <disks>
      <!--
          default disk is special, it always
          exists even if not explicitly
          configured here, but you can't change
          it's path here (you should use <path>
          on top level config instead)
      -->
      <default>
         <!--
             You can reserve some amount of free space
             on any disk (including default) by adding
             keep_free_space_bytes tag
         -->
         <keep_free_space_bytes>1024</keep_free_space_bytes>
      </default>

      <mnt_f>
         <!--
         disk path must end with a slash,
         folder should be writable for clickhouse user
         -->
         <path>/mnt/f/clickhouse/</path>
      </mnt_f>
    </disks>
    <policies>
      <mnt_f_only> <!-- name for new storage policy -->
        <volumes>  
          <mnt_f_volume> <!-- name of volume -->
            <!-- 
                we have only one disk in that volume  
                and we reference here the name of disk
                as configured above in <disks> section
            -->
            <disk>mnt_f</disk>
          </mnt_f_volume>
        </volumes>
      </mnt_f_only>
    </policies>
  </storage_configuration>
</yandex>

创建表时选择存储策略:

CREATE TABLE test(
    EventId String,
    EventName Nullable(String),
) ENGINE = MergeTree()
ORDER BY EventId
SETTINGS storage_policy = 'mnt_f_only';

【讨论】:

    【解决方案2】:

    这是因为 WSL + docker。

    尝试完整路径,而不是 ./data

    【讨论】:

    • 感谢您的输入,但输入完整路径而不是 ."/data.." 没有这样做。
    • 那可能就无解了。尝试在没有 docker 的情况下在 WSL 中安装/运行 CH。或者使用 VirtualBox。问题不在 CH 中。
    猜你喜欢
    • 2020-04-08
    • 2019-04-17
    • 1970-01-01
    • 2020-07-12
    • 2019-01-31
    • 2019-03-04
    • 2021-03-31
    • 2012-09-11
    • 1970-01-01
    相关资源
    最近更新 更多