name: clickhouse
service_id: 120
service_display_name: ClickHouse
service_short_name: clickhouse
service_man: '# Инструкция по управлению кластерами и пользователями ClickHouse
---
## Общая информация
ClickHouse — это колоночная система управления базами данных, предназначенная
для обработки аналитических запросов в реальном времени. Платформа позволяет создавать, удалять, приостанавливать и возобновлять кластеры ClickHouse, а также управлять базами данных и пользователями.
Кластер
создаётся через оператор Altinity (`https://github.com/Altinity/clickhouse-operator`) в ресурсной платформе типа `k8s`
Кластеры могут создаваться шардированными с произвольным количеством реплик.
Для обеспечения отказоустойчивости и координации обязательно включение параметра `Создать ClickHouse-Keeper`.
Кластера создаются с обязательным бекапом. Для этого необходимо предварительно создать
услугу `S3 Object Storage`.
---
## Доступные операции
* **create** — Создание кластера
* **delete** — Удаление кластера
* **suspend** — Приостановка работы кластера
*
**resume** — Возобновление работы кластера
* **create_database** — Создание базы данных
* **delete_database** — Удаление базы данных
* **create_user** — Создание пользователя и настройка
прав доступа к базе данных
* **delete_user** — Удаление пользователя
## Процесс создания и первого подключения
1. Выполнить операцию `create` - будет создан кластер
2. Выполнить
операцию `create_database` - будет создана база данных
3. Выполнить операцию `create_user` - будет создан пользователь (выбрать доступ подключения к БД, созданной в п.2)
## Примеры подключения
###
Подключение через HTTP-интерфейс
```bash
# Проверка доступности кластера
curl "http://:@:8123/" -d "SELECT 1"
# Выполнение запроса
curl "http://:@:8123/"
-d "SHOW DATABASES"
```
## Простые кейсы
*Создать БД и обычной таблицы*
```clickhouse
CREATE TABLE database.table
(
id UInt64,
value String
)
ENGINE
= MergeTree()
ORDER BY id;
INSERT INTO database.table SELECT number, toString(number) FROM numbers(10000000);
SELECT count() FROM database.table;
```
Базы и таблицы не реплицируются
без специального ключа (`ON CLUSTER ''clickhousek8s''`)
В случае создания в стиле, описанным выше, необходимо будет выполнять действия на всех шардах/репликах
*Создание БД и шардированной
таблицы*
```clickhouse
CREATE TABLE database.localUsers
(
id UInt64,
value String
)
ENGINE = MergeTree()
ORDER BY id;
CREATE TABLE database.shardedTable
AS
localUsers
ENGINE = Distributed(''clickhousek8s'', ''database'', ''localUsers'', id);
INSERT INTO shardedTable SELECT number, toString(number) FROM numbers(10000000);
SELECT count()
FROM shardedTable;
```
Важный момент - в данном примере таблицы придётся также выполнять на всех нодах ClickHouse
*Создание реплицируемой и шардированной таблицы*
```clickhouse
CREATE
TABLE IF NOT EXISTS database.localUsers ON cluster ''clickhousek8s''
(
user_id UInt64,
name String,
email String
)
ENGINE = ReplicatedMergeTree(
''/clickhouse/tables/{shard}/localUsers'',
''{replica}''
)
ORDER
BY user_id;
CREATE TABLE IF NOT EXISTS database.users ON cluster ''clickhousek8s''
AS database.localUsers
ENGINE = Distributed(''clickhousek8s'', ''database'', ''localUsers'', rand());
INSERT
INTO database.users VALUES (1, ''Alice'', ''alice@example.com'');
INSERT INTO database.users VALUES (2, ''Bob'', ''bob@example.com'');
INSERT INTO database.users VALUES (3, ''Charlie'', ''charlie@example.com'');
INSERT
INTO database.users VALUES (4, ''David'', ''david@example.com'');
INSERT INTO database.users VALUES (5, ''Gosha'', ''gosha@example.com'');
INSERT INTO database.users VALUES (6, ''Eve'', ''eve@example.com'');
INSERT
INTO database.users VALUES (7, ''Frank'', ''frank@example.com'');
INSERT INTO database.users VALUES (8, ''Grace'', ''grace@example.com'');
INSERT INTO database.users VALUES (9, ''Hannah'', ''hannah@example.com'');
INSERT
INTO database.users VALUES (10, ''Ivan'', ''ivan@example.com'');
SELECT * FROM database.localUsers;
SELECT * FROM database.users;
SELECT COUNT(*) AS total_users FROM database.users;
SELECT
COUNT(*) AS total_users_local FROM database.localUsers;
```'
lifecycle:
suspendOnDestroyDefault: true
adoptExistingOnCreateDefault: false
operations:
- svcOperationId: 181
operation: create
kind: instance
action: create
- svcOperationId: 186
operation: create_database
kind: subresource
action: create
- svcOperationId: 185
operation: create_user
kind: subresource
action: create
- svcOperationId: 184
operation: delete
kind: instance
action: delete
- svcOperationId: 188
operation: delete_database
kind: subresource
action: delete
- svcOperationId: 187
operation: delete_user
kind: subresource
action: delete
- svcOperationId: 189
operation: modify
kind: instance
action: modify
- svcOperationId: 276
operation: reconcile
kind: action
action: reconcile
- svcOperationId: 183
operation: resume
kind: instance
action: resume
- svcOperationId: 182
operation: suspend
kind: instance
action: suspend
stateOut:
databases: {}
users: {}
cfsParams:
- svcOperationCfsParamId: 837
svcOperationCfsParam: startupConfiguration
dataType: map-fixed
isRequired: true
defaultValue: ''
isModifiable: false
dataDescriptor:
resourceRealm:
dataType: string
defaultValue: ''
isRequired: true
isModifiable: false
valueList:
- k8s-3-sandbox-nubes-ru
- k8s-4-sandbox-nubes-ru
- svcOperationCfsParamId: 838
svcOperationCfsParam: clusterConfiguration
dataType: map-fixed
isRequired: true
defaultValue: ''
isModifiable: true
dataDescriptor:
cpu:
dataType: integer > 0
defaultValue: '1000'
isRequired: true
isModifiable: false
memory:
dataType: integer > 0
defaultValue: '2048'
isRequired: true
isModifiable: false
replicas:
dataType: integer > 0
defaultValue: '1'
isRequired: true
isModifiable: false
valueList:
- '1'
- '3'
- '5'
- '7'
shards:
dataType: integer > 0
defaultValue: '1'
isRequired: true
isModifiable: false
valueList:
- '1'
- '2'
- '3'
disk:
dataType: integer > 0
defaultValue: '10'
isRequired: true
isModifiable: false
- svcOperationCfsParamId: 839
svcOperationCfsParam: accessConfiguration
dataType: map-fixed
isRequired: true
defaultValue: ''
isModifiable: true
dataDescriptor:
masterIpSpace:
dataType: string
defaultValue: ''
isRequired: true
isModifiable: false
masterAccessList:
dataType: json
defaultValue: '[]'
isRequired: true
isModifiable: false
- svcOperationCfsParamId: 840
svcOperationCfsParam: clickhouseKeeperConfiguration
dataType: map-fixed
isRequired: true
defaultValue: ''
isModifiable: true
dataDescriptor:
cpu:
dataType: integer > 0
defaultValue: '500'
isRequired: true
isModifiable: false
memory:
dataType: integer > 0
defaultValue: '512'
isRequired: true
isModifiable: false
replicas:
dataType: integer >= 0
defaultValue: '0'
isRequired: true
isModifiable: false
valueList:
- '0'
- '1'
- '3'
- svcOperationCfsParamId: 841
svcOperationCfsParam: clickhouseConfiguration
dataType: map-fixed
isRequired: true
defaultValue: ''
isModifiable: true
dataDescriptor:
version:
dataType: string
defaultValue: '25.10'
isRequired: true
isModifiable: false
valueList:
- '25.10'
- svcOperationCfsParamId: 842
svcOperationCfsParam: backupConfiguration
dataType: map-fixed
isRequired: true
defaultValue: ''
isModifiable: true
dataDescriptor:
schedule:
dataType: string
defaultValue: 0 0 * * *
isRequired: true
isModifiable: false
s3Uid:
dataType: uuid
defaultValue: ''
isRequired: true
isModifiable: false
retain:
dataType: integer > 0
defaultValue: '7'
isRequired: true
isModifiable: false
- svcOperationCfsParamId: 843
svcOperationCfsParam: autoscaleConfiguration
dataType: map-fixed
isRequired: true
defaultValue: ''
isModifiable: true
dataDescriptor:
schedule:
dataType: integer >= 0
defaultValue: '0'
isRequired: true
isModifiable: false
valueList:
- '0'
- '5'
- '12'
- '23'
quota:
dataType: integer > 0
defaultValue: '100'
isRequired: true
isModifiable: false
percent:
dataType: integer > 0
defaultValue: '10'
isRequired: true
isModifiable: false
valueList:
- '10'
- '15'
- '20'
enabled:
dataType: boolean
defaultValue: 'false'
isRequired: true
isModifiable: false
valueList:
- 'false'
- 'true'
- svcOperationCfsParamId: 851
svcOperationCfsParam: clickhouseFilesConfiguration
dataType: array-map-fixed
isRequired: false
defaultValue: ''
isModifiable: true
dataDescriptor:
path:
dataType: string
defaultValue: something.xml
isRequired: true
isModifiable: false
xmlConfig:
dataType: string
defaultValue:
isRequired: true
isModifiable: false
- svcOperationCfsParamId: 600
svcOperationCfsParam: dbName
dataType: string
isRequired: true
defaultValue: db01
isModifiable: false
- svcOperationCfsParamId: 596
svcOperationCfsParam: username
dataType: string
isRequired: true
defaultValue: myusername
isModifiable: false
- svcOperationCfsParamId: 598
svcOperationCfsParam: dbName
dataType: array-map-fixed
isRequired: true
defaultValue: '[{}]'
isModifiable: false
dataDescriptor:
dbName:
dataType: string
defaultValue: ''
isRequired: true
isModifiable: false
- svcOperationCfsParamId: 599
svcOperationCfsParam: accessHosts
dataType: string
isRequired: true
defaultValue: ::/0
isModifiable: false
- svcOperationCfsParamId: 602
svcOperationCfsParam: dbName
dataType: string
isRequired: true
defaultValue: ''
isModifiable: true
- svcOperationCfsParamId: 601
svcOperationCfsParam: username
dataType: string
isRequired: true
defaultValue: ''
isModifiable: true
- svcOperationCfsParamId: 844
svcOperationCfsParam: clusterConfiguration
dataType: map-fixed
isRequired: true
defaultValue: ''
isModifiable: true
dataDescriptor:
shards:
dataType: integer > 0
defaultValue: ''
isRequired: true
isModifiable: false
valueList:
- '1'
- '2'
- '3'
disk:
dataType: integer > 0
defaultValue: ''
isRequired: true
isModifiable: false
cpu:
dataType: integer > 0
defaultValue: ''
isRequired: true
isModifiable: false
memory:
dataType: integer > 0
defaultValue: ''
isRequired: true
isModifiable: false
replicas:
dataType: integer > 0
defaultValue: ''
isRequired: true
isModifiable: false
valueList:
- '1'
- '3'
- '5'
- '7'
- svcOperationCfsParamId: 845
svcOperationCfsParam: clickhouseKeeperConfiguration
dataType: map-fixed
isRequired: true
defaultValue: ''
isModifiable: true
dataDescriptor:
replicas:
dataType: integer >= 0
defaultValue: ''
isRequired: true
isModifiable: false
valueList:
- '0'
- '1'
- '3'
cpu:
dataType: integer > 0
defaultValue: ''
isRequired: true
isModifiable: false
memory:
dataType: integer > 0
defaultValue: ''
isRequired: true
isModifiable: false
- svcOperationCfsParamId: 846
svcOperationCfsParam: accessConfiguration
dataType: map-fixed
isRequired: true
defaultValue: ''
isModifiable: true
dataDescriptor:
masterIpSpace:
dataType: string
defaultValue: ''
isRequired: true
isModifiable: false
masterAccessList:
dataType: json
defaultValue: ''
isRequired: true
isModifiable: false
- svcOperationCfsParamId: 847
svcOperationCfsParam: clickhouseConfiguration
dataType: map-fixed
isRequired: true
defaultValue: ''
isModifiable: true
dataDescriptor:
version:
dataType: string
defaultValue: ''
isRequired: true
isModifiable: false
valueList:
- '25.10'
- svcOperationCfsParamId: 848
svcOperationCfsParam: backupConfiguration
dataType: map-fixed
isRequired: true
defaultValue: ''
isModifiable: true
dataDescriptor:
s3Uid:
dataType: uuid
defaultValue: ''
isRequired: true
isModifiable: false
retain:
dataType: integer > 0
defaultValue: ''
isRequired: true
isModifiable: false
schedule:
dataType: string
defaultValue: ''
isRequired: true
isModifiable: false
- svcOperationCfsParamId: 849
svcOperationCfsParam: autoscaleConfiguration
dataType: map-fixed
isRequired: true
defaultValue: ''
isModifiable: true
dataDescriptor:
enabled:
dataType: boolean
defaultValue: false,true
isRequired: true
isModifiable: false
schedule:
dataType: integer >= 0
defaultValue: ''
isRequired: true
isModifiable: false
valueList:
- '0'
- '5'
- '12'
- '23'
quota:
dataType: integer > 0
defaultValue: ''
isRequired: true
isModifiable: false
percent:
dataType: integer > 0
defaultValue: ''
isRequired: true
isModifiable: false
valueList:
- '10'
- '15'
- '20'
- svcOperationCfsParamId: 850
svcOperationCfsParam: clickhouseFilesConfiguration
dataType: array-map-fixed
isRequired: false
defaultValue: ''
isModifiable: true
dataDescriptor:
path:
dataType: string
defaultValue: something.xml
isRequired: true
isModifiable: false
xmlConfig:
dataType: string
defaultValue:
isRequired: true
isModifiable: false
cfsParamsByOp:
181:
- 837
- 838
- 839
- 840
- 841
- 842
- 843
- 851
186:
- 600
185:
- 596
- 598
- 599
184: []
188:
- 602
187:
- 601
189:
- 844
- 845
- 846
- 847
- 848
- 849
- 850
276: []
183: []
182: []
stateParams:
startupConfiguration: '{"resourceRealm": ""}'
clusterConfiguration: '{"cpu": 1000, "memory": 2048, "replicas": 1, "shards": 1, "disk": 10}'
accessConfiguration: '{"masterIpSpace": "", "masterAccessList": "[]"}'
clickhouseKeeperConfiguration: '{"cpu": 500, "memory": 512, "replicas": 0}'
clickhouseConfiguration: '{"version": "25.10"}'
backupConfiguration: '{"schedule": "0 0 * * *", "s3Uid": "", "retain": 7}'
autoscaleConfiguration: '{"schedule": 0, "quota": 100, "percent": 10, "enabled": false}'
clickhouseFilesConfiguration: '{"path": "something.xml", "xmlConfig": ""}'