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 $ -->
22
33 <chapter id="performance-tips">
44 <title>Performance Tips</title>
@@ -800,7 +800,9 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse;
800800 prepared <command>INSERT</command> statement, and then use
801801 <command>EXECUTE</command> as many times as required. This avoids
802802 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.
804806 </para>
805807
806808 <para>
@@ -809,6 +811,20 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse;
809811 <command>INSERT</command>, even if <command>PREPARE</> is used and
810812 multiple insertions are batched into a single transaction.
811813 </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+
812828 </sect2>
813829
814830 <sect2 id="populate-rm-indexes">
@@ -877,6 +893,29 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse;
877893 </para>
878894 </sect2>
879895
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+
880919 <sect2 id="populate-analyze">
881920 <title>Run <command>ANALYZE</command> Afterwards</title>
882921
@@ -914,8 +953,12 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse;
914953 the first several guidelines are handled automatically. What is left
915954 for you to do is to set appropriate (i.e., larger than normal) values
916955 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">.
919962 </para>
920963
921964 <para>