2004-06-18 08:14:31 +02:00
|
|
|
-- create a tablespace we can use
|
|
|
|
CREATE TABLESPACE testspace LOCATION '@testtablespace@';
|
2010-01-05 22:54:00 +01:00
|
|
|
-- try setting and resetting some properties for the new tablespace
|
|
|
|
ALTER TABLESPACE testspace SET (random_page_cost = 1.0);
|
|
|
|
ALTER TABLESPACE testspace SET (some_nonexistent_parameter = true); -- fail
|
|
|
|
ERROR: unrecognized parameter "some_nonexistent_parameter"
|
|
|
|
ALTER TABLESPACE testspace RESET (random_page_cost = 2.0); -- fail
|
|
|
|
ERROR: RESET must not include values for parameters
|
|
|
|
ALTER TABLESPACE testspace RESET (random_page_cost, seq_page_cost); -- 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
|
2004-11-05 20:17:13 +01:00
|
|
|
CREATE TABLE testschema.foo (i int) TABLESPACE testspace;
|
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';
|
|
|
|
relname | spcname
|
|
|
|
---------+-----------
|
|
|
|
foo | testspace
|
|
|
|
(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
|
|
|
|
CREATE TABLE testschema.asselect TABLESPACE testspace AS SELECT 1;
|
|
|
|
SELECT relname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_class c
|
|
|
|
where c.reltablespace = t.oid AND c.relname = 'asselect';
|
|
|
|
relname | spcname
|
|
|
|
----------+-----------
|
|
|
|
asselect | testspace
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
PREPARE selectsource(int) AS SELECT $1;
|
|
|
|
CREATE TABLE testschema.asexecute TABLESPACE testspace
|
|
|
|
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';
|
|
|
|
relname | spcname
|
|
|
|
-----------+-----------
|
|
|
|
asexecute | testspace
|
|
|
|
(1 row)
|
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
-- index
|
2004-11-05 20:17:13 +01:00
|
|
|
CREATE INDEX foo_idx on testschema.foo(i) TABLESPACE testspace;
|
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';
|
|
|
|
relname | spcname
|
|
|
|
---------+-----------
|
|
|
|
foo_idx | testspace
|
|
|
|
(1 row)
|
|
|
|
|
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);
|
|
|
|
ALTER TABLE testschema.atable SET TABLESPACE testspace;
|
|
|
|
ALTER INDEX testschema.anindex SET TABLESPACE testspace;
|
|
|
|
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
|
|
|
|
CREATE TABLESPACE 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
|
|
|
|
CREATE TABLE bar (i int) TABLESPACE nosuchspace;
|
|
|
|
ERROR: tablespace "nosuchspace" does not exist
|
|
|
|
-- Fail, not empty
|
|
|
|
DROP TABLESPACE testspace;
|
|
|
|
ERROR: tablespace "testspace" is not empty
|
2013-12-11 21:42:58 +01:00
|
|
|
CREATE ROLE tablespace_testuser1 login;
|
|
|
|
CREATE ROLE tablespace_testuser2 login;
|
|
|
|
ALTER TABLESPACE testspace OWNER TO tablespace_testuser1;
|
|
|
|
SET SESSION ROLE tablespace_testuser2;
|
|
|
|
CREATE TABLE tablespace_table (i int) TABLESPACE testspace; -- fail
|
|
|
|
ERROR: permission denied for tablespace testspace
|
|
|
|
\c -
|
|
|
|
ALTER TABLESPACE testspace RENAME TO testspace_renamed;
|
2004-06-18 08:14:31 +02:00
|
|
|
DROP SCHEMA testschema CASCADE;
|
2008-06-11 23:53:49 +02:00
|
|
|
NOTICE: drop cascades to 4 other objects
|
|
|
|
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
|
2004-06-18 08:14:31 +02:00
|
|
|
-- Should succeed
|
2013-12-11 21:42:58 +01:00
|
|
|
DROP TABLESPACE testspace_renamed;
|
|
|
|
DROP ROLE tablespace_testuser1;
|
|
|
|
DROP ROLE tablespace_testuser2;
|