# ClickHouse

### Overview

HockeyStack's ClickHouse integration enables you to seamlessly connect your ClickHouse instance to our platform. This custom-built connector is designed to import data from ClickHouse based on your specific infrastructure and analytics requirements. Typical use cases include:

* Enriching your analytics with specific user profile or behavioral data
* Mapping offline revenue opportunities to your CRM activities
* Incorporating additional custom data points to unify your customer data story
* Ingesting large volumes of historical data to enhance your analytics

If you're uncertain about which data is most valuable to import, we're happy to schedule a call to help you determine which tables and fields will best support your use cases.

### Prerequisites

Before we begin, please ensure you have:

* Access to your ClickHouse instance with the ability to manage users, permissions, and network policies
* Clear information on which ClickHouse tables, databases, and columns contain the data you'd like HockeyStack to ingest
* An understanding of whether HockeyStack should have read-only access, or if write permissions are also needed

### Connecting to ClickHouse

To establish a secure connection between HockeyStack and ClickHouse, follow these steps:

**1. IP Whitelisting (if applicable)**

If you have IP restrictions in place, whitelist the following IP addresses to allow HockeyStack's workers to communicate with ClickHouse:&#x20;

* \`18.184.228.143\`&#x20;
* \`18.192.106.69\`&#x20;
* \`35.157.54.242\`
* \`3.69.98.171\`

**2. Assigning Permissions**

Decide whether HockeyStack should have read-only or read-write permissions, depending on your use case. Create a user with access to the necessary databases and tables.

For read-only access:

`CREATE USER hockeystack_user IDENTIFIED BY 'your_secure_password';`

`GRANT SELECT ON your_database.* TO hockeystack_user;`

For read-write access:

`CREATE USER hockeystack_user IDENTIFIED BY 'your_secure_password';`

`GRANT SELECT, INSERT, ALTER, CREATE ON your_database.* TO hockeystack_user;`

Additional Resources: [ClickHouse Access Rights Documentation](https://clickhouse.com/docs/en/operations/access-rights), [Managing Users and Roles](https://clickhouse.com/docs/en/sql-reference/statements/create/user)

**3. Connection Details**

Once you've configured the user and permissions, provide us with the following details using a secure method of your choice. Popular choices are:&#x20;

* One Time Secret: <https://onetimesecret.com> or&#x20;
* 1Password: <https://1password.com>

<table><thead><tr><th width="126.90625">Field</th><th>Description</th><th>Examp</th></tr></thead><tbody><tr><td>Host</td><td>Your ClickHouse server hostname or IP</td><td><code>clickhouse.yourcompany.com</code></td></tr><tr><td>Port</td><td>Connection port<br>(default: `8123` for HTTP, `8443` for HTTPS)<br><br><em>Note: Port <code>8443</code> will automatically enable HTTPS connections for secure data transfer.</em></td><td><code>8123</code></td></tr><tr><td>Database</td><td>The database containing your data</td><td><code>analytics</code></td></tr><tr><td>Username</td><td>The user created for HockeyStack</td><td><code>hockeystack_user</code></td></tr><tr><td>Password</td><td>The password for the HockeyStack user</td><td>(securely shared)</td></tr><tr><td>Table</td><td>The specific table to import data from</td><td><code>events</code></td></tr></tbody></table>

**4. Integration Details**

We connect using Node.js workers with the official ClickHouse client to ensure a stable and efficient integration. For more technical details on how the connector works, refer to ClickHouse's official documentation: <https://clickhouse.com/docs/en/integrations/language-clients/javascript>)

### Pulling Data from ClickHouse

HockeyStack runs scheduled workers (typically daily, though this can be customized) to pull data from your ClickHouse instance. The process is as follows:

**Initial Historical Backfill**

We start by running a full backfill of your historical data. This ensures that HockeyStack has all necessary historical records before moving on to incremental updates. Depending on the size of your dataset, this process may take some time.

**Incremental Data Syncs**

After the initial backfill, we perform incremental data syncs at the scheduled frequency. These syncs pull in new or updated records since the last sync, ensuring your HockeyStack analytics remain up-to-date.To enable incremental syncs, your table should have a timestamp column (such as \`updated\_at\` or \`created\_at\`) that we can use to identify new or modified records.

### Troubleshooting

If you encounter connection issues, please verify:

1\. The ClickHouse server is accessible from HockeyStack's IP addresses

2\. The user has the correct permissions on the specified database and table

3\. The connection details (host, port, credentials) are accurate

4\. Any firewall rules allow incoming connections on the specified port

### Support

If you have any questions or need assistance during the integration process, please reach out to our support team at <support@hockeystack.com>.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hockeystack.com/integrations/analytics-and-data-warehouse/clickhouse.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
