Skip to content

Instantly share code, notes, and snippets.

@Slach
Last active July 8, 2021 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Slach/c17d50ca4b2e2785ce957debc7548420 to your computer and use it in GitHub Desktop.
Save Slach/c17d50ca4b2e2785ce957debc7548420 to your computer and use it in GitHub Desktop.
system.detached_parts not works after change default storage policy to multi-disk
version: "3"
services:
clickhouse:
image: yandex/clickhouse-server:${CLICKHOUSE_VERSION:-latest}
#!/usr/bin/env bash
set -xueo pipefail
docker-compose down --remove-orphans
docker-compose up -d clickhouse
DETACHED_QUERY="
SELECT
count() AS detached_parts,
database,
table,
disk,
if(coalesce(reason,'unknown')='','detached_by_user',coalesce(reason,'unknown')) AS detach_reason
FROM system.detached_parts
GROUP BY
database,
table,
disk,
reason
"
NEW_DEFAULT_STORAGE_POLICY="
<yandex>
<storage_configuration>
<disks>
<disk2>
<path>/var/lib/clickhouse2/</path>
</disk2>
</disks>
<policies>
<default>
<volumes>
<default>
<disk>disk2</disk>
<disk>default</disk>
</default>
</volumes>
</default>
</policies>
</storage_configuration>
</yandex>
"
docker-compose exec clickhouse clickhouse-client -q "CREATE TABLE default.t1(id UInt64) ENGINE=MergeTree() ORDER BY id"
docker-compose exec clickhouse clickhouse-client -q "${DETACHED_QUERY}"
docker-compose exec clickhouse bash -c "mkdir -p /var/lib/clickhouse2 && chown -v clickhouse:clickhouse /var/lib/clickhouse2 && echo '${NEW_DEFAULT_STORAGE_POLICY}' > /etc/clickhouse-server/config.d/new_storage_policy.xml"
docker-compose exec clickhouse clickhouse-client -q "SYSTEM RELOAD CONFIG"
docker-compose exec clickhouse bash -c "ls -la /var/lib/clickhouse2"
docker-compose exec clickhouse clickhouse-client -q "${DETACHED_QUERY}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment