| -- Given a segment with a database that has a tablespace |
| !\retcode mkdir -p @testtablespace@/some_basebackup_tablespace; |
| |
| drop tablespace if exists some_basebackup_tablespace; |
| create tablespace some_basebackup_tablespace location '@testtablespace@/some_basebackup_tablespace'; |
| |
| -- And a database using the tablespace |
| drop database if exists some_database_with_tablespace; |
| create database some_database_with_tablespace tablespace some_basebackup_tablespace; |
| |
| -- And a database without using the tablespace |
| drop database if exists some_database_without_tablespace; |
| create database some_database_without_tablespace; |
| |
| -- And a table and index, temp table and index using the tablespace |
| 1:@db_name some_database_without_tablespace: CREATE TABLE test(a INT, b INT) TABLESPACE some_basebackup_tablespace; |
| 1:@db_name some_database_without_tablespace: CREATE INDEX test_index on test(a) TABLESPACE some_basebackup_tablespace; |
| 2:@db_name some_database_without_tablespace: CREATE TEMP TABLE test_tmp(a INT, b INT) TABLESPACE some_basebackup_tablespace; |
| 2:@db_name some_database_without_tablespace: CREATE INDEX test_tmp_index on test_tmp(a) TABLESPACE some_basebackup_tablespace; |
| |
| 1q: |
| |
| -- When we create a full backup |
| select pg_basebackup(address, 100, port, true, 'some_replication_slot', '@testtablespace@/some_basebackup_datadir', false, 'stream') from gp_segment_configuration where content = 0 and role = 'p'; |
| |
| -- Then we should have two directories in newly created target tablespace, some_database_with_tablespace and some_database_without_tablespace |
| select count_of_items_in_directory('@testtablespace@/some_basebackup_tablespace/100/GPDB_*/'); |
| |
| -- Then we should have two files in newly created target tablespace |
| -- under the some_database_without_tablespace, test, test_index. Files |
| -- for temp table are not copied. |
| select count_of_items_in_database_directory('@testtablespace@/some_basebackup_tablespace/100/GPDB_*/', oid) from pg_database where datname='some_database_without_tablespace'; |
| |
| -- Then we should have the tablespace symlink link to the mapped tablespace directory |
| select validate_tablespace_symlink('@testtablespace@/some_basebackup_datadir', '@testtablespace@/some_basebackup_tablespace', 100, oid) from pg_tablespace where spcname='some_basebackup_tablespace'; |
| |
| -- When we create a full backup again for the same target using force overwrite |
| select pg_basebackup(address, 100, port, false, 'some_replication_slot', '@testtablespace@/some_basebackup_datadir', true, 'stream') from gp_segment_configuration where content = 0 and role = 'p'; |
| |
| -- Then we should have two directories in newly created target tablespace, some_database_with_tablespace and some_database_without_tablespace |
| select count_of_items_in_directory('@testtablespace@/some_basebackup_tablespace/100/GPDB_*/'); |
| |
| -- Then we should have two files in newly created target tablespace |
| -- under the some_database_without_tablespace, test, test_index. Files |
| -- for temp table are not copied. |
| select count_of_items_in_database_directory('@testtablespace@/some_basebackup_tablespace/100/GPDB_*/', oid) from pg_database where datname='some_database_without_tablespace'; |
| |
| -- Then we should have the tablespace symlink link to the mapped tablespace directory |
| select validate_tablespace_symlink('@testtablespace@/some_basebackup_datadir', '@testtablespace@/some_basebackup_tablespace', 100, oid) from pg_tablespace where spcname='some_basebackup_tablespace'; |
| |
| 2q: |
| |
| -- Cleanup things we've created |
| 0U: select pg_drop_replication_slot('some_replication_slot'); |
| drop database some_database_with_tablespace; |
| -- Need to poll until db drop succeeds since after 2q: happens the PGPROC |
| -- on the server side might be still not released when we run database drop. |
| -- This makes the test flaky. |
| !\retcode bash -c 'for ((i = 0; i < 5; i++)); do dropdb some_database_without_tablespace && exit 0; done; exit 1'; |
| drop tablespace some_basebackup_tablespace; |
| !\retcode rm -rf @testtablespace@/some_basebackup_datadir/; |
| !\retcode rm -rf @testtablespace@/some_basebackup_tablespace/100; |
| |
| -- Given a segment (content=0) with a tablespace mapped to a location different from that of other segments |
| !\retcode mkdir -p @testtablespace@/some_basebackup_tablespace; |
| !\retcode mkdir -p @testtablespace@/some_basebackup_tablespace_c0; |
| !\retcode mkdir -p @testtablespace@/some_basebackup_datadir; |
| |
| create tablespace some_basebackup_tablespace LOCATION '@testtablespace@/some_basebackup_tablespace' WITH (content0='@testtablespace@/some_basebackup_tablespace_c0'); |
| |
| -- And a database without using the tablespace |
| drop database if exists some_database_without_tablespace; |
| create database some_database_without_tablespace; |
| |
| -- And a table and index, temp table and index using the tablespace |
| 1:@db_name some_database_without_tablespace: CREATE TABLE test(a INT, b INT) TABLESPACE some_basebackup_tablespace; |
| 1:@db_name some_database_without_tablespace: CREATE INDEX test_index on test(a) TABLESPACE some_basebackup_tablespace; |
| 2:@db_name some_database_without_tablespace: CREATE TEMP TABLE test_tmp(a INT, b INT) TABLESPACE some_basebackup_tablespace; |
| 2:@db_name some_database_without_tablespace: CREATE INDEX test_tmp_index on test_tmp(a) TABLESPACE some_basebackup_tablespace; |
| |
| 1q: |
| |
| -- When we create a full backup |
| select pg_basebackup(address, 100, port, true, 'some_replication_slot', '@testtablespace@/some_basebackup_datadir', false, 'stream') from gp_segment_configuration where content = 0 and role = 'p'; |
| |
| -- Then we should have one directory in the newly created target tablespace, some_database_without_tablespace |
| select count_of_items_in_directory('@testtablespace@/some_basebackup_tablespace_c0/100/GPDB_*/'); |
| |
| -- Then we should have six directories under some_basebackup_tablespace - db id = {1, 3, 4, 6, 7, 8}. 100 should not be present. |
| select count_of_items_in_directory('@testtablespace@/some_basebackup_tablespace'); |
| |
| -- Then we should have the tablespace symlink link to the mapped tablespace directory |
| select validate_tablespace_symlink('@testtablespace@/some_basebackup_datadir', '@testtablespace@/some_basebackup_tablespace_c0', 100, oid) from pg_tablespace where spcname='some_basebackup_tablespace'; |
| |
| 2q: |
| |
| -- Cleanup things we've created |
| 0U: select pg_drop_replication_slot('some_replication_slot'); |
| -- Need to poll until db drop succeeds since after 2q: happens the PGPROC |
| -- on the server side might be still not released when we run database drop. |
| -- This makes the test flaky. |
| !\retcode bash -c 'for ((i = 0; i < 5; i++)); do dropdb some_database_without_tablespace && exit 0; done; exit 1'; |
| drop tablespace some_basebackup_tablespace; |
| !\retcode rm -rf @testtablespace@/some_basebackup_datadir/; |
| !\retcode rm -rf @testtablespace@/some_basebackup_tablespace_c0/100; |
| |