Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/ubuntu/clickhouse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ done

if [ "${CH_VERSION%%.*}" -lt 25 ]; then
# Enable the JSON type in release prior to 2025.
printf "~~~~ Starting ClickHouse %s ~~~~\n" "$CH_VERSION"
setting=allow_experimental_object_type
if [ "${CH_VERSION:0:4}" == "24.8" ]; then
# The setting was renamed.
Expand Down
32 changes: 29 additions & 3 deletions dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ development of pg_clickhouse.

* `bear.json`: [Bear Configuration](#bear-configuration)
* `bear.yml`: [Bear Configuration](#bear-configuration)
* `choci`: [Run ClickHouse Server](#run-local-clickhouse-server)
* `configs`: Configuration files for `choci` and `runch`
* `docker-compose.yml`: [ClickHouse Version Testing Containers](#clickhouse-version-testing-containers)
* `Makefile`: Automates [ClickHouse Version Testing Containers](#clickhouse-version-testing-containers)
* `README.md`: This file
* `runch`: [Run ClickHouse Server](#run-clickhouse-server)
* [`tpch`]: [TPC-H Benchmark Scripts](./tpch/README.md)

## Run ClickHouse Server
## Run Local ClickHouse Server

Use `runch` to run a specific version of the ClickHouse server. For a complete
list of commands, run:
Use `runch` to locally run a specific version of the ClickHouse server. For a
complete list of commands, run:

```sh
runch help
Expand All @@ -34,6 +36,28 @@ make installcheck
Specify any version supported by [clickhousectl]. Currently defaults to
`26.6`.

## Run Docker ClickHouse Server

Use `choci` to run a specific version of ClickHouse in an OCI (Docker)
container. For a complete list of commands, run:

```sh
choci help
```

`choci` relies on [docker] to start or stop a ClickHouse server with the
default ports mapped to localhost. Useful for testing against a specific
version of ClickHouse. For example, to test pg_clickhouse against ClickHouse
23.8:

```sh
./dev/choci start 23.8
make installcheck
./dev/choci stop
```

Specify any tag supported by the [Docker image]. Defaults to `latest`.

## ClickHouse Version Testing Containers

This directory's [docker-compose.yml](docker-compose.yml) starts images for
Expand Down Expand Up @@ -87,5 +111,7 @@ There are currently two files:
The `compile_commands.json` target determines which to use.

[clickhousectl]: https://clickhouse.com/docs/interfaces/cli "ClickHouse Docs: clickhousectl"
[Docker image]: https://hub.docker.com/r/clickhouse/clickhouse-server
"clickhouse/clickhouse-server on DockerHub"
[pgxn-tools]: https://github.com/pgxn/docker-pgxn-tools/
[Bear]: https://github.com/rizsotto/Bear "Bear generates a compilation database for Clang tooling"
95 changes: 95 additions & 0 deletions dev/choci
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash

# Start and stop various versions of ClickHouse containers. Requires that an
# OCI runner like Docker or Orb be running and the `docker` CLI.

set -e

usage() {
cat <<EOF
Usage: choci <command> [<args>]

The choci commands are:
start [<version>] Start ClickHouse version; defaults to latest
stop Stop the current ClickHouse server
status Show status of server
download <version> Download a version
remove <version> Remove a version
versions Show currently-downloaded versions
help Show this usage statement and command summary
EOF
}

# https://stackoverflow.com/a/246128
dir="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
image="clickhouse/clickhouse-server"
name="$(basename "${BASH_SOURCE[0]}")"

cfg_file() {
# Determine which file from ./configs to use.
local version="$1"
# Default config.
fn=default
if [ "$version" != "latest" ] && [ "${version%%.*}" -lt 25 ]; then
fn=allow_object
# Enable the JSON type in release prior to 2025.
if [ "${version:0:4}" == "24.8" ]; then
# The setting was renamed.
fn=allow_json
fi
fi

echo "$fn"
}
stop() {
cid="$(docker ps -aq --filter "name=$name")"
if [ -n "$cid" ]; then
printf 'Stopping ClickHouse instance %s...\n' "$cid"
docker rm -f "$cid"
fi
}

case "$1" in
stop)
stop
;;
start)
version="${2:-latest}"
stop
cfg_base="$(cfg_file "$version")"
printf 'Starting ClickHouse %s\n' "$version"
docker run -p 8123:8123 -p9000:9000 \
-e CLICKHOUSE_SKIP_USER_SETUP=1 \
--name "$name" \
--ulimit nofile=262144:262144 \
-v "$dir/configs/$cfg_base.yaml:/etc/clickhouse-server/users.d/$cfg_base.yaml" \
-d "$image:$version"
;;
download)
version="${2:-latest}"
docker pull "$image:$version"
;;
status)
docker ps -f "name=$name" --format "table {{.Names}}\t{{.Image}}\t{{.State}}"
;;
remove)
version="$2"
if [ -z "$version" ]; then
printf 'No version specified\n'
usage
exit 1;
fi
docker image rm -f "$image:$version"
;;
versions)
docker image ls --filter "reference=$image:*" --format '{{.Tag}}'
;;
help)
usage
;;
*)
test -n "$1" && printf 'Unknown command: %s\n\n' "$1"
usage
exit 1;
;;
esac
4 changes: 4 additions & 0 deletions dev/configs/allow_json.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
timezone: UTC
profiles:
default:
allow_experimental_json_type: 1
4 changes: 4 additions & 0 deletions dev/configs/allow_object.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
timezone: UTC
profiles:
default:
allow_experimental_object_type: 1
1 change: 1 addition & 0 deletions dev/configs/default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
timezone: UTC
44 changes: 37 additions & 7 deletions dev/runch
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Start and stop various versions of ClickHouse. Requires:
#
# * `clickhousectl` (a.k.a., `chctl`) v0.3.0 or later
# * `mkdir -p ~/.clickhouse/configs && echo 'timezone: UTC' > ~/.clickhouse/configs/default.yaml`

set -e

Expand All @@ -15,12 +14,34 @@ The runch commands are:
start [<version>] Start ClickHouse version; defaults to 26.6
stop Stop the current ClickHouse server
status Show status of all running severs
remove <version> Remove a version
versions Show currently-installed versions
help Show this usage statement and command summary

EOF
}

name="$(basename "$0")"
# https://stackoverflow.com/a/246128
dir="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
name="$(basename "${BASH_SOURCE[0]}")"

cfg_file() {
# Determine which file from ./configs to use.
local version="$1"
# Default config.
fn=default
if [ "${version%%.*}" -lt 25 ]; then
fn=allow_object
# Enable the JSON type in release prior to 2025.
if [ "${version:0:4}" == "24.8" ]; then
# The setting was renamed.
fn=allow_json
fi
fi

mkdir -p "$HOME/.clickhouse/configs"
cp "$dir/configs/$fn.yaml" "$HOME/.clickhouse/configs/runch-$fn.yaml"
echo "runch-$fn"
}

case "$1" in
stop)
Expand All @@ -29,15 +50,24 @@ case "$1" in
start)
version="${2:-26.6}"

# cfg_file="$(dirname "$0")/clickhouse.yaml"
cfg_file=default

chctl local server stop-all # stop "$name"
chctl local server start --name "$name" --version "$version" --config-file "$cfg_file"
chctl local server start --name "$name-$version" --version "$version" --config-file "$(cfg_file "$version")"
;;
status)
chctl local server list
;;
versions)
chctl local list
;;
remove)
version="$2"
if [ -z "$version" ]; then
printf 'No version specified\n'
usage
exit 1;
fi
chctl local remove "$version"
;;
help)
usage
;;
Expand Down
Loading