dump/restore table into/from 块

dump/restore table into/from chunks

我有一个包含数百万行的非常大的数据库。我想通过使用可以从 0 到 9 或从 a 到 z 开始的注册将 table 转储到块中;所以我有 运行 这个 scrypt,其中 return 我每次注册的纯文本:

for i in 1 2 3 4 5 6 7 8 9 A B C D E G H I K L M N O P R S T W Y Z;
do
echo "exporting registration beginning with $i"
    psql "host=localhost port=5432 dbname=mydb user=user password=password" -c "\copy (
        SELECT * from registration_table_2021_06 where left(registration_no, 1) = '$i') TO '/path/to/folder/where/are/the/chunks_$i"
done

我想知道的是,首先流程是否正确,如果不正确,如何将巨大的 table 拆分成仅包含数据的块。

如果过程正确,我如何将所有块重新编译到其他数据库中的新 table。

如果这涵盖了所有数据(例如,没有 NULL 值),那应该没问题。但是由于这需要对大型 table 进行多次顺序扫描,因此它的性能可能不会很好。

我不知道以这种方式分割转储有什么好处,但是 table 分区会很好地完成这项工作。如果您在 之前就想到了 table 变大了!