From ef65f6f7a41220d578175a899fdd67b097767669 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Thu, 25 Jan 2007 02:17:26 +0000 Subject: Prevent WAL logging when COPY is done in the same transation that created it. Simon Riggs --- doc/src/sgml/perform.sgml | 51 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/perform.sgml b/doc/src/sgml/perform.sgml index 466fca8d05a..e47edcd331e 100644 --- a/doc/src/sgml/perform.sgml +++ b/doc/src/sgml/perform.sgml @@ -1,4 +1,4 @@ - + Performance Tips @@ -800,7 +800,9 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse; prepared INSERT statement, and then use EXECUTE as many times as required. This avoids some of the overhead of repeatedly parsing and planning - INSERT. + INSERT. Different interfaces provide this facility + in different ways; look for Prepared Statements in the interface + documentation. @@ -809,6 +811,20 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse; INSERT, even if PREPARE is used and multiple insertions are batched into a single transaction. + + + COPY is fastest when used within the same + transaction as an earlier CREATE TABLE or + TRUNCATE command. In those cases, no WAL + needs to be written because in case of an error, the files + containing the newly loaded data will be removed automatically. + CREATE TABLE AS SELECT is also optimized + to avoid writing WAL. COPY and + CREATE TABLE AS SELECT will write WAL + when is set and will not + therefore be optimized in that case. + + @@ -877,6 +893,29 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse; + + Turn off <varname>archive_command</varname> + + + When loading large amounts of data you may want to unset the + before loading. It may be + faster to take a new base backup once the load has completed + than to allow a large archive to accumulate. + + + + This is particularly important advice because certain commands + will perform more slowly when archive_command + is set, as a result of their needing to write large amounts of WAL. + This applies to the following commands: + CREATE TABLE AS SELECT, + CREATE INDEX and also COPY, when + it is executed in the same transaction as a prior + CREATE TABLE or TRUNCATE command. + + + + Run <command>ANALYZE</command> Afterwards @@ -914,8 +953,12 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse; the first several guidelines are handled automatically. What is left for you to do is to set appropriate (i.e., larger than normal) values for maintenance_work_mem and - checkpoint_segments before loading the dump script, - and then to run ANALYZE afterwards. + checkpoint_segments, as well as unsetting + archive_command before loading the dump script, + and then to run ANALYZE afterwards and resetting + archive_command if required. All of the + parameters can be reset once the load has completed without needing + to restart the server, as described in . -- cgit v1.2.3