1
- <!-- $PostgreSQL: pgsql/doc/src/sgml/perform.sgml,v 1.59 2006/10/07 20:59:03 petere Exp $ -->
1
+ <!-- $PostgreSQL: pgsql/doc/src/sgml/perform.sgml,v 1.60 2007/01/25 02:17:25 momjian Exp $ -->
2
2
3
3
<chapter id="performance-tips">
4
4
<title>Performance Tips</title>
@@ -800,7 +800,9 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse;
800
800
prepared <command>INSERT</command> statement, and then use
801
801
<command>EXECUTE</command> as many times as required. This avoids
802
802
some of the overhead of repeatedly parsing and planning
803
- <command>INSERT</command>.
803
+ <command>INSERT</command>. Different interfaces provide this facility
804
+ in different ways; look for Prepared Statements in the interface
805
+ documentation.
804
806
</para>
805
807
806
808
<para>
@@ -809,6 +811,20 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse;
809
811
<command>INSERT</command>, even if <command>PREPARE</> is used and
810
812
multiple insertions are batched into a single transaction.
811
813
</para>
814
+
815
+ <para>
816
+ <command>COPY</command> is fastest when used within the same
817
+ transaction as an earlier <command>CREATE TABLE</command> or
818
+ <command>TRUNCATE</command> command. In those cases, no WAL
819
+ needs to be written because in case of an error, the files
820
+ containing the newly loaded data will be removed automatically.
821
+ <command>CREATE TABLE AS SELECT</command> is also optimized
822
+ to avoid writing WAL. <command>COPY</command> and
823
+ <command>CREATE TABLE AS SELECT</command> will write WAL
824
+ when <xref linkend="guc-archive-command"> is set and will not
825
+ therefore be optimized in that case.
826
+ </para>
827
+
812
828
</sect2>
813
829
814
830
<sect2 id="populate-rm-indexes">
@@ -877,6 +893,29 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse;
877
893
</para>
878
894
</sect2>
879
895
896
+ <sect2 id="populate-pitr">
897
+ <title>Turn off <varname>archive_command</varname></title>
898
+
899
+ <para>
900
+ When loading large amounts of data you may want to unset the
901
+ <xref linkend="guc-archive-command"> before loading. It may be
902
+ faster to take a new base backup once the load has completed
903
+ than to allow a large archive to accumulate.
904
+ </para>
905
+
906
+ <para>
907
+ This is particularly important advice because certain commands
908
+ will perform more slowly when <varname>archive_command</varname>
909
+ is set, as a result of their needing to write large amounts of WAL.
910
+ This applies to the following commands:
911
+ <command>CREATE TABLE AS SELECT</command>,
912
+ <command>CREATE INDEX</command> and also <command>COPY</command>, when
913
+ it is executed in the same transaction as a prior
914
+ <command>CREATE TABLE</command> or <command>TRUNCATE</command> command.
915
+ </para>
916
+
917
+ </sect2>
918
+
880
919
<sect2 id="populate-analyze">
881
920
<title>Run <command>ANALYZE</command> Afterwards</title>
882
921
@@ -914,8 +953,12 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse;
914
953
the first several guidelines are handled automatically. What is left
915
954
for you to do is to set appropriate (i.e., larger than normal) values
916
955
for <varname>maintenance_work_mem</varname> and
917
- <varname>checkpoint_segments</varname> before loading the dump script,
918
- and then to run <command>ANALYZE</> afterwards.
956
+ <varname>checkpoint_segments</varname>, as well as unsetting
957
+ <varname>archive_command</varname> before loading the dump script,
958
+ and then to run <command>ANALYZE</> afterwards and resetting
959
+ <varname>archive_command</varname> if required. All of the
960
+ parameters can be reset once the load has completed without needing
961
+ to restart the server, as described in <xref linkend="config-setting">.
919
962
</para>
920
963
921
964
<para>
0 commit comments