Skip to main content
This page documents every configurable option in clickhouse-go v2.x. For a guide with code examples, see Configuration.
Version annotationsOptions added in clickhouse-go v2.35.0 or later are marked with (Since vX.Y.Z) next to their description. Options without a “Since” tag have been available since v2.0 and are present in every supported release.

How options are set

Options exist at three scopes: Where scopes overlap, the more specific scope wins: Batch > Query > Connection. For Settings, query-level keys are merged with connection-level keys and query-level wins on conflict. Via Options struct:
Via DSN string:
Via Connector (database/sql with Options struct):
Via context (per-query):

Connection options

Protocol and connection


Authentication


Timeouts

A ClickHouse Cloud service that has been idle is paused, and wakes on the first incoming connection. Wake-up typically takes a few tens of seconds, during which the dial blocks. If DialTimeout is lower than the wake time, the first query after an idle period fails with a dial timeout instead of running.Set DialTimeout to 1m2m for clients that may be the first to reach an idled service. The tradeoff is slower failure detection during a real outage — dials block for the full timeout before erroring — so prefer scoping the higher timeout to the first connect, or use context deadlines on individual queries to cap end-to-end latency.

Connection pool

database/sql onlyConnMaxIdleTime is a standard Go database/sql pool setting. It isn’t available in the clickhouse.Options struct or via clickhouse.Open(). Set it after OpenDB():
See Connection Pooling for usage details.

Standard database/sql pool settings

When using clickhouse.OpenDB() or sql.Open("clickhouse", dsn), the returned *sql.DB supports Go’s standard pool methods. OpenDB() auto-applies the first three from Options:
ClickHouse API (clickhouse.Open)These methods are not available on the connection returned by clickhouse.Open(). The ClickHouse API manages its own pool internally using the Options struct fields directly.

Compression

Compression method support by protocol:

TLS

See TLS for code examples.

Logging

See Logging for full examples.

Buffers and memory


HTTP-specific

Silently ignored on NativeThese options only affect Protocol: clickhouse.HTTP. They’re silently ignored when using the Native protocol, and no error or warning is emitted.
Two-layer HTTP poolingWhen using HTTP, there are two connection pools:
  • Layer 1 (application): MaxIdleConns / MaxOpenConns — controls httpConnect objects
  • Layer 2 (transport): HttpMaxConnsPerHost — controls underlying TCP connections
The Native protocol has a simple 1:1 mapping and ignores HttpMaxConnsPerHost.

Advanced connection


Client information


ClickHouse server settings

Common settings:

Context-level query options

Set per-query using clickhouse.Context():
Context deadline behaviorIf the context has a deadline > 1s, max_execution_time is automatically set to seconds_remaining + 5. This overrides any manually set value.

Batch options

Passed to PrepareBatch(). Import: github.com/ClickHouse/clickhouse-go/v2/lib/driver.

Quick reference tables

Connection pool sizing recommendations

Timeout recommendations

DSN parameter quick reference


Troubleshooting

Connection pool exhausted: “acquire conn timeout”

Cause: Connection pool exhausted - all MaxOpenConns connections are in use and none became available within DialTimeout. Fix Try the following steps in order, and diagnose the root cause before tuning knobs:
  1. Check for long-running queries holding connections: SELECT query_id, elapsed FROM system.processes ORDER BY elapsed DESC. If found, address the slow queries first.
  2. If you run long-lived batches (minutes/hours between PrepareBatch() and Send()), use WithReleaseConnection() to return the connection to the pool while the batch is open.
  3. Increase MaxOpenConns to match observed concurrency.
  4. Increase DialTimeout only if bursts are expected and acquisition wait is the actual bottleneck.

Read timeout and connection reset errors

Cause: ReadTimeout exceeded while waiting for a server response, or the connection was closed by the server/network. Fix:
  • Increase ReadTimeout for long-running queries
  • Use context deadlines for per-query timeout control
  • Check ClickHouse server-side max_execution_time limits

“Code: 516. Authentication failed”

Cause: Wrong username, password, or the user doesn’t exist. Fix:
  • Verify credentials against system.users table
  • Check for URL-encoding issues with special characters in DSN passwords
  • Confirm the user has access to the specified database

TLS certificate errors

Gradual memory growth

Cause: Large idle connection buffers accumulating. Fix:
  • Set FreeBufOnConnRelease: true in memory-constrained environments
  • Reduce MaxIdleConns to limit idle connections
  • Reduce MaxCompressionBuffer if using compression
  • Lower ConnMaxLifetime to cycle connections more frequently
Last modified on July 2, 2026