Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
358 additions
and
77 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package pg | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/wal-g/tracelog" | ||
"github.com/wal-g/wal-g/internal" | ||
) | ||
|
||
const ( | ||
CatchupFetchShortDescription = "Fetches an incremental backup from storage" | ||
) | ||
|
||
// catchupFetchCmd represents the catchup-fetch command | ||
var catchupFetchCmd = &cobra.Command{ | ||
Use: "catchup-fetch PGDATA backup_name", | ||
Short: CatchupFetchShortDescription, // TODO : improve description | ||
Args: cobra.ExactArgs(2), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
folder, err := internal.ConfigureFolder() | ||
tracelog.ErrorLogger.FatalOnError(err) | ||
internal.HandleCatchupFetch(folder, args[0], args[1]) | ||
}, | ||
} | ||
|
||
func init() { | ||
Cmd.AddCommand(catchupFetchCmd) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package pg | ||
|
||
import ( | ||
"github.com/wal-g/tracelog" | ||
"github.com/wal-g/wal-g/internal" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
catchupPushShortDescription = "Creates incremental backup from lsn" | ||
) | ||
|
||
var ( | ||
// catchupPushCmd represents the catchup-push command | ||
catchupPushCmd = &cobra.Command{ | ||
Use: "catchup-push PGDATA --from-lsn LSN", | ||
Short: catchupPushShortDescription, | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
uploader, err := internal.ConfigureUploader() | ||
tracelog.ErrorLogger.FatalOnError(err) | ||
internal.HandleCatchupPush(uploader, args[0], fromLSN) | ||
}, | ||
} | ||
fromLSN uint64 | ||
) | ||
|
||
func init() { | ||
Cmd.AddCommand(catchupPushCmd) | ||
|
||
catchupPushCmd.Flags().Uint64Var(&fromLSN, "from-lsn", 0, "LSN to start incremental backup") | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM wal-g/docker_prefix:latest | ||
|
||
CMD su postgres -c "/tmp/tests/catchup_perftest.sh" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"WALE_S3_PREFIX": "s3://deletebeforepermanentfullbucket", | ||
"WALG_USE_WAL_DELTA": "true", | ||
"WALG_UPLOAD_CONCURRENCY": "1", | ||
"WALG_UPLOAD_QUEUE": "1", | ||
"WALG_UPLOAD_DISK_CONCURRENCY": "1" |
14 changes: 14 additions & 0 deletions
14
docker/pg_tests/scripts/scripts/wait_while_replication_complete.sh
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
DATABASE=$1 | ||
TABLE=$2 | ||
PORT=$3 | ||
|
||
ROW_COUNT=`psql --port ${PORT} -d ${DATABASE} -c "SELECT COUNT(*) from ${TABLE}" | grep -E '[0-9]+' | head -1` | ||
|
||
while [[ "${ROW_COUNT}" != " 10000000" ]] | ||
do | ||
echo "Wait a sec to replication end" | ||
sleep 1 | ||
ROW_COUNT=`psql --port ${PORT} -c "SELECT COUNT(*) from ${TABLE}" | grep -E '[0-9]+' | head -1` | ||
done |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/bin/sh | ||
set -e -x | ||
|
||
PGDATA="/var/lib/postgresql/10/main" | ||
PGDATA_ALPHA="${PGDATA}_alpha" | ||
PGDATA_BETA="${PGDATA}_beta" | ||
ALPHA_DUMP="/tmp/alpha_dump" | ||
ALPHA_PORT=5432 | ||
BETA_DUMP="/tmp/beta_dump" | ||
BETA_PORT=5433 | ||
|
||
# init config | ||
CONFIG_FILE="/tmp/configs/catchup_perftest_config.json" | ||
COMMON_CONFIG="/tmp/configs/common_config.json" | ||
TMP_CONFIG="/tmp/configs/tmp_config.json" | ||
cp ${CONFIG_FILE} ${TMP_CONFIG} | ||
echo "," >> ${TMP_CONFIG} | ||
cat ${COMMON_CONFIG} >> ${TMP_CONFIG} | ||
/tmp/scripts/wrap_config_file.sh ${TMP_CONFIG} | ||
|
||
# init alpha cluster | ||
/usr/lib/postgresql/10/bin/initdb ${PGDATA_ALPHA} | ||
/usr/lib/postgresql/10/bin/pg_ctl -D ${PGDATA_ALPHA} -w start | ||
PGDATA=${PGDATA_ALPHA} /tmp/scripts/wait_while_pg_not_ready.sh | ||
|
||
# preparation for replication | ||
pushd ${PGDATA_ALPHA} | ||
psql -c "CREATE ROLE repl WITH REPLICATION PASSWORD 'password' LOGIN;" | ||
echo "host replication repl 127.0.0.1/32 md5" >> pg_hba.conf | ||
echo "wal_level = replica" >> postgresql.conf | ||
echo "wal_keep_segments = 100" >> postgresql.conf | ||
echo "max_wal_senders = 4" >> postgresql.conf | ||
/usr/lib/postgresql/10/bin/pg_ctl -D ${PGDATA_ALPHA} -w restart | ||
PGDATA=${PGDATA_ALPHA} /tmp/scripts/wait_while_pg_not_ready.sh | ||
popd | ||
|
||
# init beta cluster (replica of alpha) | ||
/usr/lib/postgresql/10/bin/pg_basebackup --wal-method=stream -D ${PGDATA_BETA} -U repl -h 127.0.0.1 -p ${ALPHA_PORT} | ||
pushd ${PGDATA_BETA} | ||
echo "port = ${BETA_PORT}" >> postgresql.conf | ||
echo "hot_standby = on" >> postgresql.conf | ||
cat > recovery.conf << EOF | ||
standby_mode = 'on' | ||
primary_conninfo = 'host=127.0.0.1 port=${ALPHA_PORT} user=repl password=password' | ||
restore_command = 'cp ${PGDATA_BETA}/archive/%f %p' | ||
trigger_file = '/tmp/postgresql.trigger.${BETA_PORT}' | ||
EOF | ||
/usr/lib/postgresql/10/bin/pg_ctl -D ${PGDATA_BETA} -w start | ||
popd | ||
|
||
# fill database postgres | ||
pgbench -i -s 100 -h 127.0.0.1 -p ${ALPHA_PORT} postgres | ||
|
||
LSN=`psql -c "SELECT pg_current_wal_lsn() - '0/0'::pg_lsn;" | grep -E '[0-9]+' | head -1` | ||
|
||
/tmp/scripts/wait_while_replication_complete.sh postgres pgbench_accounts ${BETA_PORT} | ||
# script above waits only one table, so just in case sleep | ||
sleep 5 | ||
|
||
/usr/lib/postgresql/10/bin/pg_ctl -D ${PGDATA_BETA} --mode smart -w stop | ||
sleep 5 | ||
|
||
# change database postgres and dump database | ||
pgbench -i -s 200 -h 127.0.0.1 -p ${ALPHA_PORT} postgres | ||
/usr/lib/postgresql/10/bin/pg_dump -h 127.0.0.1 -p ${ALPHA_PORT} -f ${ALPHA_DUMP} postgres | ||
|
||
wal-g --config=${TMP_CONFIG} catchup-push ${PGDATA_ALPHA} --from-lsn ${LSN} 2>/tmp/stderr 1>/tmp/stdout | ||
cat /tmp/stderr /tmp/stdout | ||
|
||
BACKUP_NAME=`grep -oE 'base_.*' /tmp/stderr` | ||
|
||
/usr/lib/postgresql/10/bin/pg_ctl -D ${PGDATA_ALPHA} -w stop | ||
sleep 5 | ||
|
||
wal-g --config=${TMP_CONFIG} catchup-fetch ${PGDATA_BETA} $BACKUP_NAME | ||
|
||
# rename recovery.conf to don't care about wals and remove backup_label | ||
# lately it can be started as replica again when recovery.conf will be renamed back | ||
# and postgres restarted | ||
pushd ${PGDATA_BETA} | ||
mv recovery.conf{,.bak} | ||
rm backup_label | ||
/usr/lib/postgresql/10/bin/pg_resetwal -f . | ||
popd | ||
|
||
/usr/lib/postgresql/10/bin/pg_ctl -D ${PGDATA_BETA} -w start | ||
sleep 5 | ||
|
||
/usr/lib/postgresql/10/bin/pg_dump -h 127.0.0.1 -p ${BETA_PORT} -f ${BETA_DUMP} postgres | ||
|
||
diff ${ALPHA_DUMP} ${BETA_DUMP} | ||
|
||
echo "Catchup perftest success" |
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
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
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
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
Oops, something went wrong.