Postgres表空间相关操作


创建表空间的语法:
highgo=# create tablespace test [owner test] location '/hgdb/test';
CREATE TABLESPACE


创建数据库时可以指定默认的表空间:
create database db01 tablespace tbsspace;


改变一个数据库的默认表空间:   
alter database db01 set tablespace new_tabspace;
注:更改数据库默认表空间时,必须没有人同时连到这个数据库上,否则会报错如下:
highgo=# alter database b set tablespace test;
错误:  其他用户正在使用数据库 "b"
DETAIL:  那里有1个其它会话正在使用数据库.


对当前连接的数据库无法更改默认表空间 :
highgo=# alter database highgo set tablespace test;
错误:  无法改变当前已打开数据库的表空间




改变数据库的默认表空间时 ,数据库中已有表的表空间并不会改变。


创建表的时候可以指定表空间:
create table test (id int) tablespace tbsspace;


创建索引、唯一约束、增加主键等都可以指定默认的表空间。




把表从一个表空间移动到另一个表空间的命令如下:
alter table test01 set tablespace pg_default;
注意:在移动表的时候会锁表,此时对该表的所有操作都将被阻塞,包括select操作,所以请考虑在合适的时候做这个操作。


highgo=# create table test (id int);
CREATE TABLE
highgo=# \d test
     Table "public.test"
 Column |  Type   | Modifiers 
--------+---------+-----------
 id     | integer | 
highgo=# alter table test set tablespace test;
ALTER TABLE
highgo=# \d test
     Table "public.test"
 Column |  Type   | Modifiers 
--------+---------+-----------
 id     | integer | 
Tablespace: "test"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值