postgresql逻辑结构--表空间(四)

一、创建表空间

1、 语法:create tablespace tablespace_name [owner user_name] location 'directory'

postgres=# create tablespace tbs_data location '/var/lib/pgsql/9.6/pgdata';
CREATE TABLESPACE

  

2、创建数据库时设置默认目录

postgres=# create database db01 tablespace tbs_data;
CREATE DATABASE

  

3、改变一个数据库默认表空间

postgres=# alter database db01 set tablespace tbs_data;
ALTER DATABASE  

操作时不能有人同时连接这个数据库,数据库中已有的表空间不会改变

 

4、创建表的时候也可以指定表空间。

postgres=# create table test04(id int,note text) tablespace tbs_data;
CREATE TABLE

  

5 、创建索引的时候指定表空间

postgres=# create index idx_test01_id on test04(id) tablespace tbs_data;
CREATE INDEX

  

6、创建唯一约束指定约束索引的表空间

postgres=# alter table test04 add constraint unique_test04_id unique(id) using index tablespace tbs_data;
ALTER TABLE

  

7、增加主键时也可以指定主键索引的表空间

postgres=# alter table test04 add constraint pk_test04_id primary key(id) using index tablespace tbs_data;
ALTER TABLE

  

 

posted @ 2018-05-17 17:16  Mr-Lee-long  阅读(640)  评论(0编辑  收藏  举报