</indexterm>
<para>
- <firstterm>Transactions</> are a fundamental concept of all database
+ <firstterm>Transactions</firstterm> are a fundamental concept of all database
systems. The essential point of a transaction is that it bundles
multiple steps into a single, all-or-nothing operation. The intermediate
states between the steps are not visible to other concurrent transactions,
remain a happy customer if she was debited without Bob being credited.
We need a guarantee that if something goes wrong partway through the
operation, none of the steps executed so far will take effect. Grouping
- the updates into a <firstterm>transaction</> gives us this guarantee.
- A transaction is said to be <firstterm>atomic</>: from the point of
+ the updates into a <firstterm>transaction</firstterm> gives us this guarantee.
+ A transaction is said to be <firstterm>atomic</firstterm>: from the point of
view of other transactions, it either happens completely or not at all.
</para>
</para>
<para>
- In <productname>PostgreSQL</>, a transaction is set up by surrounding
+ In <productname>PostgreSQL</productname>, a transaction is set up by surrounding
the SQL commands of the transaction with
- <command>BEGIN</> and <command>COMMIT</> commands. So our banking
+ <command>BEGIN</command> and <command>COMMIT</command> commands. So our banking
transaction would actually look like:
<programlisting>
<para>
If, partway through the transaction, we decide we do not want to
commit (perhaps we just noticed that Alice's balance went negative),
- we can issue the command <command>ROLLBACK</> instead of
- <command>COMMIT</>, and all our updates so far will be canceled.
+ we can issue the command <command>ROLLBACK</command> instead of
+ <command>COMMIT</command>, and all our updates so far will be canceled.
</para>
<para>
- <productname>PostgreSQL</> actually treats every SQL statement as being
- executed within a transaction. If you do not issue a <command>BEGIN</>
+ <productname>PostgreSQL</productname> actually treats every SQL statement as being
+ executed within a transaction. If you do not issue a <command>BEGIN</command>
command,
- then each individual statement has an implicit <command>BEGIN</> and
- (if successful) <command>COMMIT</> wrapped around it. A group of
- statements surrounded by <command>BEGIN</> and <command>COMMIT</>
- is sometimes called a <firstterm>transaction block</>.
+ then each individual statement has an implicit <command>BEGIN</command> and
+ (if successful) <command>COMMIT</command> wrapped around it. A group of
+ statements surrounded by <command>BEGIN</command> and <command>COMMIT</command>
+ is sometimes called a <firstterm>transaction block</firstterm>.
</para>
<note>
<para>
- Some client libraries issue <command>BEGIN</> and <command>COMMIT</>
+ Some client libraries issue <command>BEGIN</command> and <command>COMMIT</command>
commands automatically, so that you might get the effect of transaction
blocks without asking. Check the documentation for the interface
you are using.
<para>
It's possible to control the statements in a transaction in a more
- granular fashion through the use of <firstterm>savepoints</>. Savepoints
+ granular fashion through the use of <firstterm>savepoints</firstterm>. Savepoints
allow you to selectively discard parts of the transaction, while
committing the rest. After defining a savepoint with
- <command>SAVEPOINT</>, you can if needed roll back to the savepoint
- with <command>ROLLBACK TO</>. All the transaction's database changes
+ <command>SAVEPOINT</command>, you can if needed roll back to the savepoint
+ with <command>ROLLBACK TO</command>. All the transaction's database changes
between defining the savepoint and rolling back to it are discarded, but
changes earlier than the savepoint are kept.
</para>
<para>
This example is, of course, oversimplified, but there's a lot of control
possible in a transaction block through the use of savepoints.
- Moreover, <command>ROLLBACK TO</> is the only way to regain control of a
+ Moreover, <command>ROLLBACK TO</command> is the only way to regain control of a
transaction block that was put in aborted state by the
system due to an error, short of rolling it back completely and starting
again.
</indexterm>
<para>
- A <firstterm>window function</> performs a calculation across a set of
+ A <firstterm>window function</firstterm> performs a calculation across a set of
table rows that are somehow related to the current row. This is comparable
to the type of calculation that can be done with an aggregate function.
However, window functions do not cause rows to become grouped into a single
</screen>
The first three output columns come directly from the table
- <structname>empsalary</>, and there is one output row for each row in the
+ <structname>empsalary</structname>, and there is one output row for each row in the
table. The fourth column represents an average taken across all the table
- rows that have the same <structfield>depname</> value as the current row.
- (This actually is the same function as the non-window <function>avg</>
- aggregate, but the <literal>OVER</> clause causes it to be
+ rows that have the same <structfield>depname</structfield> value as the current row.
+ (This actually is the same function as the non-window <function>avg</function>
+ aggregate, but the <literal>OVER</literal> clause causes it to be
treated as a window function and computed across the window frame.)
</para>
<para>
- A window function call always contains an <literal>OVER</> clause
+ A window function call always contains an <literal>OVER</literal> clause
directly following the window function's name and argument(s). This is what
syntactically distinguishes it from a normal function or non-window
- aggregate. The <literal>OVER</> clause determines exactly how the
+ aggregate. The <literal>OVER</literal> clause determines exactly how the
rows of the query are split up for processing by the window function.
- The <literal>PARTITION BY</> clause within <literal>OVER</>
+ The <literal>PARTITION BY</literal> clause within <literal>OVER</literal>
divides the rows into groups, or partitions, that share the same
- values of the <literal>PARTITION BY</> expression(s). For each row,
+ values of the <literal>PARTITION BY</literal> expression(s). For each row,
the window function is computed across the rows that fall into the
same partition as the current row.
</para>
<para>
You can also control the order in which rows are processed by
- window functions using <literal>ORDER BY</> within <literal>OVER</>.
- (The window <literal>ORDER BY</> does not even have to match the
+ window functions using <literal>ORDER BY</literal> within <literal>OVER</literal>.
+ (The window <literal>ORDER BY</literal> does not even have to match the
order in which the rows are output.) Here is an example:
<programlisting>
(10 rows)
</screen>
- As shown here, the <function>rank</> function produces a numerical rank
- for each distinct <literal>ORDER BY</> value in the current row's
- partition, using the order defined by the <literal>ORDER BY</> clause.
- <function>rank</> needs no explicit parameter, because its behavior
- is entirely determined by the <literal>OVER</> clause.
+ As shown here, the <function>rank</function> function produces a numerical rank
+ for each distinct <literal>ORDER BY</literal> value in the current row's
+ partition, using the order defined by the <literal>ORDER BY</literal> clause.
+ <function>rank</function> needs no explicit parameter, because its behavior
+ is entirely determined by the <literal>OVER</literal> clause.
</para>
<para>
The rows considered by a window function are those of the <quote>virtual
- table</> produced by the query's <literal>FROM</> clause as filtered by its
- <literal>WHERE</>, <literal>GROUP BY</>, and <literal>HAVING</> clauses
+ table</quote> produced by the query's <literal>FROM</literal> clause as filtered by its
+ <literal>WHERE</literal>, <literal>GROUP BY</literal>, and <literal>HAVING</literal> clauses
if any. For example, a row removed because it does not meet the
- <literal>WHERE</> condition is not seen by any window function.
+ <literal>WHERE</literal> condition is not seen by any window function.
A query can contain multiple window functions that slice up the data
- in different ways using different <literal>OVER</> clauses, but
+ in different ways using different <literal>OVER</literal> clauses, but
they all act on the same collection of rows defined by this virtual table.
</para>
<para>
- We already saw that <literal>ORDER BY</> can be omitted if the ordering
+ We already saw that <literal>ORDER BY</literal> can be omitted if the ordering
of rows is not important. It is also possible to omit <literal>PARTITION
- BY</>, in which case there is a single partition containing all rows.
+ BY</literal>, in which case there is a single partition containing all rows.
</para>
<para>
There is another important concept associated with window functions:
for each row, there is a set of rows within its partition called its
- <firstterm>window frame</>. Some window functions act only
+ <firstterm>window frame</firstterm>. Some window functions act only
on the rows of the window frame, rather than of the whole partition.
- By default, if <literal>ORDER BY</> is supplied then the frame consists of
+ By default, if <literal>ORDER BY</literal> is supplied then the frame consists of
all rows from the start of the partition up through the current row, plus
any following rows that are equal to the current row according to the
- <literal>ORDER BY</> clause. When <literal>ORDER BY</> is omitted the
+ <literal>ORDER BY</literal> clause. When <literal>ORDER BY</literal> is omitted the
default frame consists of all rows in the partition.
<footnote>
<para>
<xref linkend="syntax-window-functions"> for details.
</para>
</footnote>
- Here is an example using <function>sum</>:
+ Here is an example using <function>sum</function>:
</para>
<programlisting>
</screen>
<para>
- Above, since there is no <literal>ORDER BY</> in the <literal>OVER</>
+ Above, since there is no <literal>ORDER BY</literal> in the <literal>OVER</literal>
clause, the window frame is the same as the partition, which for lack of
- <literal>PARTITION BY</> is the whole table; in other words each sum is
+ <literal>PARTITION BY</literal> is the whole table; in other words each sum is
taken over the whole table and so we get the same result for each output
- row. But if we add an <literal>ORDER BY</> clause, we get very different
+ row. But if we add an <literal>ORDER BY</literal> clause, we get very different
results:
</para>
<para>
Window functions are permitted only in the <literal>SELECT</literal> list
- and the <literal>ORDER BY</> clause of the query. They are forbidden
- elsewhere, such as in <literal>GROUP BY</>, <literal>HAVING</>
+ and the <literal>ORDER BY</literal> clause of the query. They are forbidden
+ elsewhere, such as in <literal>GROUP BY</literal>, <literal>HAVING</literal>
and <literal>WHERE</literal> clauses. This is because they logically
execute after the processing of those clauses. Also, window functions
execute after non-window aggregate functions. This means it is valid to
</programlisting>
The above query only shows the rows from the inner query having
- <literal>rank</> less than 3.
+ <literal>rank</literal> less than 3.
</para>
<para>
When a query involves multiple window functions, it is possible to write
- out each one with a separate <literal>OVER</> clause, but this is
+ out each one with a separate <literal>OVER</literal> clause, but this is
duplicative and error-prone if the same windowing behavior is wanted
for several functions. Instead, each windowing behavior can be named
- in a <literal>WINDOW</> clause and then referenced in <literal>OVER</>.
+ in a <literal>WINDOW</literal> clause and then referenced in <literal>OVER</literal>.
For example:
<programlisting>
<para>
In this case, a row of <classname>capitals</classname>
- <firstterm>inherits</firstterm> all columns (<structfield>name</>,
- <structfield>population</>, and <structfield>altitude</>) from its
+ <firstterm>inherits</firstterm> all columns (<structfield>name</structfield>,
+ <structfield>population</structfield>, and <structfield>altitude</structfield>) from its
<firstterm>parent</firstterm>, <classname>cities</classname>. The
type of the column <structfield>name</structfield> is
<type>text</type>, a native <productname>PostgreSQL</productname>
type for variable length character strings. State capitals have
- an extra column, <structfield>state</>, that shows their state. In
+ an extra column, <structfield>state</structfield>, that shows their state. In
<productname>PostgreSQL</productname>, a table can inherit from
zero or more other tables.
</para>
);
</programlisting>
As shown, an array data type is named by appending square brackets
- (<literal>[]</>) to the data type name of the array elements. The
+ (<literal>[]</literal>) to the data type name of the array elements. The
above command will create a table named
<structname>sal_emp</structname> with a column of type
<type>text</type> (<structfield>name</structfield>), a
<para>
An alternative syntax, which conforms to the SQL standard by using
- the keyword <literal>ARRAY</>, can be used for one-dimensional arrays.
+ the keyword <literal>ARRAY</literal>, can be used for one-dimensional arrays.
<structfield>pay_by_quarter</structfield> could have been defined
as:
<programlisting>
<programlisting>
pay_by_quarter integer ARRAY,
</programlisting>
- As before, however, <productname>PostgreSQL</> does not enforce the
+ As before, however, <productname>PostgreSQL</productname> does not enforce the
size restriction in any case.
</para>
</sect2>
for the type, as recorded in its <literal>pg_type</literal> entry.
Among the standard data types provided in the
<productname>PostgreSQL</productname> distribution, all use a comma
- (<literal>,</>), except for type <type>box</> which uses a semicolon
- (<literal>;</>). Each <replaceable>val</replaceable> is
+ (<literal>,</literal>), except for type <type>box</type> which uses a semicolon
+ (<literal>;</literal>). Each <replaceable>val</replaceable> is
either a constant of the array element type, or a subarray. An example
of an array constant is:
<programlisting>
</para>
<para>
- To set an element of an array constant to NULL, write <literal>NULL</>
+ To set an element of an array constant to NULL, write <literal>NULL</literal>
for the element value. (Any upper- or lower-case variant of
- <literal>NULL</> will do.) If you want an actual string value
- <quote>NULL</>, you must put double quotes around it.
+ <literal>NULL</literal> will do.) If you want an actual string value
+ <quote>NULL</quote>, you must put double quotes around it.
</para>
<para>
</para>
<para>
- The <literal>ARRAY</> constructor syntax can also be used:
+ The <literal>ARRAY</literal> constructor syntax can also be used:
<programlisting>
INSERT INTO sal_emp
VALUES ('Bill',
</programlisting>
Notice that the array elements are ordinary SQL constants or
expressions; for instance, string literals are single quoted, instead of
- double quoted as they would be in an array literal. The <literal>ARRAY</>
+ double quoted as they would be in an array literal. The <literal>ARRAY</literal>
constructor syntax is discussed in more detail in
<xref linkend="sql-syntax-array-constructors">.
</para>
The array subscript numbers are written within square brackets.
By default <productname>PostgreSQL</productname> uses a
one-based numbering convention for arrays, that is,
- an array of <replaceable>n</> elements starts with <literal>array[1]</literal> and
- ends with <literal>array[<replaceable>n</>]</literal>.
+ an array of <replaceable>n</replaceable> elements starts with <literal>array[1]</literal> and
+ ends with <literal>array[<replaceable>n</replaceable>]</literal>.
</para>
<para>
If any dimension is written as a slice, i.e., contains a colon, then all
dimensions are treated as slices. Any dimension that has only a single
number (no colon) is treated as being from 1
- to the number specified. For example, <literal>[2]</> is treated as
- <literal>[1:2]</>, as in this example:
+ to the number specified. For example, <literal>[2]</literal> is treated as
+ <literal>[1:2]</literal>, as in this example:
<programlisting>
SELECT schedule[1:2][2] FROM sal_emp WHERE name = 'Bill';
</programlisting>
To avoid confusion with the non-slice case, it's best to use slice syntax
- for all dimensions, e.g., <literal>[1:2][1:1]</>, not <literal>[2][1:1]</>.
+ for all dimensions, e.g., <literal>[1:2][1:1]</literal>, not <literal>[2][1:1]</literal>.
</para>
<para>
An array subscript expression will return null if either the array itself or
any of the subscript expressions are null. Also, null is returned if a
subscript is outside the array bounds (this case does not raise an error).
- For example, if <literal>schedule</>
- currently has the dimensions <literal>[1:3][1:2]</> then referencing
- <literal>schedule[3][3]</> yields NULL. Similarly, an array reference
+ For example, if <literal>schedule</literal>
+ currently has the dimensions <literal>[1:3][1:2]</literal> then referencing
+ <literal>schedule[3][3]</literal> yields NULL. Similarly, an array reference
with the wrong number of subscripts yields a null rather than an error.
</para>
A stored array value can be enlarged by assigning to elements not already
present. Any positions between those previously present and the newly
assigned elements will be filled with nulls. For example, if array
- <literal>myarray</> currently has 4 elements, it will have six
- elements after an update that assigns to <literal>myarray[6]</>;
- <literal>myarray[5]</> will contain null.
+ <literal>myarray</literal> currently has 4 elements, it will have six
+ elements after an update that assigns to <literal>myarray[6]</literal>;
+ <literal>myarray[5]</literal> will contain null.
Currently, enlargement in this fashion is only allowed for one-dimensional
arrays, not multidimensional arrays.
</para>
<para>
Subscripted assignment allows creation of arrays that do not use one-based
- subscripts. For example one might assign to <literal>myarray[-2:7]</> to
+ subscripts. For example one might assign to <literal>myarray[-2:7]</literal> to
create an array with subscript values from -2 to 7.
</para>
<para>
The concatenation operator allows a single element to be pushed onto the
beginning or end of a one-dimensional array. It also accepts two
- <replaceable>N</>-dimensional arrays, or an <replaceable>N</>-dimensional
- and an <replaceable>N+1</>-dimensional array.
+ <replaceable>N</replaceable>-dimensional arrays, or an <replaceable>N</replaceable>-dimensional
+ and an <replaceable>N+1</replaceable>-dimensional array.
</para>
<para>
</para>
<para>
- When an <replaceable>N</>-dimensional array is pushed onto the beginning
- or end of an <replaceable>N+1</>-dimensional array, the result is
- analogous to the element-array case above. Each <replaceable>N</>-dimensional
- sub-array is essentially an element of the <replaceable>N+1</>-dimensional
+ When an <replaceable>N</replaceable>-dimensional array is pushed onto the beginning
+ or end of an <replaceable>N+1</replaceable>-dimensional array, the result is
+ analogous to the element-array case above. Each <replaceable>N</replaceable>-dimensional
+ sub-array is essentially an element of the <replaceable>N+1</replaceable>-dimensional
array's outer dimension. For example:
<programlisting>
SELECT array_dims(ARRAY[1,2] || ARRAY[[3,4],[5,6]]);
The heuristic it uses to resolve the constant's type is to assume it's of
the same type as the operator's other input — in this case,
integer array. So the concatenation operator is presumed to
- represent <function>array_cat</>, not <function>array_append</>. When
+ represent <function>array_cat</function>, not <function>array_append</function>. When
that's the wrong choice, it could be fixed by casting the constant to the
- array's element type; but explicit use of <function>array_append</> might
+ array's element type; but explicit use of <function>array_append</function> might
be a preferable solution.
</para>
</sect2>
</para>
<para>
- Alternatively, the <function>generate_subscripts</> function can be used.
+ Alternatively, the <function>generate_subscripts</function> function can be used.
For example:
<programlisting>
</para>
<para>
- You can also search an array using the <literal>&&</> operator,
+ You can also search an array using the <literal>&&</literal> operator,
which checks whether the left operand overlaps with the right operand.
For instance:
</para>
<para>
- You can also search for specific values in an array using the <function>array_position</>
- and <function>array_positions</> functions. The former returns the subscript of
+ You can also search for specific values in an array using the <function>array_position</function>
+ and <function>array_positions</function> functions. The former returns the subscript of
the first occurrence of a value in an array; the latter returns an array with the
subscripts of all occurrences of the value in the array. For example:
The external text representation of an array value consists of items that
are interpreted according to the I/O conversion rules for the array's
element type, plus decoration that indicates the array structure.
- The decoration consists of curly braces (<literal>{</> and <literal>}</>)
+ The decoration consists of curly braces (<literal>{</literal> and <literal>}</literal>)
around the array value plus delimiter characters between adjacent items.
- The delimiter character is usually a comma (<literal>,</>) but can be
- something else: it is determined by the <literal>typdelim</> setting
+ The delimiter character is usually a comma (<literal>,</literal>) but can be
+ something else: it is determined by the <literal>typdelim</literal> setting
for the array's element type. Among the standard data types provided
in the <productname>PostgreSQL</productname> distribution, all use a comma,
- except for type <type>box</>, which uses a semicolon (<literal>;</>).
+ except for type <type>box</type>, which uses a semicolon (<literal>;</literal>).
In a multidimensional array, each dimension (row, plane,
cube, etc.) gets its own level of curly braces, and delimiters
must be written between adjacent curly-braced entities of the same level.
The array output routine will put double quotes around element values
if they are empty strings, contain curly braces, delimiter characters,
double quotes, backslashes, or white space, or match the word
- <literal>NULL</>. Double quotes and backslashes
+ <literal>NULL</literal>. Double quotes and backslashes
embedded in element values will be backslash-escaped. For numeric
data types it is safe to assume that double quotes will never appear, but
for textual data types one should be prepared to cope with either the presence
set to one. To represent arrays with other lower bounds, the array
subscript ranges can be specified explicitly before writing the
array contents.
- This decoration consists of square brackets (<literal>[]</>)
+ This decoration consists of square brackets (<literal>[]</literal>)
around each array dimension's lower and upper bounds, with
- a colon (<literal>:</>) delimiter character in between. The
- array dimension decoration is followed by an equal sign (<literal>=</>).
+ a colon (<literal>:</literal>) delimiter character in between. The
+ array dimension decoration is followed by an equal sign (<literal>=</literal>).
For example:
<programlisting>
SELECT f1[1][-2][3] AS e1, f1[1][-1][5] AS e2
</para>
<para>
- If the value written for an element is <literal>NULL</> (in any case
+ If the value written for an element is <literal>NULL</literal> (in any case
variant), the element is taken to be NULL. The presence of any quotes
or backslashes disables this and allows the literal string value
- <quote>NULL</> to be entered. Also, for backward compatibility with
- pre-8.2 versions of <productname>PostgreSQL</>, the <xref
+ <quote>NULL</quote> to be entered. Also, for backward compatibility with
+ pre-8.2 versions of <productname>PostgreSQL</productname>, the <xref
linkend="guc-array-nulls"> configuration parameter can be turned
- <literal>off</> to suppress recognition of <literal>NULL</> as a NULL.
+ <literal>off</literal> to suppress recognition of <literal>NULL</literal> as a NULL.
</para>
<para>
As shown previously, when writing an array value you can use double
- quotes around any individual array element. You <emphasis>must</> do so
+ quotes around any individual array element. You <emphasis>must</emphasis> do so
if the element value would otherwise confuse the array-value parser.
For example, elements containing curly braces, commas (or the data type's
delimiter character), double quotes, backslashes, or leading or trailing
whitespace must be double-quoted. Empty strings and strings matching the
- word <literal>NULL</> must be quoted, too. To put a double quote or
+ word <literal>NULL</literal> must be quoted, too. To put a double quote or
backslash in a quoted array element value, use escape string syntax
and precede it with a backslash. Alternatively, you can avoid quotes and use
backslash-escaping to protect all data characters that would otherwise
<para>
Remember that what you write in an SQL command will first be interpreted
as a string literal, and then as an array. This doubles the number of
- backslashes you need. For example, to insert a <type>text</> array
+ backslashes you need. For example, to insert a <type>text</type> array
value containing a backslash and a double quote, you'd need to write:
<programlisting>
INSERT ... VALUES (E'{"\\\\","\\""}');
</programlisting>
The escape string processor removes one level of backslashes, so that
- what arrives at the array-value parser looks like <literal>{"\\","\""}</>.
- In turn, the strings fed to the <type>text</> data type's input routine
- become <literal>\</> and <literal>"</> respectively. (If we were working
+ what arrives at the array-value parser looks like <literal>{"\\","\""}</literal>.
+ In turn, the strings fed to the <type>text</type> data type's input routine
+ become <literal>\</literal> and <literal>"</literal> respectively. (If we were working
with a data type whose input routine also treated backslashes specially,
- <type>bytea</> for example, we might need as many as eight backslashes
+ <type>bytea</type> for example, we might need as many as eight backslashes
in the command to get one backslash into the stored array element.)
Dollar quoting (see <xref linkend="sql-syntax-dollar-quoting">) can be
used to avoid the need to double backslashes.
<tip>
<para>
- The <literal>ARRAY</> constructor syntax (see
+ The <literal>ARRAY</literal> constructor syntax (see
<xref linkend="sql-syntax-array-constructors">) is often easier to work
with than the array-literal syntax when writing array values in SQL
- commands. In <literal>ARRAY</>, individual element values are written the
+ commands. In <literal>ARRAY</literal>, individual element values are written the
same way they would be written when not members of an array.
</para>
</tip>
<chapter id="backup">
<title>Backup and Restore</title>
- <indexterm zone="backup"><primary>backup</></>
+ <indexterm zone="backup"><primary>backup</primary></indexterm>
<para>
- As with everything that contains valuable data, <productname>PostgreSQL</>
+ As with everything that contains valuable data, <productname>PostgreSQL</productname>
databases should be backed up regularly. While the procedure is
essentially simple, it is important to have a clear understanding of
the underlying techniques and assumptions.
<para>
There are three fundamentally different approaches to backing up
- <productname>PostgreSQL</> data:
+ <productname>PostgreSQL</productname> data:
<itemizedlist>
- <listitem><para><acronym>SQL</> dump</para></listitem>
+ <listitem><para><acronym>SQL</acronym> dump</para></listitem>
<listitem><para>File system level backup</para></listitem>
<listitem><para>Continuous archiving</para></listitem>
</itemizedlist>
</para>
<sect1 id="backup-dump">
- <title><acronym>SQL</> Dump</title>
+ <title><acronym>SQL</acronym> Dump</title>
<para>
The idea behind this dump method is to generate a file with SQL
commands that, when fed back to the server, will recreate the
database in the same state as it was at the time of the dump.
- <productname>PostgreSQL</> provides the utility program
+ <productname>PostgreSQL</productname> provides the utility program
<xref linkend="app-pgdump"> for this purpose. The basic usage of this
command is:
<synopsis>
pg_dump <replaceable class="parameter">dbname</replaceable> > <replaceable class="parameter">outfile</replaceable>
</synopsis>
- As you see, <application>pg_dump</> writes its result to the
+ As you see, <application>pg_dump</application> writes its result to the
standard output. We will see below how this can be useful.
- While the above command creates a text file, <application>pg_dump</>
+ While the above command creates a text file, <application>pg_dump</application>
can create files in other formats that allow for parallelism and more
fine-grained control of object restoration.
</para>
<para>
- <application>pg_dump</> is a regular <productname>PostgreSQL</>
+ <application>pg_dump</application> is a regular <productname>PostgreSQL</productname>
client application (albeit a particularly clever one). This means
that you can perform this backup procedure from any remote host that has
- access to the database. But remember that <application>pg_dump</>
+ access to the database. But remember that <application>pg_dump</application>
does not operate with special permissions. In particular, it must
have read access to all tables that you want to back up, so in order
to back up the entire database you almost always have to run it as a
</para>
<para>
- To specify which database server <application>pg_dump</> should
+ To specify which database server <application>pg_dump</application> should
contact, use the command line options <option>-h
- <replaceable>host</></> and <option>-p <replaceable>port</></>. The
+ <replaceable>host</replaceable></option> and <option>-p <replaceable>port</replaceable></option>. The
default host is the local host or whatever your
<envar>PGHOST</envar> environment variable specifies. Similarly,
the default port is indicated by the <envar>PGPORT</envar>
</para>
<para>
- Like any other <productname>PostgreSQL</> client application,
- <application>pg_dump</> will by default connect with the database
+ Like any other <productname>PostgreSQL</productname> client application,
+ <application>pg_dump</application> will by default connect with the database
user name that is equal to the current operating system user name. To override
this, either specify the <option>-U</option> option or set the
environment variable <envar>PGUSER</envar>. Remember that
- <application>pg_dump</> connections are subject to the normal
+ <application>pg_dump</application> connections are subject to the normal
client authentication mechanisms (which are described in <xref
linkend="client-authentication">).
</para>
<para>
- An important advantage of <application>pg_dump</> over the other backup
- methods described later is that <application>pg_dump</>'s output can
- generally be re-loaded into newer versions of <productname>PostgreSQL</>,
+ An important advantage of <application>pg_dump</application> over the other backup
+ methods described later is that <application>pg_dump</application>'s output can
+ generally be re-loaded into newer versions of <productname>PostgreSQL</productname>,
whereas file-level backups and continuous archiving are both extremely
- server-version-specific. <application>pg_dump</> is also the only method
+ server-version-specific. <application>pg_dump</application> is also the only method
that will work when transferring a database to a different machine
architecture, such as going from a 32-bit to a 64-bit server.
</para>
<para>
- Dumps created by <application>pg_dump</> are internally consistent,
+ Dumps created by <application>pg_dump</application> are internally consistent,
meaning, the dump represents a snapshot of the database at the time
- <application>pg_dump</> began running. <application>pg_dump</> does not
+ <application>pg_dump</application> began running. <application>pg_dump</application> does not
block other operations on the database while it is working.
(Exceptions are those operations that need to operate with an
exclusive lock, such as most forms of <command>ALTER TABLE</command>.)
<title>Restoring the Dump</title>
<para>
- Text files created by <application>pg_dump</> are intended to
+ Text files created by <application>pg_dump</application> are intended to
be read in by the <application>psql</application> program. The
general command form to restore a dump is
<synopsis>
psql <replaceable class="parameter">dbname</replaceable> < <replaceable class="parameter">infile</replaceable>
</synopsis>
where <replaceable class="parameter">infile</replaceable> is the
- file output by the <application>pg_dump</> command. The database <replaceable
+ file output by the <application>pg_dump</application> command. The database <replaceable
class="parameter">dbname</replaceable> will not be created by this
- command, so you must create it yourself from <literal>template0</>
- before executing <application>psql</> (e.g., with
+ command, so you must create it yourself from <literal>template0</literal>
+ before executing <application>psql</application> (e.g., with
<literal>createdb -T template0 <replaceable
- class="parameter">dbname</></literal>). <application>psql</>
- supports options similar to <application>pg_dump</> for specifying
+ class="parameter">dbname</replaceable></literal>). <application>psql</application>
+ supports options similar to <application>pg_dump</application> for specifying
the database server to connect to and the user name to use. See
the <xref linkend="app-psql"> reference page for more information.
Non-text file dumps are restored using the <xref
</para>
<para>
- By default, the <application>psql</> script will continue to
+ By default, the <application>psql</application> script will continue to
execute after an SQL error is encountered. You might wish to run
<application>psql</application> with
- the <literal>ON_ERROR_STOP</> variable set to alter that
+ the <literal>ON_ERROR_STOP</literal> variable set to alter that
behavior and have <application>psql</application> exit with an
exit status of 3 if an SQL error occurs:
<programlisting>
Alternatively, you can specify that the whole dump should be
restored as a single transaction, so the restore is either fully
completed or fully rolled back. This mode can be specified by
- passing the <option>-1</> or <option>--single-transaction</>
- command-line options to <application>psql</>. When using this
+ passing the <option>-1</option> or <option>--single-transaction</option>
+ command-line options to <application>psql</application>. When using this
mode, be aware that even a minor error can rollback a
restore that has already run for many hours. However, that might
still be preferable to manually cleaning up a complex database
</para>
<para>
- The ability of <application>pg_dump</> and <application>psql</> to
+ The ability of <application>pg_dump</application> and <application>psql</application> to
write to or read from pipes makes it possible to dump a database
directly from one server to another, for example:
<programlisting>
-pg_dump -h <replaceable>host1</> <replaceable>dbname</> | psql -h <replaceable>host2</> <replaceable>dbname</>
+pg_dump -h <replaceable>host1</replaceable> <replaceable>dbname</replaceable> | psql -h <replaceable>host2</replaceable> <replaceable>dbname</replaceable>
</programlisting>
</para>
<important>
<para>
- The dumps produced by <application>pg_dump</> are relative to
- <literal>template0</>. This means that any languages, procedures,
- etc. added via <literal>template1</> will also be dumped by
- <application>pg_dump</>. As a result, when restoring, if you are
- using a customized <literal>template1</>, you must create the
- empty database from <literal>template0</>, as in the example
+ The dumps produced by <application>pg_dump</application> are relative to
+ <literal>template0</literal>. This means that any languages, procedures,
+ etc. added via <literal>template1</literal> will also be dumped by
+ <application>pg_dump</application>. As a result, when restoring, if you are
+ using a customized <literal>template1</literal>, you must create the
+ empty database from <literal>template0</literal>, as in the example
above.
</para>
</important>
see <xref linkend="vacuum-for-statistics">
and <xref linkend="autovacuum"> for more information.
For more advice on how to load large amounts of data
- into <productname>PostgreSQL</> efficiently, refer to <xref
+ into <productname>PostgreSQL</productname> efficiently, refer to <xref
linkend="populate">.
</para>
</sect2>
<sect2 id="backup-dump-all">
- <title>Using <application>pg_dumpall</></title>
+ <title>Using <application>pg_dumpall</application></title>
<para>
- <application>pg_dump</> dumps only a single database at a time,
+ <application>pg_dump</application> dumps only a single database at a time,
and it does not dump information about roles or tablespaces
(because those are cluster-wide rather than per-database).
To support convenient dumping of the entire contents of a database
cluster, the <xref linkend="app-pg-dumpall"> program is provided.
- <application>pg_dumpall</> backs up each database in a given
+ <application>pg_dumpall</application> backs up each database in a given
cluster, and also preserves cluster-wide data such as role and
tablespace definitions. The basic usage of this command is:
<synopsis>
-pg_dumpall > <replaceable>outfile</>
+pg_dumpall > <replaceable>outfile</replaceable>
</synopsis>
- The resulting dump can be restored with <application>psql</>:
+ The resulting dump can be restored with <application>psql</application>:
<synopsis>
psql -f <replaceable class="parameter">infile</replaceable> postgres
</synopsis>
(Actually, you can specify any existing database name to start from,
- but if you are loading into an empty cluster then <literal>postgres</>
+ but if you are loading into an empty cluster then <literal>postgres</literal>
should usually be used.) It is always necessary to have
- database superuser access when restoring a <application>pg_dumpall</>
+ database superuser access when restoring a <application>pg_dumpall</application>
dump, as that is required to restore the role and tablespace information.
If you use tablespaces, make sure that the tablespace paths in the
dump are appropriate for the new installation.
</para>
<para>
- <application>pg_dumpall</> works by emitting commands to re-create
+ <application>pg_dumpall</application> works by emitting commands to re-create
roles, tablespaces, and empty databases, then invoking
- <application>pg_dump</> for each database. This means that while
+ <application>pg_dump</application> for each database. This means that while
each database will be internally consistent, the snapshots of
different databases are not synchronized.
</para>
<para>
Cluster-wide data can be dumped alone using the
- <application>pg_dumpall</> <option>--globals-only</> option.
+ <application>pg_dumpall</application> <option>--globals-only</option> option.
This is necessary to fully backup the cluster if running the
- <application>pg_dump</> command on individual databases.
+ <application>pg_dump</application> command on individual databases.
</para>
</sect2>
<para>
Some operating systems have maximum file size limits that cause
- problems when creating large <application>pg_dump</> output files.
- Fortunately, <application>pg_dump</> can write to the standard
+ problems when creating large <application>pg_dump</application> output files.
+ Fortunately, <application>pg_dump</application> can write to the standard
output, so you can use standard Unix tools to work around this
potential problem. There are several possible methods:
</para>
</formalpara>
<formalpara>
- <title>Use <command>split</>.</title>
+ <title>Use <command>split</command>.</title>
<para>
The <command>split</command> command
allows you to split the output into smaller files that are
</formalpara>
<formalpara>
- <title>Use <application>pg_dump</>'s custom dump format.</title>
+ <title>Use <application>pg_dump</application>'s custom dump format.</title>
<para>
If <productname>PostgreSQL</productname> was built on a system with the
- <application>zlib</> compression library installed, the custom dump
+ <application>zlib</application> compression library installed, the custom dump
format will compress data as it writes it to the output file. This will
produce dump file sizes similar to using <command>gzip</command>, but it
has the added advantage that tables can be restored selectively. The
pg_dump -Fc <replaceable class="parameter">dbname</replaceable> > <replaceable class="parameter">filename</replaceable>
</programlisting>
- A custom-format dump is not a script for <application>psql</>, but
- instead must be restored with <application>pg_restore</>, for example:
+ A custom-format dump is not a script for <application>psql</application>, but
+ instead must be restored with <application>pg_restore</application>, for example:
<programlisting>
pg_restore -d <replaceable class="parameter">dbname</replaceable> <replaceable class="parameter">filename</replaceable>
</formalpara>
<para>
- For very large databases, you might need to combine <command>split</>
+ For very large databases, you might need to combine <command>split</command>
with one of the other two approaches.
</para>
<formalpara>
- <title>Use <application>pg_dump</>'s parallel dump feature.</title>
+ <title>Use <application>pg_dump</application>'s parallel dump feature.</title>
<para>
To speed up the dump of a large database, you can use
<application>pg_dump</application>'s parallel mode. This will dump
<para>
An alternative backup strategy is to directly copy the files that
- <productname>PostgreSQL</> uses to store the data in the database;
+ <productname>PostgreSQL</productname> uses to store the data in the database;
<xref linkend="creating-cluster"> explains where these files
are located. You can use whatever method you prefer
for doing file system backups; for example:
<para>
There are two restrictions, however, which make this method
- impractical, or at least inferior to the <application>pg_dump</>
+ impractical, or at least inferior to the <application>pg_dump</application>
method:
<orderedlist>
<listitem>
<para>
- The database server <emphasis>must</> be shut down in order to
+ The database server <emphasis>must</emphasis> be shut down in order to
get a usable backup. Half-way measures such as disallowing all
connections will <emphasis>not</emphasis> work
(in part because <command>tar</command> and similar tools do not take
If you have dug into the details of the file system layout of the
database, you might be tempted to try to back up or restore only certain
individual tables or databases from their respective files or
- directories. This will <emphasis>not</> work because the
+ directories. This will <emphasis>not</emphasis> work because the
information contained in these files is not usable without
the commit log files,
<filename>pg_xact/*</filename>, which contain the commit status of
<quote>consistent snapshot</quote> of the data directory, if the
file system supports that functionality (and you are willing to
trust that it is implemented correctly). The typical procedure is
- to make a <quote>frozen snapshot</> of the volume containing the
+ to make a <quote>frozen snapshot</quote> of the volume containing the
database, then copy the whole data directory (not just parts, see
above) from the snapshot to a backup device, then release the frozen
snapshot. This will work even while the database server is running.
the volumes. For example, if your data files and WAL log are on different
disks, or if tablespaces are on different file systems, it might
not be possible to use snapshot backup because the snapshots
- <emphasis>must</> be simultaneous.
+ <emphasis>must</emphasis> be simultaneous.
Read your file system documentation very carefully before trusting
the consistent-snapshot technique in such situations.
</para>
</para>
<para>
- Another option is to use <application>rsync</> to perform a file
- system backup. This is done by first running <application>rsync</>
+ Another option is to use <application>rsync</application> to perform a file
+ system backup. This is done by first running <application>rsync</application>
while the database server is running, then shutting down the database
- server long enough to do an <command>rsync --checksum</>.
- (<option>--checksum</> is necessary because <command>rsync</> only
+ server long enough to do an <command>rsync --checksum</command>.
+ (<option>--checksum</option> is necessary because <command>rsync</command> only
has file modification-time granularity of one second.) The
- second <application>rsync</> will be quicker than the first,
+ second <application>rsync</application> will be quicker than the first,
because it has relatively little data to transfer, and the end result
will be consistent because the server was down. This method
allows a file system backup to be performed with minimal downtime.
</indexterm>
<para>
- At all times, <productname>PostgreSQL</> maintains a
- <firstterm>write ahead log</> (WAL) in the <filename>pg_wal/</>
+ At all times, <productname>PostgreSQL</productname> maintains a
+ <firstterm>write ahead log</firstterm> (WAL) in the <filename>pg_wal/</filename>
subdirectory of the cluster's data directory. The log records
every change made to the database's data files. This log exists
primarily for crash-safety purposes: if the system crashes, the
- database can be restored to consistency by <quote>replaying</> the
+ database can be restored to consistency by <quote>replaying</quote> the
log entries made since the last checkpoint. However, the existence
of the log makes it possible to use a third strategy for backing up
databases: we can combine a file-system-level backup with backup of
Any internal inconsistency in the backup will be corrected by log
replay (this is not significantly different from what happens during
crash recovery). So we do not need a file system snapshot capability,
- just <application>tar</> or a similar archiving tool.
+ just <application>tar</application> or a similar archiving tool.
</para>
</listitem>
<listitem>
It is not necessary to replay the WAL entries all the
way to the end. We could stop the replay at any point and have a
consistent snapshot of the database as it was at that time. Thus,
- this technique supports <firstterm>point-in-time recovery</>: it is
+ this technique supports <firstterm>point-in-time recovery</firstterm>: it is
possible to restore the database to its state at any time since your base
backup was taken.
</para>
<para>
If we continuously feed the series of WAL files to another
machine that has been loaded with the same base backup file, we
- have a <firstterm>warm standby</> system: at any point we can bring up
+ have a <firstterm>warm standby</firstterm> system: at any point we can bring up
the second machine and it will have a nearly-current copy of the
database.
</para>
<application>pg_dump</application> and
<application>pg_dumpall</application> do not produce file-system-level
backups and cannot be used as part of a continuous-archiving solution.
- Such dumps are <emphasis>logical</> and do not contain enough
+ Such dumps are <emphasis>logical</emphasis> and do not contain enough
information to be used by WAL replay.
</para>
</note>
<para>
To recover successfully using continuous archiving (also called
- <quote>online backup</> by many database vendors), you need a continuous
+ <quote>online backup</quote> by many database vendors), you need a continuous
sequence of archived WAL files that extends back at least as far as the
start time of your backup. So to get started, you should set up and test
- your procedure for archiving WAL files <emphasis>before</> you take your
+ your procedure for archiving WAL files <emphasis>before</emphasis> you take your
first base backup. Accordingly, we first discuss the mechanics of
archiving WAL files.
</para>
<title>Setting Up WAL Archiving</title>
<para>
- In an abstract sense, a running <productname>PostgreSQL</> system
+ In an abstract sense, a running <productname>PostgreSQL</productname> system
produces an indefinitely long sequence of WAL records. The system
physically divides this sequence into WAL <firstterm>segment
- files</>, which are normally 16MB apiece (although the segment size
- can be altered during <application>initdb</>). The segment
+ files</firstterm>, which are normally 16MB apiece (although the segment size
+ can be altered during <application>initdb</application>). The segment
files are given numeric names that reflect their position in the
abstract WAL sequence. When not using WAL archiving, the system
normally creates just a few segment files and then
- <quote>recycles</> them by renaming no-longer-needed segment files
+ <quote>recycles</quote> them by renaming no-longer-needed segment files
to higher segment numbers. It's assumed that segment files whose
contents precede the checkpoint-before-last are no longer of
interest and can be recycled.
file once it is filled, and save that data somewhere before the segment
file is recycled for reuse. Depending on the application and the
available hardware, there could be many different ways of <quote>saving
- the data somewhere</>: we could copy the segment files to an NFS-mounted
+ the data somewhere</quote>: we could copy the segment files to an NFS-mounted
directory on another machine, write them onto a tape drive (ensuring that
you have a way of identifying the original name of each file), or batch
them together and burn them onto CDs, or something else entirely. To
provide the database administrator with flexibility,
- <productname>PostgreSQL</> tries not to make any assumptions about how
- the archiving will be done. Instead, <productname>PostgreSQL</> lets
+ <productname>PostgreSQL</productname> tries not to make any assumptions about how
+ the archiving will be done. Instead, <productname>PostgreSQL</productname> lets
the administrator specify a shell command to be executed to copy a
completed segment file to wherever it needs to go. The command could be
- as simple as a <literal>cp</>, or it could invoke a complex shell
+ as simple as a <literal>cp</literal>, or it could invoke a complex shell
script — it's all up to you.
</para>
<para>
To enable WAL archiving, set the <xref linkend="guc-wal-level">
- configuration parameter to <literal>replica</> or higher,
- <xref linkend="guc-archive-mode"> to <literal>on</>,
+ configuration parameter to <literal>replica</literal> or higher,
+ <xref linkend="guc-archive-mode"> to <literal>on</literal>,
and specify the shell command to use in the <xref
linkend="guc-archive-command"> configuration parameter. In practice
these settings will always be placed in the
<filename>postgresql.conf</filename> file.
- In <varname>archive_command</>,
- <literal>%p</> is replaced by the path name of the file to
- archive, while <literal>%f</> is replaced by only the file name.
+ In <varname>archive_command</varname>,
+ <literal>%p</literal> is replaced by the path name of the file to
+ archive, while <literal>%f</literal> is replaced by only the file name.
(The path name is relative to the current working directory,
i.e., the cluster's data directory.)
- Use <literal>%%</> if you need to embed an actual <literal>%</>
+ Use <literal>%%</literal> if you need to embed an actual <literal>%</literal>
character in the command. The simplest useful command is something
like:
<programlisting>
archive_command = 'copy "%p" "C:\\server\\archivedir\\%f"' # Windows
</programlisting>
which will copy archivable WAL segments to the directory
- <filename>/mnt/server/archivedir</>. (This is an example, not a
+ <filename>/mnt/server/archivedir</filename>. (This is an example, not a
recommendation, and might not work on all platforms.) After the
- <literal>%p</> and <literal>%f</> parameters have been replaced,
+ <literal>%p</literal> and <literal>%f</literal> parameters have been replaced,
the actual command executed might look like this:
<programlisting>
test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/00000001000000A900000065 /mnt/server/archivedir/00000001000000A900000065
<para>
The archive command will be executed under the ownership of the same
- user that the <productname>PostgreSQL</> server is running as. Since
+ user that the <productname>PostgreSQL</productname> server is running as. Since
the series of WAL files being archived contains effectively everything
in your database, you will want to be sure that the archived data is
protected from prying eyes; for example, archive into a directory that
<para>
It is important that the archive command return zero exit status if and
only if it succeeds. Upon getting a zero result,
- <productname>PostgreSQL</> will assume that the file has been
+ <productname>PostgreSQL</productname> will assume that the file has been
successfully archived, and will remove or recycle it. However, a nonzero
- status tells <productname>PostgreSQL</> that the file was not archived;
+ status tells <productname>PostgreSQL</productname> that the file was not archived;
it will try again periodically until it succeeds.
</para>
<para>
It is advisable to test your proposed archive command to ensure that it
indeed does not overwrite an existing file, <emphasis>and that it returns
- nonzero status in this case</>.
+ nonzero status in this case</emphasis>.
The example command above for Unix ensures this by including a separate
- <command>test</> step. On some Unix platforms, <command>cp</> has
- switches such as <option>-i</> that can be used to do the same thing
+ <command>test</command> step. On some Unix platforms, <command>cp</command> has
+ switches such as <option>-i</option> that can be used to do the same thing
less verbosely, but you should not rely on these without verifying that
- the right exit status is returned. (In particular, GNU <command>cp</>
- will return status zero when <option>-i</> is used and the target file
- already exists, which is <emphasis>not</> the desired behavior.)
+ the right exit status is returned. (In particular, GNU <command>cp</command>
+ will return status zero when <option>-i</option> is used and the target file
+ already exists, which is <emphasis>not</emphasis> the desired behavior.)
</para>
<para>
fills, nothing further can be archived until the tape is swapped.
You should ensure that any error condition or request to a human operator
is reported appropriately so that the situation can be
- resolved reasonably quickly. The <filename>pg_wal/</> directory will
+ resolved reasonably quickly. The <filename>pg_wal/</filename> directory will
continue to fill with WAL segment files until the situation is resolved.
- (If the file system containing <filename>pg_wal/</> fills up,
- <productname>PostgreSQL</> will do a PANIC shutdown. No committed
+ (If the file system containing <filename>pg_wal/</filename> fills up,
+ <productname>PostgreSQL</productname> will do a PANIC shutdown. No committed
transactions will be lost, but the database will remain offline until
you free some space.)
</para>
operation continues even if the archiving process falls a little behind.
If archiving falls significantly behind, this will increase the amount of
data that would be lost in the event of a disaster. It will also mean that
- the <filename>pg_wal/</> directory will contain large numbers of
+ the <filename>pg_wal/</filename> directory will contain large numbers of
not-yet-archived segment files, which could eventually exceed available
disk space. You are advised to monitor the archiving process to ensure that
it is working as you intend.
In writing your archive command, you should assume that the file names to
be archived can be up to 64 characters long and can contain any
combination of ASCII letters, digits, and dots. It is not necessary to
- preserve the original relative path (<literal>%p</>) but it is necessary to
- preserve the file name (<literal>%f</>).
+ preserve the original relative path (<literal>%p</literal>) but it is necessary to
+ preserve the file name (<literal>%f</literal>).
</para>
<para>
Note that although WAL archiving will allow you to restore any
- modifications made to the data in your <productname>PostgreSQL</> database,
+ modifications made to the data in your <productname>PostgreSQL</productname> database,
it will not restore changes made to configuration files (that is,
- <filename>postgresql.conf</>, <filename>pg_hba.conf</> and
- <filename>pg_ident.conf</>), since those are edited manually rather
+ <filename>postgresql.conf</filename>, <filename>pg_hba.conf</filename> and
+ <filename>pg_ident.conf</filename>), since those are edited manually rather
than through SQL operations.
You might wish to keep the configuration files in a location that will
be backed up by your regular file system backup procedures. See
to a new WAL segment file at least that often. Note that archived
files that are archived early due to a forced switch are still the same
length as completely full files. It is therefore unwise to set a very
- short <varname>archive_timeout</> — it will bloat your archive
- storage. <varname>archive_timeout</> settings of a minute or so are
+ short <varname>archive_timeout</varname> — it will bloat your archive
+ storage. <varname>archive_timeout</varname> settings of a minute or so are
usually reasonable.
</para>
<para>
Also, you can force a segment switch manually with
- <function>pg_switch_wal</> if you want to ensure that a
+ <function>pg_switch_wal</function> if you want to ensure that a
just-finished transaction is archived as soon as possible. Other utility
functions related to WAL management are listed in <xref
linkend="functions-admin-backup-table">.
</para>
<para>
- When <varname>wal_level</> is <literal>minimal</> some SQL commands
+ When <varname>wal_level</varname> is <literal>minimal</literal> some SQL commands
are optimized to avoid WAL logging, as described in <xref
linkend="populate-pitr">. If archiving or streaming replication were
turned on during execution of one of these statements, WAL would not
contain enough information for archive recovery. (Crash recovery is
- unaffected.) For this reason, <varname>wal_level</> can only be changed at
- server start. However, <varname>archive_command</> can be changed with a
+ unaffected.) For this reason, <varname>wal_level</varname> can only be changed at
+ server start. However, <varname>archive_command</varname> can be changed with a
configuration file reload. If you wish to temporarily stop archiving,
- one way to do it is to set <varname>archive_command</> to the empty
- string (<literal>''</>).
- This will cause WAL files to accumulate in <filename>pg_wal/</> until a
- working <varname>archive_command</> is re-established.
+ one way to do it is to set <varname>archive_command</varname> to the empty
+ string (<literal>''</literal>).
+ This will cause WAL files to accumulate in <filename>pg_wal/</filename> until a
+ working <varname>archive_command</varname> is re-established.
</para>
</sect2>
<para>
It is not necessary to be concerned about the amount of time it takes
to make a base backup. However, if you normally run the
- server with <varname>full_page_writes</> disabled, you might notice a drop
- in performance while the backup runs since <varname>full_page_writes</> is
+ server with <varname>full_page_writes</varname> disabled, you might notice a drop
+ in performance while the backup runs since <varname>full_page_writes</varname> is
effectively forced on during backup mode.
</para>
To make use of the backup, you will need to keep all the WAL
segment files generated during and after the file system backup.
To aid you in doing this, the base backup process
- creates a <firstterm>backup history file</> that is immediately
+ creates a <firstterm>backup history file</firstterm> that is immediately
stored into the WAL archive area. This file is named after the first
WAL segment file that you need for the file system backup.
For example, if the starting WAL file is
- <literal>0000000100001234000055CD</> the backup history file will be
+ <literal>0000000100001234000055CD</literal> the backup history file will be
named something like
- <literal>0000000100001234000055CD.007C9330.backup</>. (The second
+ <literal>0000000100001234000055CD.007C9330.backup</literal>. (The second
part of the file name stands for an exact position within the WAL
file, and can ordinarily be ignored.) Once you have safely archived
the file system backup and the WAL segment files used during the
<programlisting>
SELECT pg_start_backup('label', false, false);
</programlisting>
- where <literal>label</> is any string you want to use to uniquely
+ where <literal>label</literal> is any string you want to use to uniquely
identify this backup operation. The connection
- calling <function>pg_start_backup</> must be maintained until the end of
+ calling <function>pg_start_backup</function> must be maintained until the end of
the backup, or the backup will be automatically aborted.
</para>
<para>
- By default, <function>pg_start_backup</> can take a long time to finish.
+ By default, <function>pg_start_backup</function> can take a long time to finish.
This is because it performs a checkpoint, and the I/O
required for the checkpoint will be spread out over a significant
period of time, by default half your inter-checkpoint interval
<xref linkend="guc-checkpoint-completion-target">). This is
usually what you want, because it minimizes the impact on query
processing. If you want to start the backup as soon as
- possible, change the second parameter to <literal>true</>, which will
+ possible, change the second parameter to <literal>true</literal>, which will
issue an immediate checkpoint using as much I/O as available.
</para>
<para>
- The third parameter being <literal>false</> tells
- <function>pg_start_backup</> to initiate a non-exclusive base backup.
+ The third parameter being <literal>false</literal> tells
+ <function>pg_start_backup</function> to initiate a non-exclusive base backup.
</para>
</listitem>
<listitem>
<para>
Perform the backup, using any convenient file-system-backup tool
- such as <application>tar</> or <application>cpio</> (not
+ such as <application>tar</application> or <application>cpio</application> (not
<application>pg_dump</application> or
<application>pg_dumpall</application>). It is neither
necessary nor desirable to stop normal operation of the database
ready to archive.
</para>
<para>
- The <function>pg_stop_backup</> will return one row with three
+ The <function>pg_stop_backup</function> will return one row with three
values. The second of these fields should be written to a file named
- <filename>backup_label</> in the root directory of the backup. The
+ <filename>backup_label</filename> in the root directory of the backup. The
third field should be written to a file named
- <filename>tablespace_map</> unless the field is empty. These files are
+ <filename>tablespace_map</filename> unless the field is empty. These files are
vital to the backup working, and must be written without modification.
</para>
</listitem>
<listitem>
<para>
Once the WAL segment files active during the backup are archived, you are
- done. The file identified by <function>pg_stop_backup</>'s first return
+ done. The file identified by <function>pg_stop_backup</function>'s first return
value is the last segment that is required to form a complete set of
- backup files. On a primary, if <varname>archive_mode</> is enabled and the
- <literal>wait_for_archive</> parameter is <literal>true</>,
- <function>pg_stop_backup</> does not return until the last segment has
+ backup files. On a primary, if <varname>archive_mode</varname> is enabled and the
+ <literal>wait_for_archive</literal> parameter is <literal>true</literal>,
+ <function>pg_stop_backup</function> does not return until the last segment has
been archived.
- On a standby, <varname>archive_mode</> must be <literal>always</> in order
- for <function>pg_stop_backup</> to wait.
+ On a standby, <varname>archive_mode</varname> must be <literal>always</literal> in order
+ for <function>pg_stop_backup</function> to wait.
Archiving of these files happens automatically since you have
- already configured <varname>archive_command</>. In most cases this
+ already configured <varname>archive_command</varname>. In most cases this
happens quickly, but you are advised to monitor your archive
system to ensure there are no delays.
If the archive process has fallen behind
because of failures of the archive command, it will keep retrying
until the archive succeeds and the backup is complete.
If you wish to place a time limit on the execution of
- <function>pg_stop_backup</>, set an appropriate
+ <function>pg_stop_backup</function>, set an appropriate
<varname>statement_timeout</varname> value, but make note that if
- <function>pg_stop_backup</> terminates because of this your backup
+ <function>pg_stop_backup</function> terminates because of this your backup
may not be valid.
</para>
<para>
If the backup process monitors and ensures that all WAL segment files
required for the backup are successfully archived then the
- <literal>wait_for_archive</> parameter (which defaults to true) can be set
+ <literal>wait_for_archive</literal> parameter (which defaults to true) can be set
to false to have
- <function>pg_stop_backup</> return as soon as the stop backup record is
- written to the WAL. By default, <function>pg_stop_backup</> will wait
+ <function>pg_stop_backup</function> return as soon as the stop backup record is
+ written to the WAL. By default, <function>pg_stop_backup</function> will wait
until all WAL has been archived, which can take some time. This option
must be used with caution: if WAL archiving is not monitored correctly
then the backup might not include all of the WAL files and will
The process for an exclusive backup is mostly the same as for a
non-exclusive one, but it differs in a few key steps. This type of backup
can only be taken on a primary and does not allow concurrent backups.
- Prior to <productname>PostgreSQL</> 9.6, this
+ Prior to <productname>PostgreSQL</productname> 9.6, this
was the only low-level method available, but it is now recommended that
all users upgrade their scripts to use non-exclusive backups if possible.
</para>
<programlisting>
SELECT pg_start_backup('label');
</programlisting>
- where <literal>label</> is any string you want to use to uniquely
+ where <literal>label</literal> is any string you want to use to uniquely
identify this backup operation.
- <function>pg_start_backup</> creates a <firstterm>backup label</> file,
- called <filename>backup_label</>, in the cluster directory with
+ <function>pg_start_backup</function> creates a <firstterm>backup label</firstterm> file,
+ called <filename>backup_label</filename>, in the cluster directory with
information about your backup, including the start time and label string.
- The function also creates a <firstterm>tablespace map</> file,
- called <filename>tablespace_map</>, in the cluster directory with
- information about tablespace symbolic links in <filename>pg_tblspc/</> if
+ The function also creates a <firstterm>tablespace map</firstterm> file,
+ called <filename>tablespace_map</filename>, in the cluster directory with
+ information about tablespace symbolic links in <filename>pg_tblspc/</filename> if
one or more such link is present. Both files are critical to the
integrity of the backup, should you need to restore from it.
</para>
<para>
- By default, <function>pg_start_backup</> can take a long time to finish.
+ By default, <function>pg_start_backup</function> can take a long time to finish.
This is because it performs a checkpoint, and the I/O
required for the checkpoint will be spread out over a significant
period of time, by default half your inter-checkpoint interval
<listitem>
<para>
Perform the backup, using any convenient file-system-backup tool
- such as <application>tar</> or <application>cpio</> (not
+ such as <application>tar</application> or <application>cpio</application> (not
<application>pg_dump</application> or
<application>pg_dumpall</application>). It is neither
necessary nor desirable to stop normal operation of the database
</para>
<para>
Note that if the server crashes during the backup it may not be
- possible to restart until the <literal>backup_label</> file has been
+ possible to restart until the <literal>backup_label</literal> file has been
manually deleted from the <envar>PGDATA</envar> directory.
</para>
</listitem>
<listitem>
<para>
Once the WAL segment files active during the backup are archived, you are
- done. The file identified by <function>pg_stop_backup</>'s result is
+ done. The file identified by <function>pg_stop_backup</function>'s result is
the last segment that is required to form a complete set of backup files.
- If <varname>archive_mode</> is enabled,
- <function>pg_stop_backup</> does not return until the last segment has
+ If <varname>archive_mode</varname> is enabled,
+ <function>pg_stop_backup</function> does not return until the last segment has
been archived.
Archiving of these files happens automatically since you have
- already configured <varname>archive_command</>. In most cases this
+ already configured <varname>archive_command</varname>. In most cases this
happens quickly, but you are advised to monitor your archive
system to ensure there are no delays.
If the archive process has fallen behind
because of failures of the archive command, it will keep retrying
until the archive succeeds and the backup is complete.
If you wish to place a time limit on the execution of
- <function>pg_stop_backup</>, set an appropriate
+ <function>pg_stop_backup</function>, set an appropriate
<varname>statement_timeout</varname> value, but make note that if
- <function>pg_stop_backup</> terminates because of this your backup
+ <function>pg_stop_backup</function> terminates because of this your backup
may not be valid.
</para>
</listitem>
When taking a base backup of an active database, this situation is normal
and not an error. However, you need to ensure that you can distinguish
complaints of this sort from real errors. For example, some versions
- of <application>rsync</> return a separate exit code for
- <quote>vanished source files</>, and you can write a driver script to
+ of <application>rsync</application> return a separate exit code for
+ <quote>vanished source files</quote>, and you can write a driver script to
accept this exit code as a non-error case. Also, some versions of
- GNU <application>tar</> return an error code indistinguishable from
- a fatal error if a file was truncated while <application>tar</> was
- copying it. Fortunately, GNU <application>tar</> versions 1.16 and
+ GNU <application>tar</application> return an error code indistinguishable from
+ a fatal error if a file was truncated while <application>tar</application> was
+ copying it. Fortunately, GNU <application>tar</application> versions 1.16 and
later exit with 1 if a file was changed during the backup,
- and 2 for other errors. With GNU <application>tar</> version 1.23 and
+ and 2 for other errors. With GNU <application>tar</application> version 1.23 and
later, you can use the warning options <literal>--warning=no-file-changed
--warning=no-file-removed</literal> to hide the related warning messages.
</para>
<para>
Be certain that your backup includes all of the files under
- the database cluster directory (e.g., <filename>/usr/local/pgsql/data</>).
+ the database cluster directory (e.g., <filename>/usr/local/pgsql/data</filename>).
If you are using tablespaces that do not reside underneath this directory,
be careful to include them as well (and be sure that your backup
archives symbolic links as links, otherwise the restore will corrupt
<para>
You should, however, omit from the backup the files within the
- cluster's <filename>pg_wal/</> subdirectory. This
+ cluster's <filename>pg_wal/</filename> subdirectory. This
slight adjustment is worthwhile because it reduces the risk
of mistakes when restoring. This is easy to arrange if
- <filename>pg_wal/</> is a symbolic link pointing to someplace outside
+ <filename>pg_wal/</filename> is a symbolic link pointing to someplace outside
the cluster directory, which is a common setup anyway for performance
- reasons. You might also want to exclude <filename>postmaster.pid</>
- and <filename>postmaster.opts</>, which record information
- about the running <application>postmaster</>, not about the
- <application>postmaster</> which will eventually use this backup.
- (These files can confuse <application>pg_ctl</>.)
+ reasons. You might also want to exclude <filename>postmaster.pid</filename>
+ and <filename>postmaster.opts</filename>, which record information
+ about the running <application>postmaster</application>, not about the
+ <application>postmaster</application> which will eventually use this backup.
+ (These files can confuse <application>pg_ctl</application>.)
</para>
<para>
It is often a good idea to also omit from the backup the files
- within the cluster's <filename>pg_replslot/</> directory, so that
+ within the cluster's <filename>pg_replslot/</filename> directory, so that
replication slots that exist on the master do not become part of the
backup. Otherwise, the subsequent use of the backup to create a standby
may result in indefinite retention of WAL files on the standby, and
</para>
<para>
- The contents of the directories <filename>pg_dynshmem/</>,
- <filename>pg_notify/</>, <filename>pg_serial/</>,
- <filename>pg_snapshots/</>, <filename>pg_stat_tmp/</>,
- and <filename>pg_subtrans/</> (but not the directories themselves) can be
+ The contents of the directories <filename>pg_dynshmem/</filename>,
+ <filename>pg_notify/</filename>, <filename>pg_serial/</filename>,
+ <filename>pg_snapshots/</filename>, <filename>pg_stat_tmp/</filename>,
+ and <filename>pg_subtrans/</filename> (but not the directories themselves) can be
omitted from the backup as they will be initialized on postmaster startup.
If <xref linkend="guc-stats-temp-directory"> is set and is under the data
directory then the contents of that directory can also be omitted.
<para>
The backup label
- file includes the label string you gave to <function>pg_start_backup</>,
- as well as the time at which <function>pg_start_backup</> was run, and
+ file includes the label string you gave to <function>pg_start_backup</function>,
+ as well as the time at which <function>pg_start_backup</function> was run, and
the name of the starting WAL file. In case of confusion it is therefore
possible to look inside a backup file and determine exactly which
backup session the dump file came from. The tablespace map file includes
the symbolic link names as they exist in the directory
- <filename>pg_tblspc/</> and the full path of each symbolic link.
+ <filename>pg_tblspc/</filename> and the full path of each symbolic link.
These files are not merely for your information; their presence and
contents are critical to the proper operation of the system's recovery
process.
<para>
It is also possible to make a backup while the server is
stopped. In this case, you obviously cannot use
- <function>pg_start_backup</> or <function>pg_stop_backup</>, and
+ <function>pg_start_backup</function> or <function>pg_stop_backup</function>, and
you will therefore be left to your own devices to keep track of which
backup is which and how far back the associated WAL files go.
It is generally better to follow the continuous archiving procedure above.
location in case you need them later. Note that this precaution will
require that you have enough free space on your system to hold two
copies of your existing database. If you do not have enough space,
- you should at least save the contents of the cluster's <filename>pg_wal</>
+ you should at least save the contents of the cluster's <filename>pg_wal</filename>
subdirectory, as it might contain logs which
were not archived before the system went down.
</para>
<para>
Restore the database files from your file system backup. Be sure that they
are restored with the right ownership (the database system user, not
- <literal>root</>!) and with the right permissions. If you are using
+ <literal>root</literal>!) and with the right permissions. If you are using
tablespaces,
- you should verify that the symbolic links in <filename>pg_tblspc/</>
+ you should verify that the symbolic links in <filename>pg_tblspc/</filename>
were correctly restored.
</para>
</listitem>
<listitem>
<para>
- Remove any files present in <filename>pg_wal/</>; these came from the
+ Remove any files present in <filename>pg_wal/</filename>; these came from the
file system backup and are therefore probably obsolete rather than current.
- If you didn't archive <filename>pg_wal/</> at all, then recreate
+ If you didn't archive <filename>pg_wal/</filename> at all, then recreate
it with proper permissions,
being careful to ensure that you re-establish it as a symbolic link
if you had it set up that way before.
<listitem>
<para>
If you have unarchived WAL segment files that you saved in step 2,
- copy them into <filename>pg_wal/</>. (It is best to copy them,
+ copy them into <filename>pg_wal/</filename>. (It is best to copy them,
not move them, so you still have the unmodified files if a
problem occurs and you have to start over.)
</para>
</listitem>
<listitem>
<para>
- Create a recovery command file <filename>recovery.conf</> in the cluster
+ Create a recovery command file <filename>recovery.conf</filename> in the cluster
data directory (see <xref linkend="recovery-config">). You might
- also want to temporarily modify <filename>pg_hba.conf</> to prevent
+ also want to temporarily modify <filename>pg_hba.conf</filename> to prevent
ordinary users from connecting until you are sure the recovery was successful.
</para>
</listitem>
recovery be terminated because of an external error, the server can
simply be restarted and it will continue recovery. Upon completion
of the recovery process, the server will rename
- <filename>recovery.conf</> to <filename>recovery.done</> (to prevent
+ <filename>recovery.conf</filename> to <filename>recovery.done</filename> (to prevent
accidentally re-entering recovery mode later) and then
commence normal database operations.
</para>
<para>
Inspect the contents of the database to ensure you have recovered to
the desired state. If not, return to step 1. If all is well,
- allow your users to connect by restoring <filename>pg_hba.conf</> to normal.
+ allow your users to connect by restoring <filename>pg_hba.conf</filename> to normal.
</para>
</listitem>
</orderedlist>
<para>
The key part of all this is to set up a recovery configuration file that
describes how you want to recover and how far the recovery should
- run. You can use <filename>recovery.conf.sample</> (normally
- located in the installation's <filename>share/</> directory) as a
+ run. You can use <filename>recovery.conf.sample</filename> (normally
+ located in the installation's <filename>share/</filename> directory) as a
prototype. The one thing that you absolutely must specify in
- <filename>recovery.conf</> is the <varname>restore_command</>,
- which tells <productname>PostgreSQL</> how to retrieve archived
- WAL file segments. Like the <varname>archive_command</>, this is
- a shell command string. It can contain <literal>%f</>, which is
- replaced by the name of the desired log file, and <literal>%p</>,
+ <filename>recovery.conf</filename> is the <varname>restore_command</varname>,
+ which tells <productname>PostgreSQL</productname> how to retrieve archived
+ WAL file segments. Like the <varname>archive_command</varname>, this is
+ a shell command string. It can contain <literal>%f</literal>, which is
+ replaced by the name of the desired log file, and <literal>%p</literal>,
which is replaced by the path name to copy the log file to.
(The path name is relative to the current working directory,
i.e., the cluster's data directory.)
- Write <literal>%%</> if you need to embed an actual <literal>%</>
+ Write <literal>%%</literal> if you need to embed an actual <literal>%</literal>
character in the command. The simplest useful command is
something like:
<programlisting>
restore_command = 'cp /mnt/server/archivedir/%f %p'
</programlisting>
which will copy previously archived WAL segments from the directory
- <filename>/mnt/server/archivedir</>. Of course, you can use something
+ <filename>/mnt/server/archivedir</filename>. Of course, you can use something
much more complicated, perhaps even a shell script that requests the
operator to mount an appropriate tape.
</para>
<para>
It is important that the command return nonzero exit status on failure.
- The command <emphasis>will</> be called requesting files that are not
+ The command <emphasis>will</emphasis> be called requesting files that are not
present in the archive; it must return nonzero when so asked. This is not
an error condition. An exception is that if the command was terminated by
a signal (other than <systemitem>SIGTERM</systemitem>, which is used as
<para>
Not all of the requested files will be WAL segment
files; you should also expect requests for files with a suffix of
- <literal>.backup</> or <literal>.history</>. Also be aware that
- the base name of the <literal>%p</> path will be different from
- <literal>%f</>; do not expect them to be interchangeable.
+ <literal>.backup</literal> or <literal>.history</literal>. Also be aware that
+ the base name of the <literal>%p</literal> path will be different from
+ <literal>%f</literal>; do not expect them to be interchangeable.
</para>
<para>
WAL segments that cannot be found in the archive will be sought in
- <filename>pg_wal/</>; this allows use of recent un-archived segments.
+ <filename>pg_wal/</filename>; this allows use of recent un-archived segments.
However, segments that are available from the archive will be used in
- preference to files in <filename>pg_wal/</>.
+ preference to files in <filename>pg_wal/</filename>.
</para>
<para>
Normally, recovery will proceed through all available WAL segments,
thereby restoring the database to the current point in time (or as
close as possible given the available WAL segments). Therefore, a normal
- recovery will end with a <quote>file not found</> message, the exact text
+ recovery will end with a <quote>file not found</quote> message, the exact text
of the error message depending upon your choice of
- <varname>restore_command</>. You may also see an error message
+ <varname>restore_command</varname>. You may also see an error message
at the start of recovery for a file named something like
- <filename>00000001.history</>. This is also normal and does not
+ <filename>00000001.history</filename>. This is also normal and does not
indicate a problem in simple recovery situations; see
<xref linkend="backup-timelines"> for discussion.
</para>
<para>
If you want to recover to some previous point in time (say, right before
the junior DBA dropped your main transaction table), just specify the
- required <link linkend="recovery-target-settings">stopping point</link> in <filename>recovery.conf</>. You can specify
- the stop point, known as the <quote>recovery target</>, either by
+ required <link linkend="recovery-target-settings">stopping point</link> in <filename>recovery.conf</filename>. You can specify
+ the stop point, known as the <quote>recovery target</quote>, either by
date/time, named restore point or by completion of a specific transaction
ID. As of this writing only the date/time and named restore point options
are very usable, since there are no tools to help you identify with any
<note>
<para>
The stop point must be after the ending time of the base backup, i.e.,
- the end time of <function>pg_stop_backup</>. You cannot use a base backup
+ the end time of <function>pg_stop_backup</function>. You cannot use a base backup
to recover to a time when that backup was in progress. (To
recover to such a time, you must go back to your previous base backup
and roll forward from there.)
If recovery finds corrupted WAL data, recovery will
halt at that point and the server will not start. In such a case the
recovery process could be re-run from the beginning, specifying a
- <quote>recovery target</> before the point of corruption so that recovery
+ <quote>recovery target</quote> before the point of corruption so that recovery
can complete normally.
If recovery fails for an external reason, such as a system crash or
if the WAL archive has become inaccessible, then the recovery can simply
be restarted and it will restart almost from where it failed.
Recovery restart works much like checkpointing in normal operation:
the server periodically forces all its state to disk, and then updates
- the <filename>pg_control</> file to indicate that the already-processed
+ the <filename>pg_control</filename> file to indicate that the already-processed
WAL data need not be scanned again.
</para>
suppose you dropped a critical table at 5:15PM on Tuesday evening, but
didn't realize your mistake until Wednesday noon.
Unfazed, you get out your backup, restore to the point-in-time 5:14PM
- Tuesday evening, and are up and running. In <emphasis>this</> history of
+ Tuesday evening, and are up and running. In <emphasis>this</emphasis> history of
the database universe, you never dropped the table. But suppose
you later realize this wasn't such a great idea, and would like
to return to sometime Wednesday morning in the original history.
</para>
<para>
- To deal with this problem, <productname>PostgreSQL</> has a notion
- of <firstterm>timelines</>. Whenever an archive recovery completes,
+ To deal with this problem, <productname>PostgreSQL</productname> has a notion
+ of <firstterm>timelines</firstterm>. Whenever an archive recovery completes,
a new timeline is created to identify the series of WAL records
generated after that recovery. The timeline
ID number is part of WAL segment file names so a new timeline does
and so have to do several point-in-time recoveries by trial and error
until you find the best place to branch off from the old history. Without
timelines this process would soon generate an unmanageable mess. With
- timelines, you can recover to <emphasis>any</> prior state, including
+ timelines, you can recover to <emphasis>any</emphasis> prior state, including
states in timeline branches that you abandoned earlier.
</para>
<para>
- Every time a new timeline is created, <productname>PostgreSQL</> creates
- a <quote>timeline history</> file that shows which timeline it branched
+ Every time a new timeline is created, <productname>PostgreSQL</productname> creates
+ a <quote>timeline history</quote> file that shows which timeline it branched
off from and when. These history files are necessary to allow the system
to pick the right WAL segment files when recovering from an archive that
contains multiple timelines. Therefore, they are archived into the WAL
that was current when the base backup was taken. If you wish to recover
into some child timeline (that is, you want to return to some state that
was itself generated after a recovery attempt), you need to specify the
- target timeline ID in <filename>recovery.conf</>. You cannot recover into
+ target timeline ID in <filename>recovery.conf</filename>. You cannot recover into
timelines that branched off earlier than the base backup.
</para>
</sect2>
<title>Standalone Hot Backups</title>
<para>
- It is possible to use <productname>PostgreSQL</>'s backup facilities to
+ It is possible to use <productname>PostgreSQL</productname>'s backup facilities to
produce standalone hot backups. These are backups that cannot be used
for point-in-time recovery, yet are typically much faster to backup and
- restore than <application>pg_dump</> dumps. (They are also much larger
- than <application>pg_dump</> dumps, so in some cases the speed advantage
+ restore than <application>pg_dump</application> dumps. (They are also much larger
+ than <application>pg_dump</application> dumps, so in some cases the speed advantage
might be negated.)
</para>
<para>
As with base backups, the easiest way to produce a standalone
hot backup is to use the <xref linkend="app-pgbasebackup">
- tool. If you include the <literal>-X</> parameter when calling
+ tool. If you include the <literal>-X</literal> parameter when calling
it, all the write-ahead log required to use the backup will be
included in the backup automatically, and no special action is
required to restore the backup.
If more flexibility in copying the backup files is needed, a lower
level process can be used for standalone hot backups as well.
To prepare for low level standalone hot backups, make sure
- <varname>wal_level</> is set to
- <literal>replica</> or higher, <varname>archive_mode</> to
- <literal>on</>, and set up an <varname>archive_command</> that performs
- archiving only when a <emphasis>switch file</> exists. For example:
+ <varname>wal_level</varname> is set to