1.检查database,计划转移benchmarksql的table至新的tablespace
2.检查tablespace,可以看到大部分数据都位于pg_default的tablespace
3.登录root账户,创建tablespace所在的文件夹,并授权给postgres
4.创建tablespace
5.使用如下语句生成批量sql
select ‘alter table ‘||relname||’ set tablespace bmsql_tbs;’ from pg_class where relowner=(select usesysid from pg_user where usename=‘benchmarksql’) and relkind=‘r’
6.保存上图生成的sql至文件(这里取名tab.sql)
7.打开psql,切换到目标库,执行刚刚生成的脚本
8.再次确认tablespace,pg_default已经从1088MB,减少到222MB,而bmsql_tbs则增加了866MB
9.重复上述步骤,使用如下sql产生脚本去转移index至新的tablespace
select ‘alter index ‘||relname||’ set tablespace bmsql_tbs;’ from pg_class where relowner=(select usesysid from pg_user where usename=‘benchmarksql’) and relkind=‘i’