|
| 1 | +# Simple tablespace tests that can't be replicated on the same host |
| 2 | +# due to the use of absolute paths, so we keep them out of the regular |
| 3 | +# regression tests. |
| 4 | + |
| 5 | +use strict; |
| 6 | +use warnings; |
| 7 | +use PostgreSQL::Test::Cluster; |
| 8 | +use PostgreSQL::Test::Utils; |
| 9 | +use Test::More tests => 20; |
| 10 | + |
| 11 | +my $node = PostgreSQL::Test::Cluster->new('main'); |
| 12 | +$node->init; |
| 13 | +$node->start; |
| 14 | + |
| 15 | +# Create a couple of directories to use as tablespaces. |
| 16 | +my $TS1_LOCATION = $node->basedir() . "/ts1"; |
| 17 | +mkdir($TS1_LOCATION); |
| 18 | +my $TS2_LOCATION = $node->basedir() . "/ts2"; |
| 19 | +mkdir($TS2_LOCATION); |
| 20 | + |
| 21 | +my $result; |
| 22 | + |
| 23 | +# Create a tablespace with an absolute path |
| 24 | +$result = $node->psql('postgres', |
| 25 | + "CREATE TABLESPACE regress_ts1 LOCATION '$TS1_LOCATION'"); |
| 26 | +ok($result == 0, 'create tablespace with absolute path'); |
| 27 | + |
| 28 | +# Can't create a tablespace where there is one already |
| 29 | +$result = $node->psql('postgres', |
| 30 | + "CREATE TABLESPACE regress_ts1 LOCATION '$TS1_LOCATION'"); |
| 31 | +ok($result != 0, 'clobber tablespace with absolute path'); |
| 32 | + |
| 33 | +# Create table in it |
| 34 | +$result = $node->psql('postgres', |
| 35 | + "CREATE TABLE t () TABLESPACE regress_ts1"); |
| 36 | +ok($result == 0, 'create table in tablespace with absolute path'); |
| 37 | + |
| 38 | +# Can't drop a tablespace that still has a table in it |
| 39 | +$result = $node->psql('postgres', |
| 40 | + "DROP TABLESPACE regress_ts1"); |
| 41 | +ok($result != 0, 'drop tablespace with absolute path'); |
| 42 | + |
| 43 | +# Drop the table |
| 44 | +$result = $node->psql('postgres', "DROP TABLE t"); |
| 45 | +ok($result == 0, 'drop table in tablespace with absolute path'); |
| 46 | + |
| 47 | +# Drop the tablespace |
| 48 | +$result = $node->psql('postgres', "DROP TABLESPACE regress_ts1"); |
| 49 | +ok($result == 0, 'drop tablespace with absolute path'); |
| 50 | + |
| 51 | +# Create two absolute tablespaces and two in-place tablespaces, so we can |
| 52 | +# testing various kinds of tablespace moves. |
| 53 | +$result = $node->psql('postgres', |
| 54 | + "CREATE TABLESPACE regress_ts1 LOCATION '$TS1_LOCATION'"); |
| 55 | +ok($result == 0, 'create tablespace 1 with absolute path'); |
| 56 | +$result = $node->psql('postgres', |
| 57 | + "CREATE TABLESPACE regress_ts2 LOCATION '$TS2_LOCATION'"); |
| 58 | +ok($result == 0, 'create tablespace 2 with absolute path'); |
| 59 | +$result = $node->psql('postgres', |
| 60 | + "SET allow_in_place_tablespaces=on; CREATE TABLESPACE regress_ts3 LOCATION ''"); |
| 61 | +ok($result == 0, 'create tablespace 3 with in-place directory'); |
| 62 | +$result = $node->psql('postgres', |
| 63 | + "SET allow_in_place_tablespaces=on; CREATE TABLESPACE regress_ts4 LOCATION ''"); |
| 64 | +ok($result == 0, 'create tablespace 4 with in-place directory'); |
| 65 | + |
| 66 | +# Create a table and test moving between absolute and in-place tablespaces |
| 67 | +$result = $node->psql('postgres', |
| 68 | + "CREATE TABLE t () TABLESPACE regress_ts1"); |
| 69 | +ok($result == 0, 'create table in tablespace 1'); |
| 70 | +$result = $node->psql('postgres', |
| 71 | + "ALTER TABLE t SET tablespace regress_ts2"); |
| 72 | +ok($result == 0, 'move table abs->abs'); |
| 73 | +$result = $node->psql('postgres', |
| 74 | + "ALTER TABLE t SET tablespace regress_ts3"); |
| 75 | +ok($result == 0, 'move table abs->in-place'); |
| 76 | +$result = $node->psql('postgres', |
| 77 | + "ALTER TABLE t SET tablespace regress_ts4"); |
| 78 | +ok($result == 0, 'move table in-place->in-place'); |
| 79 | +$result = $node->psql('postgres', |
| 80 | + "ALTER TABLE t SET tablespace regress_ts1"); |
| 81 | +ok($result == 0, 'move table in-place->abs'); |
| 82 | + |
| 83 | +# Drop everything |
| 84 | +$result = $node->psql('postgres', |
| 85 | + "DROP TABLE t"); |
| 86 | +ok($result == 0, 'create table in tablespace 1'); |
| 87 | +$result = $node->psql('postgres', "DROP TABLESPACE regress_ts1"); |
| 88 | +ok($result == 0, 'drop tablespace 1'); |
| 89 | +$result = $node->psql('postgres', "DROP TABLESPACE regress_ts2"); |
| 90 | +ok($result == 0, 'drop tablespace 2'); |
| 91 | +$result = $node->psql('postgres', "DROP TABLESPACE regress_ts3"); |
| 92 | +ok($result == 0, 'drop tablespace 3'); |
| 93 | +$result = $node->psql('postgres', "DROP TABLESPACE regress_ts4"); |
| 94 | +ok($result == 0, 'drop tablespace 4'); |
| 95 | + |
| 96 | +$node->stop; |
0 commit comments