Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit 4b2ffc1

Browse filesBrowse files
authored
Merge pull request #116 from postgres-ai/dmius-local-pgdata
Use local pgdata
2 parents 43fc165 + 5ad788f commit 4b2ffc1
Copy full SHA for 4b2ffc1

File tree

Expand file treeCollapse file tree

2 files changed

+57
-9
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+57
-9
lines changed

‎nancy_run.sh

Copy file name to clipboardExpand all lines: nancy_run.sh
+57-9Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ function dbg_cli_parameters() {
377377
echo "AWS_EBS_VOLUME_SIZE: $AWS_EBS_VOLUME_SIZE"
378378
echo "AWS_REGION: ${AWS_REGION}"
379379
echo "AWS_ZONE: ${AWS_ZONE}"
380+
echo "DB_LOCAL_PGDATA: ${DB_LOCAL_PGDATA}"
380381
fi
381382
}
382383

@@ -461,6 +462,10 @@ function check_cli_parameters() {
461462
err "ERROR: Container ID may be specified only for local runs ('--run-on localhost')."
462463
exit 1
463464
fi
465+
if [[ ! -z ${DB_LOCAL_PGDATA+x} ]]; then
466+
err "ERROR: --db-local-pgdata may be specified only for local runs ('--run-on localhost')."
467+
exit 1
468+
fi
464469
if [[ -z ${AWS_KEYPAIR_NAME+x} ]] || [[ -z ${AWS_SSH_KEY_PATH+x} ]]; then
465470
err "ERROR: AWS keypair name and ssh key file must be specified to run on AWS EC2."
466471
exit 1
@@ -505,6 +510,10 @@ function check_cli_parameters() {
505510
fi
506511
fi
507512
elif [[ "$RUN_ON" == "localhost" ]]; then
513+
if [[ ! -z ${CONTAINER_ID+x} ]] && [[ ! -z ${DB_LOCAL_PGDATA+x} ]]; then
514+
err "ERROR: Both --container-id and --db-local-pgdata are provided. Cannot use --db-local-pgdata with existing container."
515+
exit 1
516+
fi
508517
if [[ ! -z ${AWS_KEYPAIR_NAME+x} ]] || [[ ! -z ${AWS_SSH_KEY_PATH+x} ]] ; then
509518
err "ERROR: options '--aws-keypair-name' and '--aws-ssh-key-path' must be used with '--run-on aws'."
510519
exit 1
@@ -560,7 +569,8 @@ function check_cli_parameters() {
560569
[[ ! -z ${WORKLOAD_PGBENCH+x} ]] && let workloads_count=$workloads_count+1
561570

562571
if [[ -z ${DB_PREPARED_SNAPSHOT+x} ]] && [[ -z ${DB_DUMP+x} ]] \
563-
&& [[ -z ${DB_PGBENCH+x} ]] && [[ -z ${DB_EBS_VOLUME_ID+x} ]]; then
572+
&& [[ -z ${DB_PGBENCH+x} ]] && [[ -z ${DB_EBS_VOLUME_ID+x} ]] \
573+
&& [[ -z ${DB_LOCAL_PGDATA+x} ]]; then
564574
err "ERROR: The object (database) is not defined."
565575
exit 1
566576
fi
@@ -606,8 +616,8 @@ function check_cli_parameters() {
606616
check_path PG_CONFIG
607617
if [[ "$?" -ne "0" ]]; then # TODO(NikolayS) support file:// and s3://
608618
#err "WARNING: Value given as pg_config: '$PG_CONFIG' not found as file will use as content"
609-
echo "$PG_CONFIG" > $TMP_PATH/pg_config_tmp.sql
610-
PG_CONFIG="$TMP_PATH/pg_config_tmp.sql"
619+
echo "$PG_CONFIG" > $TMP_PATH/pg_config_tmp.conf
620+
PG_CONFIG="$TMP_PATH/pg_config_tmp.conf"
611621
fi
612622
fi
613623

@@ -1123,6 +1133,8 @@ while [ $# -gt 0 ]; do
11231133
AWS_BLOCK_DURATION=$2; shift 2 ;;
11241134
--db-ebs-volume-id )
11251135
DB_EBS_VOLUME_ID=$2; shift 2;;
1136+
--db-local-pgdata )
1137+
DB_LOCAL_PGDATA=$2; shift 2;;
11261138

11271139
--s3cfg-path )
11281140
S3_CFG_PATH="$2"; shift 2 ;;
@@ -1162,10 +1174,18 @@ trap cleanup_and_exit EXIT
11621174

11631175
if [[ "$RUN_ON" == "localhost" ]]; then
11641176
if [[ -z ${CONTAINER_ID+x} ]]; then
1165-
CONTAINER_HASH=$(docker run --name="pg_nancy_${CURRENT_TS}" \
1166-
-v $TMP_PATH:/machine_home \
1167-
-dit "postgresmen/postgres-with-stuff:postgres${PG_VERSION}_pgbadger10" \
1168-
)
1177+
if [[ -z ${DB_LOCAL_PGDATA+x} ]]; then
1178+
CONTAINER_HASH=$(docker run --name="pg_nancy_${CURRENT_TS}" \
1179+
-v $TMP_PATH:/machine_home \
1180+
-dit "postgresmen/postgres-with-stuff:pg${PG_VERSION}" \
1181+
)
1182+
else
1183+
CONTAINER_HASH=$(docker run --name="pg_nancy_${CURRENT_TS}" \
1184+
-v $TMP_PATH:/machine_home \
1185+
-v $DB_LOCAL_PGDATA:/pgdata \
1186+
-dit "postgresmen/postgres-with-stuff:pg${PG_VERSION}" \
1187+
)
1188+
fi
11691189
else
11701190
CONTAINER_HASH="$CONTAINER_ID"
11711191
fi
@@ -1279,6 +1299,30 @@ function cp_db_ebs_backup() {
12791299
docker_exec bash -c "localedef -f UTF-8 -i ru_RU ru_RU.UTF-8"
12801300
}
12811301

1302+
#######################################
1303+
# Copy pgdata to postgres localtion
1304+
# Globals:
1305+
# PG_VERSION
1306+
# Arguments:
1307+
# None
1308+
# Returns:
1309+
# None
1310+
#######################################
1311+
1312+
function attach_pgdata() {
1313+
local op_start_time=$(date +%s)
1314+
docker_exec bash -c "sudo /etc/init.d/postgresql stop"
1315+
docker_exec bash -c "sudo rm -rf /var/lib/postgresql/$PG_VERSION/main"
1316+
docker_exec bash -c "ln -s /pgdata/ /var/lib/postgresql/$PG_VERSION/main"
1317+
docker_exec bash -c "chown -R postgres:postgres /var/lib/postgresql/$PG_VERSION/main"
1318+
docker_exec bash -c "chmod -R 0700 /var/lib/postgresql/9.6/main/"
1319+
local end_time=$(date +%s);
1320+
local duration=$(echo $((end_time-op_start_time)) | awk '{printf "%d:%02d:%02d", $1/3600, ($1/60)%60, $1%60}')
1321+
msg "Time taken to attach PGDATA: $duration."
1322+
docker_exec bash -c "sudo /etc/init.d/postgresql start"
1323+
sleep 30 # wait for postgres started, may be will recover database
1324+
}
1325+
12821326
#######################################
12831327
# Detach EBS volume
12841328
# Globals:
@@ -1313,6 +1357,10 @@ if [[ "$RUN_ON" == "aws" ]]; then
13131357

13141358
docker_exec bash -c "sudo /etc/init.d/postgresql start"
13151359
sleep 2 # wait for postgres started
1360+
else
1361+
if [[ ! -z ${DB_LOCAL_PGDATA+x} ]]; then
1362+
attach_pgdata
1363+
fi
13161364
fi
13171365

13181366
#######################################
@@ -1736,11 +1784,11 @@ fi
17361784

17371785
## Apply machine features
17381786
# Dump
1739-
sleep 2 # wait for postgres up&running
1787+
sleep 10 # wait for postgres up&running
17401788

17411789
apply_commands_after_container_init
17421790
apply_sql_before_db_restore
1743-
if [[ -z ${DB_EBS_VOLUME_ID+x} ]]; then
1791+
if [[ ! -z ${DB_DUMP+x} ]] || [[ ! -z ${DB_PGBENCH+x} ]]; then
17441792
restore_dump
17451793
fi
17461794
apply_sql_after_db_restore

‎tests/nancy_run_localhost_pgbench.sh

Copy file name to clipboard
100644100755
Expand all lines: tests/nancy_run_localhost_pgbench.sh
File mode changed.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.