2014-01-19 02:59:31 +01:00
|
|
|
-- create a tablespace using WITH clause
|
2016-07-18 00:42:31 +02:00
|
|
|
CREATE TABLESPACE regress_tblspacewith LOCATION '@testtablespace@' WITH (some_nonexistent_parameter = true); -- fail
|
2014-01-19 02:59:31 +01:00
|
|
|
ERROR: unrecognized parameter "some_nonexistent_parameter"
|
2016-07-18 00:42:31 +02:00
|
|
|
CREATE TABLESPACE regress_tblspacewith LOCATION '@testtablespace@' WITH (random_page_cost = 3.0); -- ok
|
2014-01-19 02:59:31 +01:00
|
|
|
-- check to see the parameter was used
|
2016-07-18 00:42:31 +02:00
|
|
|
SELECT spcoptions FROM pg_tablespace WHERE spcname = 'regress_tblspacewith';
|
2014-01-19 02:59:31 +01:00
|
|
|
spcoptions
|
|
|
|
------------------------
|
|
|
|
{random_page_cost=3.0}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- drop the tablespace so we can re-use the location
|
2016-07-18 00:42:31 +02:00
|
|
|
DROP TABLESPACE regress_tblspacewith;
|
2004-06-18 08:14:31 +02:00
|
|
|
-- create a tablespace we can use
|
2016-07-18 00:42:31 +02:00
|
|
|
CREATE TABLESPACE regress_tblspace LOCATION '@testtablespace@';
|
2010-01-05 22:54:00 +01:00
|
|
|
-- try setting and resetting some properties for the new tablespace
|
2017-10-19 14:14:18 +02:00
|
|
|
ALTER TABLESPACE regress_tblspace SET (random_page_cost = 1.0, seq_page_cost = 1.1);
|
2016-07-18 00:42:31 +02:00
|
|
|
ALTER TABLESPACE regress_tblspace SET (some_nonexistent_parameter = true); -- fail
|
2010-01-05 22:54:00 +01:00
|
|
|
ERROR: unrecognized parameter "some_nonexistent_parameter"
|
2016-07-18 00:42:31 +02:00
|
|
|
ALTER TABLESPACE regress_tblspace RESET (random_page_cost = 2.0); -- fail
|
2010-01-05 22:54:00 +01:00
|
|
|
ERROR: RESET must not include values for parameters
|
2017-10-19 14:14:18 +02:00
|
|
|
ALTER TABLESPACE regress_tblspace RESET (random_page_cost, effective_io_concurrency); -- ok
|
2004-11-05 20:17:13 +01:00
|
|
|
-- create a schema we can use
|
|
|
|
CREATE SCHEMA testschema;
|
2004-06-18 08:14:31 +02:00
|
|
|
-- try a table
|
2016-07-18 00:42:31 +02:00
|
|
|
CREATE TABLE testschema.foo (i int) TABLESPACE regress_tblspace;
|
2004-06-18 08:14:31 +02:00
|
|
|
SELECT relname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_class c
|
|
|
|
where c.reltablespace = t.oid AND c.relname = 'foo';
|
2016-07-18 00:42:31 +02:00
|
|
|
relname | spcname
|
|
|
|
---------+------------------
|
|
|
|
foo | regress_tblspace
|
2004-06-18 08:14:31 +02:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
INSERT INTO testschema.foo VALUES(1);
|
|
|
|
INSERT INTO testschema.foo VALUES(2);
|
2006-02-19 01:04:28 +01:00
|
|
|
-- tables from dynamic sources
|
2016-07-18 00:42:31 +02:00
|
|
|
CREATE TABLE testschema.asselect TABLESPACE regress_tblspace AS SELECT 1;
|
2006-02-19 01:04:28 +01:00
|
|
|
SELECT relname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_class c
|
|
|
|
where c.reltablespace = t.oid AND c.relname = 'asselect';
|
2016-07-18 00:42:31 +02:00
|
|
|
relname | spcname
|
|
|
|
----------+------------------
|
|
|
|
asselect | regress_tblspace
|
2006-02-19 01:04:28 +01:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
PREPARE selectsource(int) AS SELECT $1;
|
2016-07-18 00:42:31 +02:00
|
|
|
CREATE TABLE testschema.asexecute TABLESPACE regress_tblspace
|
2006-02-19 01:04:28 +01:00
|
|
|
AS EXECUTE selectsource(2);
|
|
|
|
SELECT relname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_class c
|
|
|
|
where c.reltablespace = t.oid AND c.relname = 'asexecute';
|
2016-07-18 00:42:31 +02:00
|
|
|
relname | spcname
|
|
|
|
-----------+------------------
|
|
|
|
asexecute | regress_tblspace
|
2006-02-19 01:04:28 +01:00
|
|
|
(1 row)
|
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
-- index
|
2016-07-18 00:42:31 +02:00
|
|
|
CREATE INDEX foo_idx on testschema.foo(i) TABLESPACE regress_tblspace;
|
2004-06-18 08:14:31 +02:00
|
|
|
SELECT relname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_class c
|
|
|
|
where c.reltablespace = t.oid AND c.relname = 'foo_idx';
|
2016-07-18 00:42:31 +02:00
|
|
|
relname | spcname
|
|
|
|
---------+------------------
|
|
|
|
foo_idx | regress_tblspace
|
2004-06-18 08:14:31 +02:00
|
|
|
(1 row)
|
|
|
|
|
2016-11-23 19:45:55 +01:00
|
|
|
-- check that default_tablespace doesn't affect ALTER TABLE index rebuilds
|
|
|
|
CREATE TABLE testschema.test_default_tab(id bigint) TABLESPACE regress_tblspace;
|
|
|
|
INSERT INTO testschema.test_default_tab VALUES (1);
|
|
|
|
CREATE INDEX test_index1 on testschema.test_default_tab (id);
|
|
|
|
CREATE INDEX test_index2 on testschema.test_default_tab (id) TABLESPACE regress_tblspace;
|
|
|
|
\d testschema.test_index1
|
2018-07-19 20:53:41 +02:00
|
|
|
Index "testschema.test_index1"
|
|
|
|
Column | Type | Key? | Definition
|
|
|
|
--------+--------+------+------------
|
|
|
|
id | bigint | yes | id
|
2016-11-23 19:45:55 +01:00
|
|
|
btree, for table "testschema.test_default_tab"
|
|
|
|
|
|
|
|
\d testschema.test_index2
|
2018-07-19 20:53:41 +02:00
|
|
|
Index "testschema.test_index2"
|
|
|
|
Column | Type | Key? | Definition
|
|
|
|
--------+--------+------+------------
|
|
|
|
id | bigint | yes | id
|
2016-11-23 19:45:55 +01:00
|
|
|
btree, for table "testschema.test_default_tab"
|
|
|
|
Tablespace: "regress_tblspace"
|
|
|
|
|
|
|
|
-- use a custom tablespace for default_tablespace
|
|
|
|
SET default_tablespace TO regress_tblspace;
|
|
|
|
-- tablespace should not change if no rewrite
|
|
|
|
ALTER TABLE testschema.test_default_tab ALTER id TYPE bigint;
|
|
|
|
\d testschema.test_index1
|
2018-07-19 20:53:41 +02:00
|
|
|
Index "testschema.test_index1"
|
|
|
|
Column | Type | Key? | Definition
|
|
|
|
--------+--------+------+------------
|
|
|
|
id | bigint | yes | id
|
2016-11-23 19:45:55 +01:00
|
|
|
btree, for table "testschema.test_default_tab"
|
|
|
|
|
|
|
|
\d testschema.test_index2
|
2018-07-19 20:53:41 +02:00
|
|
|
Index "testschema.test_index2"
|
|
|
|
Column | Type | Key? | Definition
|
|
|
|
--------+--------+------+------------
|
|
|
|
id | bigint | yes | id
|
2016-11-23 19:45:55 +01:00
|
|
|
btree, for table "testschema.test_default_tab"
|
|
|
|
Tablespace: "regress_tblspace"
|
|
|
|
|
|
|
|
SELECT * FROM testschema.test_default_tab;
|
|
|
|
id
|
|
|
|
----
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- tablespace should not change even if there is an index rewrite
|
|
|
|
ALTER TABLE testschema.test_default_tab ALTER id TYPE int;
|
|
|
|
\d testschema.test_index1
|
2018-07-19 20:53:41 +02:00
|
|
|
Index "testschema.test_index1"
|
|
|
|
Column | Type | Key? | Definition
|
|
|
|
--------+---------+------+------------
|
|
|
|
id | integer | yes | id
|
2016-11-23 19:45:55 +01:00
|
|
|
btree, for table "testschema.test_default_tab"
|
|
|
|
|
|
|
|
\d testschema.test_index2
|
2018-07-19 20:53:41 +02:00
|
|
|
Index "testschema.test_index2"
|
|
|
|
Column | Type | Key? | Definition
|
|
|
|
--------+---------+------+------------
|
|
|
|
id | integer | yes | id
|
2016-11-23 19:45:55 +01:00
|
|
|
btree, for table "testschema.test_default_tab"
|
|
|
|
Tablespace: "regress_tblspace"
|
|
|
|
|
|
|
|
SELECT * FROM testschema.test_default_tab;
|
|
|
|
id
|
|
|
|
----
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- now use the default tablespace for default_tablespace
|
|
|
|
SET default_tablespace TO '';
|
|
|
|
-- tablespace should not change if no rewrite
|
|
|
|
ALTER TABLE testschema.test_default_tab ALTER id TYPE int;
|
|
|
|
\d testschema.test_index1
|
2018-07-19 20:53:41 +02:00
|
|
|
Index "testschema.test_index1"
|
|
|
|
Column | Type | Key? | Definition
|
|
|
|
--------+---------+------+------------
|
|
|
|
id | integer | yes | id
|
2016-11-23 19:45:55 +01:00
|
|
|
btree, for table "testschema.test_default_tab"
|
|
|
|
|
|
|
|
\d testschema.test_index2
|
2018-07-19 20:53:41 +02:00
|
|
|
Index "testschema.test_index2"
|
|
|
|
Column | Type | Key? | Definition
|
|
|
|
--------+---------+------+------------
|
|
|
|
id | integer | yes | id
|
2016-11-23 19:45:55 +01:00
|
|
|
btree, for table "testschema.test_default_tab"
|
|
|
|
Tablespace: "regress_tblspace"
|
|
|
|
|
|
|
|
-- tablespace should not change even if there is an index rewrite
|
|
|
|
ALTER TABLE testschema.test_default_tab ALTER id TYPE bigint;
|
|
|
|
\d testschema.test_index1
|
2018-07-19 20:53:41 +02:00
|
|
|
Index "testschema.test_index1"
|
|
|
|
Column | Type | Key? | Definition
|
|
|
|
--------+--------+------+------------
|
|
|
|
id | bigint | yes | id
|
2016-11-23 19:45:55 +01:00
|
|
|
btree, for table "testschema.test_default_tab"
|
|
|
|
|
|
|
|
\d testschema.test_index2
|
2018-07-19 20:53:41 +02:00
|
|
|
Index "testschema.test_index2"
|
|
|
|
Column | Type | Key? | Definition
|
|
|
|
--------+--------+------+------------
|
|
|
|
id | bigint | yes | id
|
2016-11-23 19:45:55 +01:00
|
|
|
btree, for table "testschema.test_default_tab"
|
|
|
|
Tablespace: "regress_tblspace"
|
|
|
|
|
|
|
|
DROP TABLE testschema.test_default_tab;
|
2016-11-24 20:13:19 +01:00
|
|
|
-- check that default_tablespace affects index additions in ALTER TABLE
|
|
|
|
CREATE TABLE testschema.test_tab(id int) TABLESPACE regress_tblspace;
|
|
|
|
INSERT INTO testschema.test_tab VALUES (1);
|
|
|
|
SET default_tablespace TO regress_tblspace;
|
|
|
|
ALTER TABLE testschema.test_tab ADD CONSTRAINT test_tab_unique UNIQUE (id);
|
|
|
|
SET default_tablespace TO '';
|
|
|
|
ALTER TABLE testschema.test_tab ADD CONSTRAINT test_tab_pkey PRIMARY KEY (id);
|
|
|
|
\d testschema.test_tab_unique
|
2018-07-19 20:53:41 +02:00
|
|
|
Index "testschema.test_tab_unique"
|
|
|
|
Column | Type | Key? | Definition
|
|
|
|
--------+---------+------+------------
|
|
|
|
id | integer | yes | id
|
2016-11-24 20:13:19 +01:00
|
|
|
unique, btree, for table "testschema.test_tab"
|
|
|
|
Tablespace: "regress_tblspace"
|
|
|
|
|
|
|
|
\d testschema.test_tab_pkey
|
2018-07-19 20:53:41 +02:00
|
|
|
Index "testschema.test_tab_pkey"
|
|
|
|
Column | Type | Key? | Definition
|
|
|
|
--------+---------+------+------------
|
|
|
|
id | integer | yes | id
|
2016-11-24 20:13:19 +01:00
|
|
|
primary key, btree, for table "testschema.test_tab"
|
|
|
|
|
|
|
|
SELECT * FROM testschema.test_tab;
|
|
|
|
id
|
|
|
|
----
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
DROP TABLE testschema.test_tab;
|
2007-01-02 22:43:36 +01:00
|
|
|
-- let's try moving a table from one place to another
|
|
|
|
CREATE TABLE testschema.atable AS VALUES (1), (2);
|
|
|
|
CREATE UNIQUE INDEX anindex ON testschema.atable(column1);
|
2016-07-18 00:42:31 +02:00
|
|
|
ALTER TABLE testschema.atable SET TABLESPACE regress_tblspace;
|
|
|
|
ALTER INDEX testschema.anindex SET TABLESPACE regress_tblspace;
|
2007-01-02 22:43:36 +01:00
|
|
|
INSERT INTO testschema.atable VALUES(3); -- ok
|
|
|
|
INSERT INTO testschema.atable VALUES(1); -- fail (checks index)
|
2007-06-04 00:16:03 +02:00
|
|
|
ERROR: duplicate key value violates unique constraint "anindex"
|
2009-08-01 21:59:41 +02:00
|
|
|
DETAIL: Key (column1)=(1) already exists.
|
2007-01-02 22:43:36 +01:00
|
|
|
SELECT COUNT(*) FROM testschema.atable; -- checks heap
|
|
|
|
count
|
|
|
|
-------
|
|
|
|
3
|
|
|
|
(1 row)
|
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
-- Will fail with bad path
|
2016-07-18 00:42:31 +02:00
|
|
|
CREATE TABLESPACE regress_badspace LOCATION '/no/such/location';
|
2010-01-12 03:42:52 +01:00
|
|
|
ERROR: directory "/no/such/location" does not exist
|
2004-06-18 08:14:31 +02:00
|
|
|
-- No such tablespace
|
2016-07-18 00:42:31 +02:00
|
|
|
CREATE TABLE bar (i int) TABLESPACE regress_nosuchspace;
|
|
|
|
ERROR: tablespace "regress_nosuchspace" does not exist
|
2004-06-18 08:14:31 +02:00
|
|
|
-- Fail, not empty
|
2016-07-18 00:42:31 +02:00
|
|
|
DROP TABLESPACE regress_tblspace;
|
|
|
|
ERROR: tablespace "regress_tblspace" is not empty
|
|
|
|
CREATE ROLE regress_tablespace_user1 login;
|
|
|
|
CREATE ROLE regress_tablespace_user2 login;
|
2017-02-12 22:03:41 +01:00
|
|
|
GRANT USAGE ON SCHEMA testschema TO regress_tablespace_user2;
|
2016-07-18 00:42:31 +02:00
|
|
|
ALTER TABLESPACE regress_tblspace OWNER TO regress_tablespace_user1;
|
2017-02-12 22:03:41 +01:00
|
|
|
CREATE TABLE testschema.tablespace_acl (c int);
|
|
|
|
-- new owner lacks permission to create this index from scratch
|
|
|
|
CREATE INDEX k ON testschema.tablespace_acl (c) TABLESPACE regress_tblspace;
|
|
|
|
ALTER TABLE testschema.tablespace_acl OWNER TO regress_tablespace_user2;
|
2016-07-18 00:42:31 +02:00
|
|
|
SET SESSION ROLE regress_tablespace_user2;
|
|
|
|
CREATE TABLE tablespace_table (i int) TABLESPACE regress_tblspace; -- fail
|
|
|
|
ERROR: permission denied for tablespace regress_tblspace
|
2017-02-12 22:03:41 +01:00
|
|
|
ALTER TABLE testschema.tablespace_acl ALTER c TYPE bigint;
|
2014-11-12 13:33:17 +01:00
|
|
|
RESET ROLE;
|
2016-07-18 00:42:31 +02:00
|
|
|
ALTER TABLESPACE regress_tblspace RENAME TO regress_tblspace_renamed;
|
|
|
|
ALTER TABLE ALL IN TABLESPACE regress_tblspace_renamed SET TABLESPACE pg_default;
|
|
|
|
ALTER INDEX ALL IN TABLESPACE regress_tblspace_renamed SET TABLESPACE pg_default;
|
2014-01-19 00:56:40 +01:00
|
|
|
-- Should show notice that nothing was done
|
2016-07-18 00:42:31 +02:00
|
|
|
ALTER TABLE ALL IN TABLESPACE regress_tblspace_renamed SET TABLESPACE pg_default;
|
|
|
|
NOTICE: no matching relations in tablespace "regress_tblspace_renamed" found
|
2014-01-19 00:56:40 +01:00
|
|
|
-- Should succeed
|
2016-07-18 00:42:31 +02:00
|
|
|
DROP TABLESPACE regress_tblspace_renamed;
|
2004-06-18 08:14:31 +02:00
|
|
|
DROP SCHEMA testschema CASCADE;
|
2017-02-12 22:03:41 +01:00
|
|
|
NOTICE: drop cascades to 5 other objects
|
2008-06-11 23:53:49 +02:00
|
|
|
DETAIL: drop cascades to table testschema.foo
|
|
|
|
drop cascades to table testschema.asselect
|
|
|
|
drop cascades to table testschema.asexecute
|
|
|
|
drop cascades to table testschema.atable
|
2017-02-12 22:03:41 +01:00
|
|
|
drop cascades to table testschema.tablespace_acl
|
2016-07-18 00:42:31 +02:00
|
|
|
DROP ROLE regress_tablespace_user1;
|
|
|
|
DROP ROLE regress_tablespace_user2;
|