Postgres 13.2 数据库包含名为 company2 的模式,其中包含表和索引,位于 g:\Program Files\Postgresql\data 目录中。
服务器也有驱动器I:
如何将表和索引从company2模式移动到I:驱动器?
使用
PostgreSQL 13.2,由 Visual C++ build 1914 编译,64 位
在 Windows 服务器上。
您必须在 系统目录
上的 pl/pgsql 循环中运行一些动态 sql
execute
,以分别为其中的所有内容发出 alter...set tablespace
。例如,表位于 pg_tables
: demo at db<>fiddle
select * from pg_tables where schemaname='company2';
do $do_block$
declare record_ record;
begin
for record_ in select schemaname,tablename from pg_tables
where coalesce(tablespace,'')<>'new_tablespace'
and schemaname='company2'
loop
execute format ('alter table %I.%I set tablespace new_tablespace',record_.schemaname,record_.tablename);
end loop;
end $do_block$;
select * from pg_tables where schemaname='company2';
架构名称 | 表名 | 桌主 | 表空间 | 有索引 | 有规则 | 有触发器 | 行安全 |
---|---|---|---|---|---|---|---|
公司2 | 测试 | postgres | 空 | t | f | f | f |
架构名称 | 表名 | 桌主 | 表空间 | 有索引 | 有规则 | 有触发器 | 行安全 |
---|---|---|---|---|---|---|---|
公司2 | 测试 | postgres | 新表空间 | t | f | f | f |
外部数据包装器允许批量导入模式及其中的所有内容,权限系统允许对整个模式及其中的所有内容进行批量授予/撤销,删除可以级联到模式中的所有内容。通过扩展,期望批量表空间切换操作是合理的 - 不幸的是,没有这样的操作。