blob: 43044a2bcf86f66e43d3d732b7dbbd6bd003a709 (
plain)
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
|
-- create a tablespace we can use
CREATE TABLESPACE testspace LOCATION '@testtablespace@';
-- create a schema in the tablespace
CREATE SCHEMA testschema TABLESPACE testspace;
-- sanity check
SELECT nspname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_namespace n
where n.nsptablespace = t.oid and n.nspname = 'testschema';
nspname | spcname
------------+-----------
testschema | testspace
(1 row)
-- try a table
CREATE TABLE testschema.foo (i int);
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);
-- index
CREATE INDEX foo_idx on testschema.foo(i);
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)
-- Will fail with bad path
CREATE TABLESPACE badspace LOCATION '/no/such/location';
ERROR: could not set permissions on directory "/no/such/location": No such file or directory
-- 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
DROP SCHEMA testschema CASCADE;
NOTICE: drop cascades to table testschema.foo
-- Should succeed
DROP TABLESPACE testspace;
|