- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit7d5c83b
committed
pg_dump: Reduce memory usage of dumps with statistics.
Right now, pg_dump stores all generated commands for statistics inmemory. These commands can be quite large and therefore cansignificantly increase pg_dump's memory footprint. To fix, waituntil we are about to write out the commands before generatingthem, and be sure to free the commands after writing. This isimplemented via a new defnDumper callback that works much like thedataDumper one but is specifically designed for TOC entries.Custom dumps that include data might write the TOC twice (to updatedata offset information), which would ordinarily cause pg_dump torun the attribute statistics queries twice. However, as a hack, wesave the length of the written-out entry in the first pass and skipover it in the second. While there is no known technical issuewith executing the queries multiple times and rewriting theresults, it's expensive and feels risky, so let's avoid it.As an exception, we _do_ execute the queries twice for the tarformat. This format does a second pass through the TOC to generatethe restore.sql file. pg_restore doesn't use this file, so even ifthe second round of queries returns different results than thefirst, it won't corrupt the output; the archive and restore.sqlfile will just have different content. A follow-up commit willteach pg_dump to gather attribute statistics in batches, which ourtesting indicates more than makes up for the added expense ofrunning the queries twice.Author: Corey Huinker <corey.huinker@gmail.com>Co-authored-by: Nathan Bossart <nathandbossart@gmail.com>Reviewed-by: Jeff Davis <pgsql@j-davis.com>Discussion:https://postgr.es/m/CADkLM%3Dc%2Br05srPy9w%2B-%2BnbmLEo15dKXYQ03Q_xyK%2BriJerigLQ%40mail.gmail.com1 parente3cc039 commit7d5c83b
File tree
4 files changed
+120
-16
lines changed- src/bin/pg_dump
4 files changed
+120
-16
lines changedLines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
285 | 285 |
| |
286 | 286 |
| |
287 | 287 |
| |
| 288 | + | |
288 | 289 |
| |
289 | 290 |
| |
290 | 291 |
| |
|
Lines changed: 81 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1266 | 1266 |
| |
1267 | 1267 |
| |
1268 | 1268 |
| |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
1269 | 1272 |
| |
1270 | 1273 |
| |
1271 | 1274 |
| |
| |||
2621 | 2624 |
| |
2622 | 2625 |
| |
2623 | 2626 |
| |
2624 |
| - | |
| 2627 | + | |
| 2628 | + | |
| 2629 | + | |
| 2630 | + | |
| 2631 | + | |
| 2632 | + | |
| 2633 | + | |
| 2634 | + | |
| 2635 | + | |
| 2636 | + | |
| 2637 | + | |
| 2638 | + | |
| 2639 | + | |
| 2640 | + | |
| 2641 | + | |
| 2642 | + | |
| 2643 | + | |
| 2644 | + | |
| 2645 | + | |
| 2646 | + | |
| 2647 | + | |
| 2648 | + | |
| 2649 | + | |
| 2650 | + | |
| 2651 | + | |
| 2652 | + | |
| 2653 | + | |
| 2654 | + | |
| 2655 | + | |
| 2656 | + | |
| 2657 | + | |
| 2658 | + | |
| 2659 | + | |
| 2660 | + | |
| 2661 | + | |
| 2662 | + | |
| 2663 | + | |
| 2664 | + | |
| 2665 | + | |
2625 | 2666 |
| |
2626 | 2667 |
| |
2627 | 2668 |
| |
| |||
3849 | 3890 |
| |
3850 | 3891 |
| |
3851 | 3892 |
| |
3852 |
| - | |
| 3893 | + | |
3853 | 3894 |
| |
3854 | 3895 |
| |
3855 | 3896 |
| |
| |||
3862 | 3903 |
| |
3863 | 3904 |
| |
3864 | 3905 |
| |
| 3906 | + | |
| 3907 | + | |
| 3908 | + | |
| 3909 | + | |
| 3910 | + | |
3865 | 3911 |
| |
3866 | 3912 |
| |
3867 | 3913 |
| |
| |||
3877 | 3923 |
| |
3878 | 3924 |
| |
3879 | 3925 |
| |
| 3926 | + | |
| 3927 | + | |
| 3928 | + | |
| 3929 | + | |
| 3930 | + | |
| 3931 | + | |
| 3932 | + | |
| 3933 | + | |
| 3934 | + | |
| 3935 | + | |
| 3936 | + | |
| 3937 | + | |
| 3938 | + | |
| 3939 | + | |
| 3940 | + | |
| 3941 | + | |
| 3942 | + | |
| 3943 | + | |
| 3944 | + | |
| 3945 | + | |
| 3946 | + | |
| 3947 | + | |
| 3948 | + | |
| 3949 | + | |
| 3950 | + | |
| 3951 | + | |
| 3952 | + | |
| 3953 | + | |
| 3954 | + | |
| 3955 | + | |
| 3956 | + | |
| 3957 | + | |
| 3958 | + | |
3880 | 3959 |
| |
3881 | 3960 |
| |
3882 | 3961 |
| |
|
Lines changed: 6 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
368 | 368 |
| |
369 | 369 |
| |
370 | 370 |
| |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
371 | 375 |
| |
372 | 376 |
| |
373 | 377 |
| |
| |||
407 | 411 |
| |
408 | 412 |
| |
409 | 413 |
| |
| 414 | + | |
| 415 | + | |
410 | 416 |
| |
411 | 417 |
| |
412 | 418 |
| |
|
Lines changed: 32 additions & 14 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
10554 | 10554 |
| |
10555 | 10555 |
| |
10556 | 10556 |
| |
10557 |
| - | |
| 10557 | + | |
10558 | 10558 |
| |
10559 |
| - | |
| 10559 | + | |
| 10560 | + | |
| 10561 | + | |
10560 | 10562 |
| |
10561 |
| - | |
10562 |
| - | |
| 10563 | + | |
| 10564 | + | |
10563 | 10565 |
| |
| 10566 | + | |
10564 | 10567 |
| |
10565 | 10568 |
| |
10566 | 10569 |
| |
10567 |
| - | |
| 10570 | + | |
| 10571 | + | |
10568 | 10572 |
| |
10569 | 10573 |
| |
10570 | 10574 |
| |
| |||
10581 | 10585 |
| |
10582 | 10586 |
| |
10583 | 10587 |
| |
10584 |
| - | |
10585 |
| - | |
10586 |
| - | |
10587 |
| - | |
10588 | 10588 |
| |
10589 | 10589 |
| |
10590 | 10590 |
| |
| |||
10620 | 10620 |
| |
10621 | 10621 |
| |
10622 | 10622 |
| |
10623 |
| - | |
| 10623 | + | |
10624 | 10624 |
| |
10625 | 10625 |
| |
10626 | 10626 |
| |
| |||
10764 | 10764 |
| |
10765 | 10765 |
| |
10766 | 10766 |
| |
| 10767 | + | |
| 10768 | + | |
| 10769 | + | |
| 10770 | + | |
| 10771 | + | |
| 10772 | + | |
| 10773 | + | |
| 10774 | + | |
| 10775 | + | |
| 10776 | + | |
| 10777 | + | |
| 10778 | + | |
| 10779 | + | |
| 10780 | + | |
| 10781 | + | |
| 10782 | + | |
| 10783 | + | |
| 10784 | + | |
| 10785 | + | |
| 10786 | + | |
10767 | 10787 |
| |
10768 | 10788 |
| |
10769 | 10789 |
| |
10770 | 10790 |
| |
10771 | 10791 |
| |
10772 |
| - | |
| 10792 | + | |
| 10793 | + | |
10773 | 10794 |
| |
10774 | 10795 |
| |
10775 |
| - | |
10776 |
| - | |
10777 |
| - | |
10778 | 10796 |
| |
10779 | 10797 |
| |
10780 | 10798 |
| |
|
0 commit comments
Comments
(0)