๋ฐ์ดํ„ฐ ์—”์ง€๋‹ˆ์–ด๋ง

๋ฐ์ดํ„ฐ ๋ถ„์„ ํ™˜๊ฒฝ ๊ตฌ์ถ• - 01. Clickhouse๋ž€?

Tempo 2025. 3. 20. 09:00

๋ฐ์ดํ„ฐ ๋ถ„์„์„ ์œ„ํ•œ ๊ฐ•๋ ฅํ•œ OLAP ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์ฐพ๊ณ  ๊ณ„์‹ ๊ฐ€์š”?
ClickHouse๋Š” ๋น ๋ฅธ ์†๋„์™€ ํ™•์žฅ์„ฑ์„ ์ž๋ž‘ํ•˜๋Š” ์ปฌ๋Ÿผํ˜• ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋กœ, ๋Œ€๊ทœ๋ชจ ๋ฐ์ดํ„ฐ ๋ถ„์„์— ์ตœ์ ํ™”๋œ ์†”๋ฃจ์…˜์ž…๋‹ˆ๋‹ค.
์ด ๊ธ€์—์„œ๋Š” ClickHouse์˜ ๊ฐœ๋…์„ ์ดํ•ดํ•˜๊ณ , ์ง์ ‘ ์‹ค์Šต์„ ํ†ตํ•ด ๊ธฐ๋ณธ์ ์ธ ์‚ฌ์šฉ๋ฒ•์„ ์ตํ˜€๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

1. ClickHouse๋ž€?

ClickHouse๋Š” Yandex์—์„œ ๊ฐœ๋ฐœํ•œ ์˜คํ”ˆ์†Œ์Šค ์ปฌ๋Ÿผํ˜• ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋กœ, ํŠนํžˆ ๋Œ€๊ทœ๋ชจ ๋ฐ์ดํ„ฐ ๋ถ„์„(OLAP)์— ์ตœ์ ํ™”๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
๋‹ค๋ฅธ RDBMS์™€ ๋‹ฌ๋ฆฌ ์ปฌ๋Ÿผ ๋‹จ์œ„ ์ €์žฅ ๋ฐฉ์‹์„ ์ฑ„ํƒํ•˜์—ฌ ๋น ๋ฅธ ์ฟผ๋ฆฌ ์„ฑ๋Šฅ๊ณผ ํšจ์œจ์ ์ธ ๋ฐ์ดํ„ฐ ์••์ถ•์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

ClickHouse์˜ ์ฃผ์š” ํŠน์ง•

โœ… ์ปฌ๋Ÿผ ๊ธฐ๋ฐ˜ ์ €์žฅ(Columnar Storage) → ๋น ๋ฅธ ๋ถ„์„ ์ฟผ๋ฆฌ ์†๋„
โœ… ๋ถ„์‚ฐ ์•„ํ‚คํ…์ฒ˜(Distributed Architecture) → ๋Œ€๊ทœ๋ชจ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ ๊ฐ€๋Šฅ
โœ… ์‹ค์‹œ๊ฐ„ ๋ฐ์ดํ„ฐ ์‚ฝ์ž… ๋ฐ ๋ถ„์„(Real-time Ingestion & Querying)
โœ… ๋น ๋ฅธ ์ง‘๊ณ„ ์—ฐ์‚ฐ ๋ฐ ํšจ์œจ์ ์ธ ์ธ๋ฑ์‹ฑ(Aggregation & Indexing)

ClickHouse vs. PostgreSQL ๋น„๊ต

ํŠน์„ฑ ClickHouse PostgreSQL

๋ฐ์ดํ„ฐ ์ €์žฅ ๋ฐฉ์‹ ์ปฌ๋Ÿผ ๊ธฐ๋ฐ˜(Column-oriented) ํ–‰ ๊ธฐ๋ฐ˜(Row-oriented)
๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ ์œ ํ˜• OLAP (๋ถ„์„์šฉ) OLTP (ํŠธ๋žœ์žญ์…˜)
์ฝ๊ธฐ ์„ฑ๋Šฅ ๋งค์šฐ ๋น ๋ฆ„ ์ƒ๋Œ€์ ์œผ๋กœ ๋Š๋ฆผ
์“ฐ๊ธฐ ์„ฑ๋Šฅ ๋ฐฐ์น˜ ์‚ฝ์ž…์— ์ตœ์ ํ™” ๋‹จ์ผ ํ–‰ ์‚ฝ์ž…์— ์ ํ•ฉ
ํŠธ๋žœ์žญ์…˜ ์ง€์› ์ œํ•œ์  ๊ฐ•๋ ฅํ•œ ํŠธ๋žœ์žญ์…˜ ์ง€์›

