当前位置:Gxlcms > 数据库问题 > 【PostgreSQL】表空间

【PostgreSQL】表空间

时间:2021-07-01 10:21:17 帮助过:14人阅读

表空间目录必须是系统中已存在的目录 test=# create tablespace tb_01 location /opt/postgresql/data/pg_data; CREATE TABLESPACE

2. 创建数据库,指定表空间

test=# create database test01 tablespace tb_01;
CREATE DATABASE

3. 修改数据库的表空间

test=# alter database test01 set tablespace tb_02;
ALTER DATABASE
--修改数据库的默认表空间后,数据库中表的表空间不会改变。

4. 建表时,指定表空间

test=# create table t1 (id int,note text) tablespace tb_01;
CREATE TABLE

5. 创建索引时,指定表空间

test=# create index idx_t1_id on t1(id) tablespace tb_02;
CREATE INDEX

6. 增加约束时,指定表空间

test=# alter table t1 add constraint unique_t1_id unique (id) using index tablespace tb_02;
ALTER TABLE 
test=# alter table t1 add constraint pk_t1_id primary key (id) using index tablespace tb_02;
ALTER TABLE

7. 把表移动到新的表空间

test=# alter table t1 set tablespace tb_02;
ALTER TABLE
--表移动过程中会被锁定,所有的操作都被阻塞,包括Select,所以要选择合适的时间移动表。

 

The End!

2017-08-20

 

【PostgreSQL】表空间

标签:post   text   创建数据库   add   创建索引   指定   tables   alt   uniq   

人气教程排行