Git Product home page Git Product logo

clickhouse-demo's Introduction

ClickHouse

1.Create clickhouse User

  • Connect to clickhouse-client
clickhouse-client --user default --password

-- Create user

CREATE USER clickhouse_admin IDENTIFIED BY '1234566';

-- Grant privileges

GRANT ALL PRIVILEGES ON *.* TO clickhouse_admin;
  • Account: clickhouse_admin / 1234566

2. Sync data from Postgres to ClickHouse

  • Option 1: Using engine PostgreSQL
    • Create new table
        CREATE TABLE customers (
        "customer_id" String,
        "company_name" String,
        "contact_name" String,
        "contact_title" String,
        "address" String,
        "city" String,
        "region" String,
        "postal_code" String,
        "country" String,
        "phone" String,
        "fax" String
        ) ENGINE = PostgreSQL('192.168.0.9:5432', 'clickhouse_pq_db', 'customers', 'postgres', 'postgres')
    
    
    • db_host: 192.168.0.9
    • db_name: clickhouse_pq_db
    • table_name: customers
    • db_user: postgres
    • db_password: postgres
  • Option 2: Using engine MaterializedPostgreSQL
    • Add config to postgresql.conf
    • docker mount volume: ./data/db/postgresql.conf
          listen_addresses = '*' 
          max_replication_slots = 10
          wal_level = logical
    • Enable experimental features in ClickHouse
      SET allow_experimental_database_materialized_postgresql=1
      
    • Create replica database in ClickHouse
       CREATE DATABASE postgres_db ENGINE = MaterializedPostgreSQL('192.168.0.9:5432', 'clickhouse_pq_db', 'postgres', 'postgres')
      
      • db_host: 192.168.0.9
      • db_name: clickhouse_pq_db
      • db_user: postgres
      • db_password: postgres
      • db_port: 5432

Command in ClickHouse

  • Show databases
SHOW DATABASES
  • Show tables
SHOW TABLES
  • Add tables to MaterializedPostgreSQL database
ATTACH TABLE db_postgres.customers;
- database_name: db_postgres
- table_name: customers
  • Detach tables from MaterializedPostgreSQL database
DETACH TABLE db_postgres.customers;
- database_name: db_postgres
- table_name: customers

clickhouse-demo's People

Contributors

chithien0909 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.