--
-- XC_NOTRANS_BLOCK
--
select pg_sleep(3);
pg_sleep
----------
(1 row)
-- This file contains tests for testing statements that cannot be run
-- within a transaction block. They verify that the cluster is consistent
-- even if one particular node aborts and others succeed.
------------
-- Test#1 : CREATE TABLESPACE
------------
START TRANSACTION;
CREATE TABLESPACE xc_testspace1 LOCATION '@testtablespace@';
ERROR: CREATE TABLESPACE cannot run inside a transaction block
ROLLBACK;
select exec_util_on_node('CREATE TABLESPACE xc_testspace1 LOCATION $LOC$@testtablespace@$LOC$', 1);
exec_util_on_node
-------------------
(1 row)
-- This should fail because we have one tablespace created on data node 1.
CREATE TABLESPACE xc_testspace1 LOCATION '@testtablespace@';
ERROR: tablespace "xc_testspace1" already exists
CONTEXT: Error message received from nodes: datanode1
-- Drop tablespace on data node 1.
select exec_util_on_node('drop TABLESPACE xc_testspace1 ', 1);
exec_util_on_node
-------------------
(1 row)
-- Now this should work
CREATE TABLESPACE xc_testspace1 LOCATION '@testtablespace@';
------------
-- Test#2 CREATE DATABASE
------------
START TRANSACTION;
CREATE DATABASE xc_db tablespace xc_testspace1;
ERROR: CREATE DATABASE cannot run inside a transaction block
ROLLBACK;
-- Drop tablespace on data node 1.
select exec_util_on_node('drop TABLESPACE xc_testspace1 ', 1);
exec_util_on_node
-------------------
(1 row)
-- This should not work because there is no tablespace on datanode1
CREATE DATABASE xc_db tablespace xc_testspace1;
ERROR: tablespace "xc_testspace1" does not exist
CONTEXT: Error message received from nodes: datanode1
select exec_util_on_node('CREATE TABLESPACE xc_testspace1 LOCATION $LOC$@testtablespace@$LOC$', 1);
exec_util_on_node
-------------------
(1 row)
-- This should work
CREATE DATABASE xc_db tablespace xc_testspace1;
------------
-- Test#3: ALTER DATABASE SET TABLESPACE
------------
START TRANSACTION;
alter database xc_db set tablespace xc_testspace1;
ERROR: ALTER DATABASE SET TABLESPACE cannot run inside a transaction block
ROLLBACK;
-- Recreate database on global tablespace.
clean connection to all for database xc_db;
drop database xc_db;
CREATE DATABASE xc_db;
-- Insert some objects.
\c xc_db
create table xc_tab1 (id int);
insert into xc_tab1 select generate_series(1, 50, 1);
\c regression
clean connection to all for database xc_db;
-- Drop tablespace on data node 1.
select exec_util_on_node('drop TABLESPACE xc_testspace1 ', 1);
exec_util_on_node
-------------------
(1 row)
clean connection to all for database xc_db;
-- This should error out, since we don't have tablespace on data node 1
alter database xc_db set tablespace xc_testspace1;
ERROR: tablespace "xc_testspace1" does not exist
CONTEXT: Error message received from nodes: datanode1
select exec_util_on_node('CREATE TABLESPACE xc_testspace1 LOCATION $LOC$@testtablespace@$LOC$', 1);
exec_util_on_node
-------------------
(1 row)
-- Now this should work.
alter database xc_db set tablespace xc_testspace1;
-- Verify data in the objects created earlier
\c xc_db
select * from xc_tab1 order by id;
id
----
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(50 rows)
\c regression
clean connection to all for database xc_db;
drop database xc_db;
drop tablespace xc_testspace1;
select pg_sleep(3);
pg_sleep
----------
(1 row)