### Install chDB Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/chdb/datastore/quickstart.md Install the base chDB package. ```bash pip install "chdb>=4.0" ``` -------------------------------- ### Install optional dependencies Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/chdb/datastore/quickstart.md Install chDB with optional dependencies for pandas, PyArrow, or all. ```bash # For pandas DataFrame support pip install "chdb[pandas]>=4.0" # For PyArrow support pip install "chdb[arrow]>=4.0" # All optional dependencies pip install "chdb[all]>=4.0" ``` -------------------------------- ### Run ClickStack Example Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/use-cases/observability/clickstack/example-datasets/_snippets/_instrument_application.md Execute this command to start the ClickStack example after stopping any previous runs. ```bash # Ctrl-C the previous run, then: ./run.sh ``` -------------------------------- ### Verify Installation Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/chdb/datastore/quickstart.md Check the installed chDB version and confirm DataStore readiness. ```python import chdb print(chdb.__version__) # Should print 4.x.x or higher from chdb import datastore as pd print("DataStore ready!") ``` -------------------------------- ### Install and Run ClickHouse CLI Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/deployment-modes.md Installs the ClickHouse CLI, sets the latest version as default, starts a local server, and opens the client. ```bash # Install the CLI curl https://clickhouse.com/cli | sh # Install the latest ClickHouse, set it as your default, and symlink the clickhouse binary onto your PATH clickhousectl local use latest clickhousectl local server start clickhousectl local client ``` -------------------------------- ### Create the database and table Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/operations_/backup_restore/_snippets/_example_setup.md SQL commands to create a test database named `test_db` and a `test_table` with various columns for backup and restoration examples. ```sql CREATE DATABASE test_db; CREATE TABLE test_db.test_table ( id UUID, name String, email String, age UInt8, salary UInt32, created_at DateTime, is_active UInt8, department String, score Float32, country String ) ENGINE = MergeTree() ORDER BY id; ``` -------------------------------- ### WSL Installation Success Output Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/getting-started/install/_snippets/_windows_install.md Example output after successful WSL installation and initial setup. ```text Welcome to Ubuntu 24.04.1 LTS (GNU/Linux 5.15.133.1-microsoft-WSL2 x86_64) ``` -------------------------------- ### Install Pandas and Apache Arrow Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/chdb/getting-started.md Command to install Pandas and PyArrow libraries. ```bash pip install pandas pyarrow ``` -------------------------------- ### Create sample tables Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/cloud/managed-postgres/quickstart.md Create two sample tables, 'events' and 'users', for demonstration. ```sql CREATE TABLE events ( event_id SERIAL PRIMARY KEY, event_name VARCHAR(255) NOT NULL, event_type VARCHAR(100), event_timestamp TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, event_data JSONB, user_id INT, user_ip INET, is_active BOOLEAN DEFAULT TRUE, created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE users ( user_id SERIAL PRIMARY KEY, name VARCHAR(100), country VARCHAR(50), platform VARCHAR(50) ); ``` -------------------------------- ### Old distributions method for installing the deb-packages Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/getting-started/install/_snippets/_deb_install.md Commands for installing ClickHouse on older Debian/Ubuntu distributions, including prerequisites, GPG key, repository setup, package installation, and starting services. ```bash # Install prerequisite packages sudo apt-get install apt-transport-https ca-certificates dirmngr # Add the ClickHouse GPG key to authenticate packages sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 8919F6BD2B48D754 # Add the ClickHouse repository to apt sources echo "deb https://packages.clickhouse.com/deb stable main" | sudo tee \ /etc/apt/sources.list.d/clickhouse.list # Update apt package lists sudo apt-get update # Install ClickHouse server and client packages sudo apt-get install -y clickhouse-server clickhouse-client # Start the ClickHouse server service sudo service clickhouse-server start # Launch the ClickHouse command line client clickhouse-client # or "clickhouse-client --password" if you set up a password. ``` -------------------------------- ### Clone and Run the Application Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/use-cases/observability/clickstack/example-datasets/_snippets/_instrument_application.md Clone the repository, install dependencies, and start the application. This sets up the basic environment before instrumentation. ```bash git clone https://github.com/ClickHouse/hn-news-analyzer.git cd hn-news-analyzer npm install cp .env.example .env ``` ```bash ./run.sh ``` -------------------------------- ### Creating a DataStore Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/chdb/datastore/quickstart.md Examples of creating a DataStore from dictionaries, pandas DataFrames, CSV files, and Parquet files. ```python from chdb import datastore as pd # From a dictionary ds = pd.DataFrame({ 'name': ['Alice', 'Bob', 'Charlie'], 'age': [25, 30, 35], 'city': ['NYC', 'LA', 'NYC'] }) # From a pandas DataFrame import pandas pdf = pandas.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]}) ds = pd.DataFrame(pdf) # From a CSV file ds = pd.read_csv("data.csv") # From a Parquet file (recommended for large datasets) ds = pd.read_parquet("data.parquet") ``` -------------------------------- ### Installing npm and yarn - Linux (deb) - nvm example Source: https://github.com/clickhouse/clickhouse-docs/blob/main/contribute/contrib-writing-guide.md Example commands to use nvm for managing Node.js versions. ```bash curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash nvm use ``` -------------------------------- ### pg_hba.conf entry for ClickPipes user Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/integrations/data-ingestion/clickpipes/postgres/source/generic.md Example configuration line for pg_hba.conf to allow connections for the ClickPipes user. ```config host all clickpipes_user 0.0.0.0/0 scram-sha-256 ``` -------------------------------- ### Databases Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/chdb/datastore/quickstart.md Examples of connecting to MySQL and PostgreSQL databases, including using a URI. ```python from chdb.datastore import DataStore # MySQL ds = DataStore.from_mysql( host="localhost", database="mydb", table="users", user="root", password="pass" ) # PostgreSQL ds = DataStore.from_postgresql( host="localhost", database="mydb", table="users", user="postgres", password="pass" ) # Using URI ds = DataStore.uri("mysql://user:pass@localhost:3306/mydb/users") ``` -------------------------------- ### Quick Start Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/chdb/debugging/profiling.md Example demonstrating how to enable profiling, run DataStore operations, and view the performance report. ```python from chdb import datastore as pd from chdb.datastore.config import config, get_profiler # Enable profiling config.enable_profiling() # Run your operations ds = pd.read_csv("large_data.csv") result = (ds .filter(ds['amount'] > 100) .groupby('category') .agg({'amount': 'sum'}) .sort('sum', ascending=False) .head(10) .to_df() ) # View report profiler = get_profiler() print(profiler.report()) ``` -------------------------------- ### Correct way to get Tokyo timezone Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/integrations/language-clients/java/date_time_guide.md Example demonstrating the preferred method for obtaining a timezone by ID using `java.time.ZoneId` to avoid silent fallbacks. ```Java TimeZone.getTimeZone(ZoneId.of("Asia/Tokyo")) ``` -------------------------------- ### Example Application Setup and Run Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/integrations/language-clients/go/index.md Steps to create a new Go application, add the ClickHouse client, and run a simple connection test. ```bash mkdir my-clickhouse-app && cd my-clickhouse-app cat > go.mod <<-END module my-clickhouse-app go 1.21 require github.com/ClickHouse/clickhouse-go/v2 main END cat > main.go <<-END package main import ( "fmt" "github.com/ClickHouse/clickhouse-go/v2" ) func main() { conn, _ := clickhouse.Open(&clickhouse.Options{Addr: []string{"127.0.0.1:9000"}}) v, _ := conn.ServerVersion() fmt.Println(v.String()) } END go mod tidy go run main.go ``` -------------------------------- ### MySQL 5.7 Binary Log Settings in Config File Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/integrations/data-ingestion/clickpipes/mysql/source/generic.md Example configuration for MySQL 5.7 binary log settings in the `my.cnf` file. ```ini [mysqld] server_id = 1 log_bin = ON binlog_format = ROW binlog_row_image = FULL expire_logs_days = 1 ``` -------------------------------- ### Build the docs Source: https://github.com/clickhouse/clickhouse-docs/blob/main/contribute/contrib-writing-guide.md Step-by-step commands to clone the documentation repository, prepare the ClickHouse repo docs, install dependencies, and start the Docusaurus development server. ```bash git clone https://github.com/ClickHouse/clickhouse-docs.git cd clickhouse-docs # local docs repo # Below you can choose only ***ONE*** of the two prep commands # yarn copy-clickhouse-repo-docs # This command will clone master ClickHouse/Clickhouse branch to a temp folder and # from there it will copy over the relevant docs folders to this folder yarn copy-clickhouse-repo-docs # OR # yarn prep-from-local # This command will use a locally available folder containing ClickHouse/Clickhouse # and from there it will copy over the relevant docs folders to this folder # running this without using the local full path as an argument will lead to error yarn prep-from-local /full/path/to/your/local/Clickhouse/Clickhouse # Once you have run prep command (ONE of the two) the below command installs the Docusaurus packages and prerequisites in a subdirectory of `clickhouse-docs` named `node_modules` yarn install # This command will start Docusaurus in development mode, which means that as you edit source (for example, .md files) # files the changes will be rendered into HTML files and served by the Docusaurus development server. # Edit your files. Remember that if you are editing files in the ClickHouse/ClickHouse repo then you should edit them in # that repo and then copy the edited file into the ClickHouse/clickhouse-docs/ directory structure so that they are updated # in your develoment environment. yarn start # 'yarn start' probably opened a browser for you when you ran it; if not, open a browser to http://localhost:3000/docs/intro # and navigate to the documentation that you are changing. If you have already made the changes, you can verify them here; if # not, make them, and you will see the page update as you save the changes. ``` -------------------------------- ### Quick Start Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/chdb/debugging/logging.md Example demonstrating how to enable debug logging and perform operations. ```python from pathlib import Path Path("data.csv").write_text("""\ name,age,city,salary,department Alice,25,NYC,55000,Engineering Bob,30,LA,65000,Product Charlie,35,NYC,80000,Engineering Diana,28,SF,70000,Design Eve,42,NYC,95000,Product """) from chdb import datastore as pd from chdb.datastore.config import config # Enable debug logging config.enable_debug() # Now all operations will log details ds = pd.read_csv("data.csv") result = ds.filter(ds['age'] > 25).to_df() ``` -------------------------------- ### Start ClickHouse server Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/getting-started/install/_snippets/_nixos_install.md Command to start the ClickHouse server after installation. ```bash clickhouse-server ``` -------------------------------- ### Grant schema-level, read-only access Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/integrations/data-ingestion/clickpipes/postgres/source/azure-flexible-server-postgres.md Commands to grant usage on a schema and select permissions on all tables within that schema to the ClickPipes user. This example is for the 'public' schema. ```sql GRANT USAGE ON SCHEMA "public" TO clickpipes_user; GRANT SELECT ON ALL TABLES IN SCHEMA "public" TO clickpipes_user; ALTER DEFAULT PRIVILEGES IN SCHEMA "public" GRANT SELECT ON TABLES TO clickpipes_user; ``` -------------------------------- ### Create Sample Database Source: https://github.com/clickhouse/clickhouse-docs/blob/main/knowledgebase/projection_example.mdx Initializes a new database for testing projection usage. ```sql CREATE database db1; ``` -------------------------------- ### Grant schema permissions Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/integrations/data-ingestion/clickpipes/mysql/source/azure-flexible-server-mysql.md Grant schema permissions. The following example shows permissions for the `mysql` database. Repeat these commands for each database and host you want to replicate. ```sql GRANT SELECT ON `mysql`.* TO 'clickpipes_user'@'%'; ``` -------------------------------- ### Selecting Columns Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/chdb/datastore/quickstart.md Examples of selecting columns from a DataStore using both pandas-style and SQL-style methods. ```python # Pandas style subset = ds[['name', 'age']] # SQL style subset = ds.select('name', 'age') ``` -------------------------------- ### Setup for Partitioned Table Example Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/operations_/backup_restore/01_local_disk.md Creates a partitioned table, inserts data into it, and verifies the partition counts before performing backup/restore operations. ```sql CREATE IF NOT EXISTS test_db; -- Create a partitioend table CREATE TABLE test_db.partitioned ( id UInt32, data String, partition_key UInt8 ) ENGINE = MergeTree() PARTITION BY partition_key ORDER BY id; INSERT INTO test_db.partitioned VALUES (1, 'data1', 1), (2, 'data2', 2), (3, 'data3', 3), (4, 'data4', 4); SELECT count() FROM test_db.partitioned; SELECT partition_key, count() FROM test_db.partitioned GROUP BY partition_key ORDER BY partition_key; ``` -------------------------------- ### Query Endpoint v2 GET Response Example Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/cloud/guides/SQL_console/query-endpoints.md Example of a response in application/x-ndjson format from a version 2 query endpoint GET request. ```application/x-ndjson {"database":"INFORMATION_SCHEMA","num_tables":"COLUMNS"} {"database":"INFORMATION_SCHEMA","num_tables":"KEY_COLUMN_USAGE"} {"database":"INFORMATION_SCHEMA","num_tables":"REFERENTIAL_CONSTRAINTS"} ``` -------------------------------- ### Pandas to DataStore Migration Example Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/chdb/datastore/quickstart.md Demonstrates migrating a pandas workflow to DataStore by only changing the import statement, showing identical results with faster execution. ```python from pathlib import Path Path("employees.csv").write_text("""\ name,age,city,salary,department,dept_id,status,email Alice,28,NYC,75000,Engineering,1,active,alice@company.com Bob,35,LA,85000,Engineering,1,active,bob@company.com Charlie,52,NYC,95000,Product,2,active,charlie@company.com Diana,32,SF,70000,Design,3,active,diana@company.com Eve,23,LA,48000,Product,2,inactive,eve@company.com """) # Original pandas code import pandas as pd df = pd.read_csv("employees.csv") result = (df[df['salary'] > 50000] .groupby('department')['salary'] .agg(['mean', 'count']) .sort_values('mean', ascending=False)) print(result) # DataStore version - just change the import! from chdb import datastore as pd df = pd.read_csv("employees.csv") result = (df[df['salary'] > 50000] .groupby('department')['salary'] .agg(['mean', 'count']) .sort_values('mean', ascending=False)) print(result) # Same result, faster execution! ``` -------------------------------- ### Tab Structure for Operating System Specific Content Source: https://github.com/clickhouse/clickhouse-docs/blob/main/contribute/contrib-writing-guide.md Example of using Docusaurus Tabs and TabItem components to provide operating system-specific installation instructions while keeping common introductory and next steps content. ```md --- slug: /integrations/sql-clients/clickhouse-client-local sidebar_label: clickhouse-client title: clickhouse-client and clickhouse-local --- import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # clickhouse-client and clickhouse-local Common information :::tip If you have already installed ClickHouse server locally you may have **clickhouse-client** and **clickhouse local** installed. Check by running **clickhouse client** and **clickhouse local** at the commandline. Otherwise follow the instructions for your operating system. ::: ## Install clickhouse-client and clickhouse-local #### Install the clickhouse-client package: more details for Linux #### Download ClickHouse: We do not provide an installer for macOS. Download the binary build for your architecture (x86_64 or Apple Silicon). more details for macOS In Microsoft Windows 10 or 11 with the Windows Subsystem for Linux (WSL) version 2 (WSL 2) you can run Ubuntu Linux, and then install `clickhouse-client` and `clickhouse-local` by following the Debian install instructions. more details for Windows WSL ## Next Steps Common content ``` -------------------------------- ### Start ClickHouse server Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/getting-started/install/_snippets/_deb_install.md Command to start the ClickHouse server service. ```bash sudo service clickhouse-server start ``` -------------------------------- ### Insert random data Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/operations_/backup_restore/_snippets/_example_setup.md SQL command to insert one thousand rows of randomly generated data into the `test_table` for demonstration purposes. ```sql INSERT INTO test_table (id, name, email, age, salary, created_at, is_active, department, score, country) SELECT generateUUIDv4() as id, concat('User_', toString(rand() % 10000)) as name, concat('user', toString(rand() % 10000), '@example.com') as email, 18 + (rand() % 65) as age, 30000 + (rand() % 100000) as salary, now() - toIntervalSecond(rand() % 31536000) as created_at, rand() % 2 as is_active, arrayElement(['Engineering', 'Marketing', 'Sales', 'HR', 'Finance', 'Operations'], (rand() % 6) + 1) as department, rand() / 4294967295.0 * 100 as score, arrayElement(['USA', 'UK', 'Germany', 'France', 'Canada', 'Australia', 'Japan', 'Brazil'], (rand() % 8) + 1) as country FROM numbers(1000); ``` -------------------------------- ### Cloud Storage Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/chdb/datastore/quickstart.md Examples of connecting to data stored in S3 (anonymously and with credentials) and via HTTP/HTTPS. ```python from chdb.datastore import DataStore # S3 (anonymous) ds = DataStore.uri("s3://bucket/data.parquet?nosign=true") # S3 (with credentials) ds = DataStore.from_s3( "s3://bucket/data.parquet", access_key_id="KEY", secret_access_key="SECRET" ) # HTTP/HTTPS ds = DataStore.uri("https://example.com/data.csv") ``` -------------------------------- ### Quick start Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/integrations/language-clients/csharp.md Example demonstrating how to create a ClickHouse client, execute a query, and print the result. ```csharp using ClickHouse.Driver; // Create a client (typically as a singleton) using var client = new ClickHouseClient("Host=my.clickhouse;Protocol=https;Port=8443;Username=user"); // Execute a query var version = await client.ExecuteScalarAsync("SELECT version()"); Console.WriteLine(version); ``` -------------------------------- ### Delete example models directory Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/integrations/data-ingestion/etl-tools/dbt/guides.md Command to remove the default example models directory. ```bash clickhouse-user@clickhouse:~/imdb$ rm -rf models/example ``` -------------------------------- ### Joining DataStores Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/chdb/datastore/quickstart.md Examples of performing inner and left joins between DataStore objects, including using the pandas-style merge function. ```python from pathlib import Path Path("departments.csv").write_text("""\ dept_id,department_name 1,Engineering 2,Product 3,Design """) from chdb import datastore as pd employees = pd.read_csv("employees.csv") departments = pd.read_csv("departments.csv") # Inner join result = employees.join(departments, on='dept_id', how='inner') # Left join result = employees.join(departments, on='dept_id', how='left') # Using merge (pandas style) result = pd.merge(employees, departments, on='dept_id') ``` -------------------------------- ### Install IPython Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/chdb/guides/clickhouse-local.md Installs the IPython interactive shell, which is used for running commands throughout the guide. ```bash pip install ipython ``` -------------------------------- ### Create Table Example Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/cloud/reference/01_changelog/02_release_notes/25_06.md Example of creating a MergeTree table with primary key and partitioning. ```sql CREATE TABLE t0 ( key Int32, value Int32 ) ENGINE=MergeTree() PRIMARY KEY key PARTITION BY key % 2; ``` -------------------------------- ### Extract and install server package with configuration Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/getting-started/install/_snippets/_linux_tar_install.md Commands to extract and install the clickhouse-server package and start the server. ```bash # Extract and install server package with configuration tar -xzvf "clickhouse-server-$LATEST_VERSION-${ARCH}.tgz" \ || tar -xzvf "clickhouse-server-$LATEST_VERSION.tgz" sudo "clickhouse-server-$LATEST_VERSION/install/doinst.sh" configure sudo /etc/init.d/clickhouse-server start # Start the server ``` -------------------------------- ### Create a table Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/_snippets/_users-and-roles-common.md Create a sample table for examples. ```sql CREATE TABLE db1.table1 ( id UInt64, column1 String, column2 String ) ENGINE MergeTree ORDER BY id; ``` -------------------------------- ### Install libraries Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/use-cases/AI_ML/MCP/ai_agent_libraries/streamlit.md Install the required libraries by running the following commands: ```bash pip install streamlit agno ipywidgets ``` -------------------------------- ### Example `get /keeper/config` output Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/guides/sre/keeper/index.md An example of the output when querying the `/keeper/config` virtual node. ```sql :) get /keeper/config server.1=zoo1:9234;participant;1 server.2=zoo2:9234;participant;1 server.3=zoo3:9234;participant;1 ``` -------------------------------- ### String Length Example Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/chdb/datastore/accessors.md Example of getting string length in bytes using `.str.len()`. ```python ds['name_len'] = ds['name'].str.len() ``` -------------------------------- ### Start PostgreSQL + ClickHouse Stack Source: https://github.com/clickhouse/clickhouse-docs/blob/main/docs/cloud/managed-postgres/local-development.md Clone the repository and start the local development environment with PostgreSQL, ClickHouse, and PeerDB preconfigured. This command initiates all necessary services for local testing. ```bash git clone https://github.com/ClickHouse/postgres-clickhouse-stack.git cd postgres-clickhouse-stack ./run.sh start ```