Skip to content

Commit

Permalink
add start_postgres function and stop_function to REL_11_STABLE and RE…
Browse files Browse the repository at this point in the history
…L_10_STABLE (#233)

* Fix the fail if a tablespace path has PGDATA(#141) (#210)

Previously, if the server has a tablespace and
its path has PGDATA's path, the restore
fails because mkdirs.sh doesn't work.

For example, the following case fails to restore.

* PGDATA path: /tmp/pgdata
* tablespace path: /tmp/pgdata_tblspc

So, this patch fixes the case. The root cause
is the logic checking whether the file taking backup
is in tablespace or PGDATA.

Because it only considers their prefix, if the prefix
path of tablespace is the same as PGDATA, it decides
the file is in PGDATA.

So, this patch changes the logic to check it has '/'
after the prefix.

* add start function

Co-authored-by: mikecaat <[email protected]>
Co-authored-by: huangfumingyue <[email protected]>
  • Loading branch information
3 people committed Sep 8, 2022
1 parent 859f99e commit ad6184c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ dir_print_mkdirs_sh(FILE *out, const parray *files, const char *root)
pgFile *file = (pgFile *) parray_get(files, i);
if (S_ISDIR(file->mode))
{
if (strstr(file->path, root) == file->path)
if (strstr(file->path, root) == file->path && file->path[strlen(root)] == '/')
fprintf(out, "mkdir -m 700 -p %s\n", file->path + strlen(root) + 1);
else
fprintf(out, "mkdir -m 700 -p %s\n", file->path);
Expand Down
5 changes: 5 additions & 0 deletions expected/restore.out
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,8 @@ OK: hard-copy option works well.
0
0

###### RESTORE COMMAND TEST-0018 ######
###### check to work even if the path of tablespace has $PGDATA ######
0
0

5 changes: 5 additions & 0 deletions expected/restore_checksum.out
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,8 @@ OK: hard-copy option works well.
0
0

###### RESTORE COMMAND TEST-0018 ######
###### check to work even if the path of tablespace has $PGDATA ######
0
0

41 changes: 41 additions & 0 deletions sql/restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ function server_is_running
pg_ctl status | grep "server is running" | wc -l
}

function start_postgres
{
pg_ctl start -w -t 600 > /dev/null 2>&1
}

function stop_postgres
{
pg_ctl stop -m fast > /dev/null 2>&1
}

function pg_is_in_recovery
{
psql -tA -p ${TEST_PGPORT} --no-psqlrc -d pgbench -c "SELECT pg_is_in_recovery();"
Expand Down Expand Up @@ -441,6 +451,37 @@ psql --no-psqlrc -p ${TEST_PGPORT} -d db0015 -c "SELECT * FROM t0015;" > ${TEST_
diff ${TEST_BASE}/TEST-0015-before.out ${TEST_BASE}/TEST-0015-after.out
echo ''

echo '###### RESTORE COMMAND TEST-0018 ######'
echo '###### check to work even if the path of tablespace has $PGDATA ######'
init_backup
start_postgres

TBLSPC_PATH_HAS_PGDATA_PATH=${PGDATA_PATH}_test_tbl/test
TEST_DB=test

mkdir -p ${TBLSPC_PATH_HAS_PGDATA_PATH}
psql --no-psqlrc -p ${TEST_PGPORT} -d postgres > /dev/null 2>&1 << EOF
CREATE TABLESPACE ${TEST_DB} LOCATION '${TBLSPC_PATH_HAS_PGDATA_PATH}';
CREATE DATABASE ${TEST_DB} TABLESPACE = ${TEST_DB};
EOF

pgbench -p ${TEST_PGPORT} -i -s 10 -d ${TEST_DB} > /dev/null 2>&1
psql -p ${TEST_PGPORT} --no-psqlrc -d ${TEST_DB} -c "SELECT * FROM pgbench_branches;" > ${TEST_BASE}/TEST-0018-before.out

pg_rman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet;echo $?
pg_rman validate -B ${BACKUP_PATH} --quiet
stop_postgres
pg_rman restore -B ${BACKUP_PATH} --quiet;echo $?
start_postgres
sleep 1

psql -p ${TEST_PGPORT} --no-psqlrc -d ${TEST_DB} -c "SELECT * FROM pgbench_branches;" > ${TEST_BASE}/TEST-0018-after.out
diff ${TEST_BASE}/TEST-0018-before.out ${TEST_BASE}/TEST-0018-after.out

stop_postgres
rm -r ${TBLSPC_PATH_HAS_PGDATA_PATH}
echo ''

# clean up the temporal test data
pg_ctl stop -m immediate > /dev/null 2>&1
rm -fr ${PGDATA_PATH}
Expand Down

0 comments on commit ad6184c

Please sign in to comment.