Skip to content

Commit c542bf2

Browse files
committed
Added tests for the namespace change feature
Currently not passing as --moveidx not implemented yet.
1 parent 6488eca commit c542bf2

File tree

3 files changed

+121
-1
lines changed

3 files changed

+121
-1
lines changed

bin/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
SRCS = pg_repack.c pgut/pgut.c pgut/pgut-fe.c
99
OBJS = $(SRCS:.c=.o)
1010
PROGRAM = pg_repack
11-
REGRESS = init repack
11+
REGRESS = init repack tablespace
1212

1313
EXTRA_CLEAN = sql/init-$(MAJORVERSION).sql sql/init.sql
1414

bin/expected/tablespace.out

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
SET client_min_messages = warning;
2+
--
3+
-- Tablespace features tests
4+
--
5+
-- Note: in order to pass this test you must create a tablespace called 'testts'
6+
--
7+
SELECT spcname FROM pg_tablespace WHERE spcname = 'testts';
8+
spcname
9+
---------
10+
testts
11+
(1 row)
12+
13+
-- If the query above failed you must create the 'testts' tablespace;
14+
CREATE TABLE testts1 (id serial primary key, data text);
15+
INSERT INTO testts1 (data) values ('a');
16+
INSERT INTO testts1 (data) values ('b');
17+
INSERT INTO testts1 (data) values ('c');
18+
-- can move the tablespace from default
19+
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts
20+
SELECT relname, spcname
21+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
22+
WHERE relname ~ '^testts1';
23+
relname | spcname
24+
---------+---------
25+
testts1 | testts
26+
(1 row)
27+
28+
SELECT * from testts1 order by id;
29+
id | data
30+
----+------
31+
1 | a
32+
2 | b
33+
3 | c
34+
(3 rows)
35+
36+
-- tablespace stays where it is
37+
\! pg_repack --dbname=contrib_regression --no-order --table=testts1
38+
SELECT relname, spcname
39+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
40+
WHERE relname ~ '^testts1';
41+
relname | spcname
42+
---------+---------
43+
testts1 | testts
44+
(1 row)
45+
46+
-- can move the ts back to default
47+
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 -s pg_default
48+
SELECT relname, spcname
49+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
50+
WHERE relname ~ '^testts1';
51+
relname | spcname
52+
---------+---------
53+
(0 rows)
54+
55+
-- can move the table together with the indexes
56+
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace pg_default --moveidx
57+
SELECT relname, spcname
58+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
59+
WHERE relname ~ '^testts1';
60+
relname | spcname
61+
--------------+---------
62+
testts1 | testts
63+
testts1_pkey | testts
64+
(2 rows)
65+
66+
-- can't specify --moveidx without --tablespace
67+
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --moveidx
68+
ERROR: cannot specify --moveidx (-S) without --tablespace (-s)
69+
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 -S
70+
ERROR: cannot specify --moveidx (-S) without --tablespace (-s)

bin/sql/tablespace.sql

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
SET client_min_messages = warning;
2+
3+
--
4+
-- Tablespace features tests
5+
--
6+
-- Note: in order to pass this test you must create a tablespace called 'testts'
7+
--
8+
9+
SELECT spcname FROM pg_tablespace WHERE spcname = 'testts';
10+
-- If the query above failed you must create the 'testts' tablespace;
11+
12+
CREATE TABLE testts1 (id serial primary key, data text);
13+
INSERT INTO testts1 (data) values ('a');
14+
INSERT INTO testts1 (data) values ('b');
15+
INSERT INTO testts1 (data) values ('c');
16+
17+
-- can move the tablespace from default
18+
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts
19+
20+
SELECT relname, spcname
21+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
22+
WHERE relname ~ '^testts1';
23+
24+
SELECT * from testts1 order by id;
25+
26+
-- tablespace stays where it is
27+
\! pg_repack --dbname=contrib_regression --no-order --table=testts1
28+
29+
SELECT relname, spcname
30+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
31+
WHERE relname ~ '^testts1';
32+
33+
-- can move the ts back to default
34+
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 -s pg_default
35+
36+
SELECT relname, spcname
37+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
38+
WHERE relname ~ '^testts1';
39+
40+
-- can move the table together with the indexes
41+
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace pg_default --moveidx
42+
43+
SELECT relname, spcname
44+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
45+
WHERE relname ~ '^testts1';
46+
47+
-- can't specify --moveidx without --tablespace
48+
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --moveidx
49+
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 -S
50+

0 commit comments

Comments
 (0)