陈老师:1415968548 郑老师:2735197625 乐老师:354331153
客服热线:
19941464235 / 19906632509 / 19906733890 / 19905812933(微信同号)

客服微信

【技术文章】PostgreSQL修改表空间

作者:崔鹏
原创
发布时间:2023-12-19 10:12
浏览量:1059

作者:崔鹏,曾获得中国PostgreSQL数据库管理高级工程师(PGCM),是PostgreSQL官方认证讲师,Mysql 5.7/8.0 OCP,Oracle 11g OCM


创建表空间


表空间1

postgres@pgexp1-> mkdir /opt/tbs_test1


表空间2

postgres@pgexp1-> mkdir /opt/tbs_test2 postgres@pgexp1-> psqlpsql (12.4)Type "help" for help. postgres=# create tablespace tbs_test1 location '/opt/tbs_test1'; CREATE TABLESPACEpostgres=# create tablespace tbs_test2 location '/opt/tbs_test2';CREATE TABLESPACE postgres=# \db List of tablespaces Name |  Owner   |    Location ------------+----------+---------------- pg_default | postgres | pg_global | postgres | tbs_test1 | postgres | /opt/tbs_test1 tbs_test2 | postgres | /opt/tbs_test2(4 rows)
 
创建表:
postgres=# create table test (id int) tablespace tbs_test1;CREATE TABLEpostgres=# \d+ test Table "public.test" Column | Type | Collation | Nullable | Default | Storage | Stats target | Description--------+---------+-----------+----------+---------+---------+--------------+------------- id | integer |           |          |         | plain   |              |Tablespace: "tbs_test1"Access method: heap
 
修改表空间
postgres=# alter table test set tablespace tbs_test2;ALTER TABLEpostgres=# \d+ test Table "public.test" Column | Type | Collation | Nullable | Default | Storage | Stats target | Description--------+---------+-----------+----------+---------+---------+--------------+------------- id | integer |           |          |         | plain   |              |Tablespace: "tbs_test2"Access method: heap