Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
postgresqlite/postgresqlite
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
33 lines (27 sloc)
1.36 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -Eeuo pipefail # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/#:~:text=set%20%2Du,is%20often%20highly%20desirable%20behavior. | |
DATADIR=$(realpath "$1") | |
CONTAINER_NAME="postgres-${DATADIR//[^a-zA-Z0-9_.-]/_}" | |
IMAGE='postgres:latest' | |
COMMAND='' | |
if [ -n "${2-}" ]; then | |
COMMAND="-c \"$2\"" | |
fi | |
if [ -t 0 ]; then | |
# used interactively | |
INTERACTIVE="-it" | |
else | |
# got stdin | |
INTERACTIVE="-i" | |
fi | |
POSTGRES_OPTS="-c 'max_connections=200' -c 'shared_buffers=4GB' -c 'effective_cache_size=12GB' -c 'maintenance_work_mem=1GB' -c 'checkpoint_completion_target=0.7' -c 'wal_buffers=16MB' -c 'default_statistics_target=100' -c 'random_page_cost=1.1' -c 'effective_io_concurrency=200' -c 'work_mem=1GB' -c 'min_wal_size=1GB' -c 'max_wal_size=2GB' -c 'max_worker_processes=8' -c 'max_parallel_workers_per_gather=8' -c 'max_parallel_workers=8'" | |
mkdir -p "$DATADIR" | |
docker run --rm \ | |
"$INTERACTIVE" \ | |
--name "$CONTAINER_NAME" \ | |
-v "$DATADIR":/var/lib/postgresql/data \ | |
-e POSTGRES_PASSWORD=mysecretpassword \ | |
--user $UID \ | |
--shm-size=8g \ | |
"$IMAGE" \ | |
bash -c "(./docker-entrypoint.sh postgres $POSTGRES_OPTS &) &>/dev/null; until pg_isready -U postgres &>/dev/null; do sleep 0.1; done; psql -U postgres -d postgres --echo-all -v ON_ERROR_STOP=1 $COMMAND; EXIT_CODE=\$?; pg_ctl stop &>/dev/null; exit \$EXIT_CODE" | |