ClickHouse is the fastest column-oriented database for analytical queries — scanning billions of rows per second on commodity hardware. Running ClickHouse on a Hong Kong VPS enables real-time dashboards, log analytics, e-commerce reporting, and ad metrics processing for Asia-Pacific data at a fraction of BigQuery or Snowflake costs. ClickHouse’s columnar storage and vectorised query execution make it 10–100× faster than PostgreSQL for analytical aggregations.
ClickHouse vs PostgreSQL vs BigQuery for Analytics
| Factor | ClickHouse (HK VPS) | PostgreSQL | BigQuery |
|---|---|---|---|
| 1B row aggregation | 0.1–2 seconds | 5–60 minutes | 5–30 seconds |
| Storage (columnar compression) | 3–10× less than raw | 1–2× less | Managed |
| Cost (1 TB/month scanned) | ~$20–60 VPS flat | Slow (not designed for this) | $5 per TB scanned |
| Data gravity (China) | On-prem HK VPS | On-prem | US data centres |
| SQL support | Near-full SQL + CH extensions | Full SQL | Standard SQL |
Step 1: Install ClickHouse
<code">apt install -y apt-transport-https ca-certificates curl curl -fsSL 'https://packages.clickhouse.com/rpm/lts/repodata/repomd.xml.key' | gpg --dearmor \ > /usr/share/keyrings/clickhouse-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/clickhouse-keyring.gpg] \ https://packages.clickhouse.com/deb stable main" \ > /etc/apt/sources.list.d/clickhouse.list apt update && apt install -y clickhouse-server clickhouse-client systemctl enable --now clickhouse-server clickhouse-client # Test connection # :) SELECT 1
Step 2: Configure for Production
<code"># /etc/clickhouse-server/config.d/production.xml
<clickhouse>
<!-- Bind to localhost only; Nginx proxies external access -->
<listen_host>127.0.0.1</listen_host>
<!-- Increase max memory for queries (70% of VPS RAM) -->
<max_server_memory_usage_to_ram_ratio>0.7</max_server_memory_usage_to_ram_ratio>
<!-- Data path -->
<path>/var/lib/clickhouse/</path>
<tmp_path>/var/lib/clickhouse/tmp/</tmp_path>
<!-- Log rotation -->
<logger>
<level>information</level>
<log>/var/log/clickhouse-server/clickhouse-server.log</log>
<errorlog>/var/log/clickhouse-server/clickhouse-server.err.log</errorlog>
<size>1000M</size>
<count>3</count>
</logger>
</clickhouse>
# /etc/clickhouse-server/users.d/production.xml — set password
<clickhouse>
<users>
<default>
<password_sha256_hex>SHA256_OF_YOUR_PASSWORD</password_sha256_hex>
<networks><ip>127.0.0.1/8</ip></networks>
</default>
<analytics_user>
<password_sha256_hex>SHA256_OF_ANALYTICS_PASS</password_sha256_hex>
<networks><ip>127.0.0.1/8</ip></networks>
<profile>readonly</profile>
<quota>default</quota>
</analytics_user>
</users>
</clickhouse>
Step 3: Create Analytical Tables
<code"># Connect and create tables
clickhouse-client --password YourPass
-- E-commerce events table
CREATE TABLE IF NOT EXISTS ecommerce.events
(
event_time DateTime64(3, 'Asia/Hong_Kong'),
event_date Date DEFAULT toDate(event_time), -- Auto-populated for partitioning
event_type LowCardinality(String), -- LowCardinality = dictionary compression
user_id UInt64,
session_id String,
product_id Nullable(UInt64),
order_id Nullable(UInt64),
revenue Nullable(Decimal(18, 2)),
currency LowCardinality(String),
country LowCardinality(String),
device_type LowCardinality(String),
referrer String
)
ENGINE = MergeTree()
PARTITION BY toYYYYMM(event_date) -- Monthly partitions
ORDER BY (event_date, event_type, user_id) -- Primary key (sorting key)
TTL event_date + INTERVAL 2 YEAR -- Auto-delete data older than 2 years
SETTINGS index_granularity = 8192;
-- Web server access log table
CREATE TABLE IF NOT EXISTS logs.nginx
(
time DateTime64(3),
remote_addr String,
method LowCardinality(String),
path String,
status UInt16,
bytes UInt64,
duration_ms UInt32,
user_agent String
)
ENGINE = MergeTree()
PARTITION BY toYYYYMMDD(time)
ORDER BY (time, status)
TTL time + INTERVAL 90 DAY;
Step 4: Powerful Analytical Queries
<code"># Revenue by country, last 30 days
SELECT
country,
count() AS orders,
sum(revenue) AS total_revenue,
avg(revenue) AS avg_order_value,
uniq(user_id) AS unique_customers
FROM ecommerce.events
WHERE event_type = 'purchase'
AND event_date >= today() - 30
GROUP BY country
ORDER BY total_revenue DESC
LIMIT 20;
-- Runs in <1 second on 100M rows
-- Funnel analysis: view → add_to_cart → purchase
SELECT
countIf(event_type = 'product_view') AS views,
countIf(event_type = 'add_to_cart') AS add_to_cart,
countIf(event_type = 'purchase') AS purchases,
round(100 * countIf(event_type = 'add_to_cart') / countIf(event_type = 'product_view'), 1) AS view_to_cart_pct,
round(100 * countIf(event_type = 'purchase') / countIf(event_type = 'add_to_cart'), 1) AS cart_to_purchase_pct
FROM ecommerce.events
WHERE event_date >= today() - 7;
-- Top 10 slow Nginx paths
SELECT
path,
count() AS requests,
quantile(0.95)(duration_ms) AS p95_ms,
quantile(0.99)(duration_ms) AS p99_ms
FROM logs.nginx
WHERE time >= now() - INTERVAL 1 HOUR
AND status = 200
GROUP BY path
HAVING requests > 100
ORDER BY p95_ms DESC
LIMIT 10;
Step 5: Ingest Data from PostgreSQL
<code"># ClickHouse can read from PostgreSQL directly (for migration or cross-DB joins)
CREATE TABLE pg_products_mirror
(
id UInt64, name String, price Decimal(10,2), created_at DateTime
)
ENGINE = PostgreSQL('localhost:5432', 'myapp_db', 'products', 'myapp_user', 'DbPass!');
-- Copy to ClickHouse native storage
INSERT INTO ecommerce.products SELECT * FROM pg_products_mirror;
# Or use Python to stream from any source
import clickhouse_driver
client = clickhouse_driver.Client('localhost', password='YourPass')
client.execute('INSERT INTO ecommerce.events VALUES', rows, types_check=True)
Step 6: Grafana Dashboard
<code"># Connect Grafana to ClickHouse
# Grafana → Plugins → Install "ClickHouse" plugin
# Data Source → ClickHouse:
# Server: localhost
# Port: 9000 (native) or 8123 (HTTP)
# User: analytics_user
# Database: ecommerce
# Sample Grafana query (revenue over time):
SELECT
toStartOfHour(event_time) AS time,
sum(revenue) AS revenue
FROM ecommerce.events
WHERE event_type = 'purchase'
AND $__timeFilter(event_time)
GROUP BY time
ORDER BY time
Conclusion
ClickHouse on a Hong Kong VPS handles analytical workloads that would bring PostgreSQL to its knees — billion-row aggregations in seconds, 90%+ storage compression via columnar encoding, and Grafana dashboards that refresh in real time. For Asia-Pacific e-commerce platforms, ad tech companies, and SaaS businesses storing event data and access logs, ClickHouse on a 4–8 GB HK VPS eliminates BigQuery egress costs and keeps sensitive transaction data on infrastructure you control, with the CN2 GIA network ensuring Chinese data sources reach the database efficiently.
Analyse your data faster: Browse Server.HK Hong Kong VPS plans — an 8 GB NVMe plan with ClickHouse handles hundreds of millions of events for typical e-commerce analytics workloads.