[英]Backup Postgres Table using pg_dump is there a workaround to include the --jobs option
I am using postgres 12 and have a database thats 1TB in size.我正在使用 postgres 12 并且有一个大小为 1TB 的数据库。 I am performing a big delete on a table that is 140+GB in size.
我正在对大小为 140+GB 的表执行大删除。
I am testing the process and am looking to do a pg_dump of the table and its contents however running as is takes approximately 33mins我正在测试该过程,并希望对表及其内容进行 pg_dump,但按原样运行大约需要 33 分钟
pg_dump -d titan -t public.play > /backup/playBackup.sql
I know that pg_dump does include a --jobs option which given I have a 32 core machine could really utilise but that's to backup the database itself as opposed to a table in the database.我知道 pg_dump 确实包含一个 --jobs 选项,如果我有一台 32 核机器可以真正利用它,但那是为了备份数据库本身而不是数据库中的表。
Is there a quicker way of backing up the table I need?有没有更快的方法来备份我需要的表?
The --jobs
option, which works only with a "database" format dump, won't help you with a single table, because a single table is dumped by a single process. --jobs
选项仅适用于“数据库”格式转储,不会帮助您处理单个表,因为单个表由单个进程转储。
You could of course start a couple of parallel COPY
statements:您当然可以启动几个并行的
COPY
语句:
COPY (SELECT * FROM titan WHERE id % 5 = 0) TO '/path/titan0.csv' (FORMAT 'csv');
COPY (SELECT * FROM titan WHERE id % 5 = 1) TO '/path/titan1.csv' (FORMAT 'csv');
COPY (SELECT * FROM titan WHERE id % 5 = 2) TO '/path/titan2.csv' (FORMAT 'csv');
COPY (SELECT * FROM titan WHERE id % 5 = 3) TO '/path/titan3.csv' (FORMAT 'csv');
COPY (SELECT * FROM titan WHERE id % 5 = 4) TO '/path/titan4.csv' (FORMAT 'csv');
If you start these statements at the same time, you have a chance to get synchronized sequential scans and get done with a single read of the table.如果您同时启动这些语句,您就有机会获得同步的顺序扫描并完成对表的一次读取。 Then you can load those files in parallel.
然后您可以并行加载这些文件。
If you need the table structure too, run these:如果您也需要表结构,请运行以下命令:
pg_dump --section=pre-data -t public.play titan
pg_dump --section=post-data -t public.play titan
First restore pre-data, then the data, then post-data.先恢复前数据,再恢复数据,再恢复后数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.