ClickHouse๋Š” OLTP(ํŠธ๋žœ์žญ์…˜ ์ฒ˜๋ฆฌ)๋ณด๋‹ค๋Š” OLAP(๋Œ€๊ทœ๋ชจ ๋ถ„์„ ์ž‘์—…)์— ์ ํ•ฉํ•ฉ๋‹ˆ๋‹ค.
์ฆ‰, ๋น ๋ฅธ ์ง‘๊ณ„ ์ฟผ๋ฆฌ์™€ ๋Œ€๊ทœ๋ชจ ๋ฐ์ดํ„ฐ ์กฐํšŒ๊ฐ€ ํ•„์š”ํ•œ ๊ฒฝ์šฐ ClickHouse๊ฐ€ PostgreSQL๋ณด๋‹ค ํ›จ์”ฌ ์œ ๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

2. ClickHouse ์‹ค์Šต: Docker๋กœ ๋น ๋ฅด๊ฒŒ ์‹คํ–‰ํ•˜๊ธฐ

ClickHouse๋ฅผ ์„ค์น˜ํ•˜๋Š” ๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ ๋ฐฉ๋ฒ•์€ Docker๋ฅผ ์ด์šฉํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.
์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ๊ฐ„๋‹จํžˆ ClickHouse๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

docker run -d --name test-clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server

์ด์ œ ClickHouse์— ์ ‘์†ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

docker exec -it some-clickhouse-server clickhouse-client

ํ…Œ์ด๋ธ”์„ ์ƒ์„ฑํ•˜๊ณ  ์ƒ˜ํ”Œ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฝ์ž…ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

CREATE TABLE users (
    id UInt32,
    name String,
    age UInt8
) ENGINE = MergeTree()
ORDER BY id;

INSERT INTO users VALUES (1, 'Alice', 25), (2, 'Bob', 30), (3, 'Charlie', 35);

SELECT * FROM users;

ClickHouse๋Š” ์ปฌ๋Ÿผ ๊ธฐ๋ฐ˜ ์ €์žฅ ๋ฐฉ์‹ ๋•๋ถ„์— ๋Œ€๋Ÿ‰์˜ ๋ฐ์ดํ„ฐ ๋ถ„์„ ๋ฐ ์ง‘๊ณ„ ์ž‘์—…์—์„œ ๋›ฐ์–ด๋‚œ ์„ฑ๋Šฅ์„ ๋ณด์ž…๋‹ˆ๋‹ค.

3. ClickHouse์˜ ํ•œ๊ณ„ ๋ฐ ๊ณ ๋ คํ•  ์ 

๐Ÿšง OLTP ์›Œํฌ๋กœ๋“œ์— ์ ํ•ฉํ•˜์ง€ ์•Š์Œ

  • ClickHouse๋Š” UPDATE, DELETE ์—ฐ์‚ฐ์ด ๋น„ํšจ์œจ์ ์ž…๋‹ˆ๋‹ค.
  • ์‹ค์‹œ๊ฐ„ ํŠธ๋žœ์žญ์…˜ ์ฒ˜๋ฆฌ๋ณด๋‹ค๋Š” ๋Œ€๋Ÿ‰ ๋ฐ์ดํ„ฐ ๋ถ„์„์— ํŠนํ™”๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

๐Ÿšง ๊ณ ๊ธ‰ ์„ค์ • ํ•„์š”

  • ๊ธฐ๋ณธ ์„ค์ •์œผ๋กœ๋„ ๋น ๋ฅด์ง€๋งŒ, ์ฟผ๋ฆฌ ์ตœ์ ํ™” ๋ฐ ์—”์ง„ ํŠœ๋‹์ด ํ•„์š”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๋ฐ˜์‘ํ˜•