zoukankan      html  css  js  c++  java
  • 【PostgreSQL-9.6.3】表空间

    在PostgreSQL中,表空间实际上是为表指定一个存储目录,这样方便我们把不同的表放在不同的存储介质或者文件系统中。在创建数据库、表、索引时都可以指定表空间。

    1. 创建表空间

    --表空间目录必须是系统中已存在的目录
    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

  • 相关阅读:
    九省联考2018 IIIDX
    WC2020 猜数游戏
    Gym101821D Search Engine
    Gym102586B Evacuation
    Gym102576D Clique
    UOJ498 新年的追逐战
    LOJ6703 小 Q 的序列
    Codechef A Leisurely Journey
    LG5050 多项式多点求值 和 LG5158 多项式快速插值
    PE427 n-sequences 和 ZJOI2020 抽卡
  • 原文地址:https://www.cnblogs.com/NextAction/p/7400420.html
Copyright © 2011-2022 走看看