Sophie

Sophie

distrib > Mageia > 7 > x86_64 > by-pkgid > 9b6cc37ce608401d44f6535a0c7cb777 > files > 14

postgresql11-docs-11.5-1.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>pg_dumpall</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="app-pgdump.html" title="pg_dump" /><link rel="next" href="app-pg-isready.html" title="pg_isready" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center"><span xmlns="http://www.w3.org/1999/xhtml" class="application">pg_dumpall</span></th></tr><tr><td width="10%" align="left"><a accesskey="p" href="app-pgdump.html" title="pg_dump">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="reference-client.html" title="PostgreSQL Client Applications">Up</a></td><th width="60%" align="center">PostgreSQL Client Applications</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 11.5 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="app-pg-isready.html" title="pg_isready">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="APP-PG-DUMPALL"><div class="titlepage"></div><a id="id-1.9.4.13.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle"><span class="application">pg_dumpall</span></span></h2><p>pg_dumpall — extract a <span class="productname">PostgreSQL</span> database cluster into a script file</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p id="id-1.9.4.13.4.1"><code class="command">pg_dumpall</code> [<em class="replaceable"><code>connection-option</code></em>...] [<em class="replaceable"><code>option</code></em>...]</p></div></div><div class="refsect1" id="APP-PG-DUMPALL-DESCRIPTION"><h2>Description</h2><p>
   <span class="application">pg_dumpall</span> is a utility for writing out
   (<span class="quote">“<span class="quote">dumping</span>”</span>) all <span class="productname">PostgreSQL</span> databases
   of a cluster into one script file.  The script file contains
   <acronym class="acronym">SQL</acronym> commands that can be used as input to <a class="xref" href="app-psql.html" title="psql"><span class="refentrytitle"><span class="application">psql</span></span></a> to restore the databases.  It does this by
   calling <a class="xref" href="app-pgdump.html" title="pg_dump"><span class="refentrytitle">pg_dump</span></a> for each database in the cluster.
   <span class="application">pg_dumpall</span> also dumps global objects
   that are common to all databases, that is, database roles and tablespaces.
   (<span class="application">pg_dump</span> does not save these objects.)
  </p><p>
   Since <span class="application">pg_dumpall</span> reads tables from all
   databases you will most likely have to connect as a database
   superuser in order to produce a complete dump.  Also you will need
   superuser privileges to execute the saved script in order to be
   allowed to add roles and create databases.
  </p><p>
   The SQL script will be written to the standard output.  Use the
   [-f|file] option or shell operators to redirect it into a file.
  </p><p>
  <span class="application">pg_dumpall</span> needs to connect several
  times to the <span class="productname">PostgreSQL</span> server (once per
  database).  If you use password authentication it will ask for
  a password each time. It is convenient to have a
  <code class="filename">~/.pgpass</code> file in such cases. See <a class="xref" href="libpq-pgpass.html" title="34.15. The Password File">Section 34.15</a> for more information.
  </p></div><div class="refsect1" id="id-1.9.4.13.6"><h2>Options</h2><p>
    The following command-line options control the content and
    format of the output.

    </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-a</code><br /></span><span class="term"><code class="option">--data-only</code></span></dt><dd><p>
        Dump only the data, not the schema (data definitions).
       </p></dd><dt><span class="term"><code class="option">-c</code><br /></span><span class="term"><code class="option">--clean</code></span></dt><dd><p>
        Include SQL commands to clean (drop) databases before
        recreating them.  <code class="command">DROP</code> commands for roles and
        tablespaces are added as well.
       </p></dd><dt><span class="term"><code class="option">-E <em class="replaceable"><code>encoding</code></em></code><br /></span><span class="term"><code class="option">--encoding=<em class="replaceable"><code>encoding</code></em></code></span></dt><dd><p>
        Create the dump in the specified character set encoding. By default,
        the dump is created in the database encoding.  (Another way to get the
        same result is to set the <code class="envar">PGCLIENTENCODING</code> environment
        variable to the desired dump encoding.)
       </p></dd><dt><span class="term"><code class="option">-f <em class="replaceable"><code>filename</code></em></code><br /></span><span class="term"><code class="option">--file=<em class="replaceable"><code>filename</code></em></code></span></dt><dd><p>
        Send output to the specified file.  If this is omitted, the
        standard output is used.
       </p></dd><dt><span class="term"><code class="option">-g</code><br /></span><span class="term"><code class="option">--globals-only</code></span></dt><dd><p>
        Dump only global objects (roles and tablespaces), no databases.
       </p></dd><dt><span class="term"><code class="option">-o</code><br /></span><span class="term"><code class="option">--oids</code></span></dt><dd><p>
        Dump object identifiers (<acronym class="acronym">OID</acronym>s) as part of the
        data for every table.  Use this option if your application references
        the <acronym class="acronym">OID</acronym>
        columns in some way (e.g., in a foreign key constraint).
        Otherwise, this option should not be used.
       </p></dd><dt><span class="term"><code class="option">-O</code><br /></span><span class="term"><code class="option">--no-owner</code></span></dt><dd><p>
        Do not output commands to set
        ownership of objects to match the original database.
        By default, <span class="application">pg_dumpall</span> issues
        <code class="command">ALTER OWNER</code> or
        <code class="command">SET SESSION AUTHORIZATION</code>
        statements to set ownership of created schema elements.
        These statements
        will fail when the script is run unless it is started by a superuser
        (or the same user that owns all of the objects in the script).
        To make a script that can be restored by any user, but will give
        that user ownership of all the objects, specify <code class="option">-O</code>.
       </p></dd><dt><span class="term"><code class="option">-r</code><br /></span><span class="term"><code class="option">--roles-only</code></span></dt><dd><p>
        Dump only roles, no databases or tablespaces.
       </p></dd><dt><span class="term"><code class="option">-s</code><br /></span><span class="term"><code class="option">--schema-only</code></span></dt><dd><p>
        Dump only the object definitions (schema), not data.
       </p></dd><dt><span class="term"><code class="option">-S <em class="replaceable"><code>username</code></em></code><br /></span><span class="term"><code class="option">--superuser=<em class="replaceable"><code>username</code></em></code></span></dt><dd><p>
        Specify the superuser user name to use when disabling triggers.
        This is relevant only if <code class="option">--disable-triggers</code> is used.
        (Usually, it's better to leave this out, and instead start the
        resulting script as superuser.)
       </p></dd><dt><span class="term"><code class="option">-t</code><br /></span><span class="term"><code class="option">--tablespaces-only</code></span></dt><dd><p>
        Dump only tablespaces, no databases or roles.
       </p></dd><dt><span class="term"><code class="option">-v</code><br /></span><span class="term"><code class="option">--verbose</code></span></dt><dd><p>
        Specifies verbose mode.  This will cause
        <span class="application">pg_dumpall</span> to output start/stop
        times to the dump file, and progress messages to standard error.
        It will also enable verbose output in <span class="application">pg_dump</span>.
       </p></dd><dt><span class="term"><code class="option">-V</code><br /></span><span class="term"><code class="option">--version</code></span></dt><dd><p>
       Print the <span class="application">pg_dumpall</span> version and exit.
       </p></dd><dt><span class="term"><code class="option">-x</code><br /></span><span class="term"><code class="option">--no-privileges</code><br /></span><span class="term"><code class="option">--no-acl</code></span></dt><dd><p>
        Prevent dumping of access privileges (grant/revoke commands).
       </p></dd><dt><span class="term"><code class="option">--binary-upgrade</code></span></dt><dd><p>
        This option is for use by in-place upgrade utilities.  Its use
        for other purposes is not recommended or supported.  The
        behavior of the option may change in future releases without
        notice.
       </p></dd><dt><span class="term"><code class="option">--column-inserts</code><br /></span><span class="term"><code class="option">--attribute-inserts</code></span></dt><dd><p>
        Dump data as <code class="command">INSERT</code> commands with explicit
        column names (<code class="literal">INSERT INTO
        <em class="replaceable"><code>table</code></em>
        (<em class="replaceable"><code>column</code></em>, ...) VALUES
        ...</code>).  This will make restoration very slow; it is mainly
        useful for making dumps that can be loaded into
        non-<span class="productname">PostgreSQL</span> databases.
       </p></dd><dt><span class="term"><code class="option">--disable-dollar-quoting</code></span></dt><dd><p>
        This option disables the use of dollar quoting for function bodies,
        and forces them to be quoted using SQL standard string syntax.
       </p></dd><dt><span class="term"><code class="option">--disable-triggers</code></span></dt><dd><p>
        This option is relevant only when creating a data-only dump.
        It instructs <span class="application">pg_dumpall</span> to include commands
        to temporarily disable triggers on the target tables while
        the data is reloaded.  Use this if you have referential
        integrity checks or other triggers on the tables that you
        do not want to invoke during data reload.
       </p><p>
        Presently, the commands emitted for <code class="option">--disable-triggers</code>
        must be done as superuser.  So, you should also specify
        a superuser name with <code class="option">-S</code>, or preferably be careful to
        start the resulting script as a superuser.
       </p></dd><dt><span class="term"><code class="option">--if-exists</code></span></dt><dd><p>
        Use conditional commands (i.e. add an <code class="literal">IF EXISTS</code>
        clause) to drop databases and other objects.  This option is not valid
        unless <code class="option">--clean</code> is also specified.
       </p></dd><dt><span class="term"><code class="option">--inserts</code></span></dt><dd><p>
        Dump data as <code class="command">INSERT</code> commands (rather
        than <code class="command">COPY</code>).  This will make restoration very slow;
        it is mainly useful for making dumps that can be loaded into
        non-<span class="productname">PostgreSQL</span> databases.  Note that
        the restore might fail altogether if you have rearranged column order.
        The <code class="option">--column-inserts</code> option is safer, though even
        slower.
       </p></dd><dt><span class="term"><code class="option">--load-via-partition-root</code></span></dt><dd><p>
        When dumping data for a table partition, make
        the <code class="command">COPY</code> or <code class="command">INSERT</code> statements
        target the root of the partitioning hierarchy that contains it, rather
        than the partition itself.  This causes the appropriate partition to
        be re-determined for each row when the data is loaded.  This may be
        useful when reloading data on a server where rows do not always fall
        into the same partitions as they did on the original server.  That
        could happen, for example, if the partitioning column is of type text
        and the two systems have different definitions of the collation used
        to sort the partitioning column.
       </p></dd><dt><span class="term"><code class="option">--lock-wait-timeout=<em class="replaceable"><code>timeout</code></em></code></span></dt><dd><p>
        Do not wait forever to acquire shared table locks at the beginning of
        the dump. Instead, fail if unable to lock a table within the specified
        <em class="replaceable"><code>timeout</code></em>. The timeout may be
        specified in any of the formats accepted by <code class="command">SET
        statement_timeout</code>.  Allowed values vary depending on the server
        version you are dumping from, but an integer number of milliseconds
        is accepted by all versions since 7.3.  This option is ignored when
        dumping from a pre-7.3 server.
       </p></dd><dt><span class="term"><code class="option">--no-comments</code></span></dt><dd><p>
        Do not dump comments.
       </p></dd><dt><span class="term"><code class="option">--no-publications</code></span></dt><dd><p>
        Do not dump publications.
       </p></dd><dt><span class="term"><code class="option">--no-role-passwords</code></span></dt><dd><p>
        Do not dump passwords for roles.  When restored, roles will have a
        null password, and password authentication will always fail until the
        password is set.  Since password values aren't needed when this option
        is specified, the role information is read from the catalog
        view <code class="structname">pg_roles</code> instead
        of <code class="structname">pg_authid</code>.  Therefore, this option also
        helps if access to <code class="structname">pg_authid</code> is restricted by
        some security policy.
       </p></dd><dt><span class="term"><code class="option">--no-security-labels</code></span></dt><dd><p>
        Do not dump security labels.
       </p></dd><dt><span class="term"><code class="option">--no-subscriptions</code></span></dt><dd><p>
        Do not dump subscriptions.
       </p></dd><dt><span class="term"><code class="option">--no-sync</code></span></dt><dd><p>
        By default, <code class="command">pg_dumpall</code> will wait for all files
        to be written safely to disk.  This option causes
        <code class="command">pg_dumpall</code> to return without waiting, which is
        faster, but means that a subsequent operating system crash can leave
        the dump corrupt.  Generally, this option is useful for testing
        but should not be used when dumping data from production installation.
       </p></dd><dt><span class="term"><code class="option">--no-tablespaces</code></span></dt><dd><p>
        Do not output commands to create tablespaces nor select tablespaces
        for objects.
        With this option, all objects will be created in whichever
        tablespace is the default during restore.
       </p></dd><dt><span class="term"><code class="option">--no-unlogged-table-data</code></span></dt><dd><p>
        Do not dump the contents of unlogged tables.  This option has no
        effect on whether or not the table definitions (schema) are dumped;
        it only suppresses dumping the table data.
       </p></dd><dt><span class="term"><code class="option">--quote-all-identifiers</code></span></dt><dd><p>
        Force quoting of all identifiers.  This option is recommended when
        dumping a database from a server whose <span class="productname">PostgreSQL</span>
        major version is different from <span class="application">pg_dumpall</span>'s, or when
        the output is intended to be loaded into a server of a different
        major version.  By default, <span class="application">pg_dumpall</span> quotes only
        identifiers that are reserved words in its own major version.
        This sometimes results in compatibility issues when dealing with
        servers of other versions that may have slightly different sets
        of reserved words.  Using <code class="option">--quote-all-identifiers</code> prevents
        such issues, at the price of a harder-to-read dump script.
       </p></dd><dt><span class="term"><code class="option">--use-set-session-authorization</code></span></dt><dd><p>
        Output SQL-standard <code class="command">SET SESSION AUTHORIZATION</code> commands
        instead of <code class="command">ALTER OWNER</code> commands to determine object
        ownership.  This makes the dump more standards compatible, but
        depending on the history of the objects in the dump, might not restore
        properly.
       </p></dd><dt><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help</code></span></dt><dd><p>
       Show help about <span class="application">pg_dumpall</span> command line
       arguments, and exit.
       </p></dd></dl></div><p>
   </p><p>
   The following command-line options control the database connection parameters.

   </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-d <em class="replaceable"><code>connstr</code></em></code><br /></span><span class="term"><code class="option">--dbname=<em class="replaceable"><code>connstr</code></em></code></span></dt><dd><p>
        Specifies parameters used to connect to the server, as a connection
        string. See <a class="xref" href="libpq-connect.html#LIBPQ-CONNSTRING" title="34.1.1. Connection Strings">Section 34.1.1</a> for more information.
       </p><p>
        The option is called <code class="literal">--dbname</code> for consistency with other
        client applications, but because <span class="application">pg_dumpall</span>
        needs to connect to many databases, the database name in the
        connection string will be ignored.  Use the <code class="literal">-l</code>
        option to specify the name of the database used for the initial
        connection, which will dump global objects and discover what other
        databases should be dumped.
       </p></dd><dt><span class="term"><code class="option">-h <em class="replaceable"><code>host</code></em></code><br /></span><span class="term"><code class="option">--host=<em class="replaceable"><code>host</code></em></code></span></dt><dd><p>
        Specifies the host name of the machine on which the database
        server is running.  If the value begins with a slash, it is
        used as the directory for the Unix domain socket.  The default
        is taken from the <code class="envar">PGHOST</code> environment variable,
        if set, else a Unix domain socket connection is attempted.
       </p></dd><dt><span class="term"><code class="option">-l <em class="replaceable"><code>dbname</code></em></code><br /></span><span class="term"><code class="option">--database=<em class="replaceable"><code>dbname</code></em></code></span></dt><dd><p>
         Specifies the name of the database to connect to for dumping global
         objects and discovering what other databases should be dumped. If
         not specified, the <code class="literal">postgres</code> database will be used,
         and if that does not exist, <code class="literal">template1</code> will be used.
       </p></dd><dt><span class="term"><code class="option">-p <em class="replaceable"><code>port</code></em></code><br /></span><span class="term"><code class="option">--port=<em class="replaceable"><code>port</code></em></code></span></dt><dd><p>
        Specifies the TCP port or local Unix domain socket file
        extension on which the server is listening for connections.
        Defaults to the <code class="envar">PGPORT</code> environment variable, if
        set, or a compiled-in default.
       </p></dd><dt><span class="term"><code class="option">-U <em class="replaceable"><code>username</code></em></code><br /></span><span class="term"><code class="option">--username=<em class="replaceable"><code>username</code></em></code></span></dt><dd><p>
        User name to connect as.
       </p></dd><dt><span class="term"><code class="option">-w</code><br /></span><span class="term"><code class="option">--no-password</code></span></dt><dd><p>
        Never issue a password prompt.  If the server requires
        password authentication and a password is not available by
        other means such as a <code class="filename">.pgpass</code> file, the
        connection attempt will fail.  This option can be useful in
        batch jobs and scripts where no user is present to enter a
        password.
       </p></dd><dt><span class="term"><code class="option">-W</code><br /></span><span class="term"><code class="option">--password</code></span></dt><dd><p>
        Force <span class="application">pg_dumpall</span> to prompt for a
        password before connecting to a database.
       </p><p>
        This option is never essential, since
        <span class="application">pg_dumpall</span> will automatically prompt
        for a password if the server demands password authentication.
        However, <span class="application">pg_dumpall</span> will waste a
        connection attempt finding out that the server wants a password.
        In some cases it is worth typing <code class="option">-W</code> to avoid the extra
        connection attempt.
       </p><p>
        Note that the password prompt will occur again for each database
        to be dumped.  Usually, it's better to set up a
        <code class="filename">~/.pgpass</code> file than to rely on manual password entry.
       </p></dd><dt><span class="term"><code class="option">--role=<em class="replaceable"><code>rolename</code></em></code></span></dt><dd><p>
        Specifies a role name to be used to create the dump.
        This option causes <span class="application">pg_dumpall</span> to issue a
        <code class="command">SET ROLE</code> <em class="replaceable"><code>rolename</code></em>
        command after connecting to the database. It is useful when the
        authenticated user (specified by <code class="option">-U</code>) lacks privileges
        needed by <span class="application">pg_dumpall</span>, but can switch to a role with
        the required rights.  Some installations have a policy against
        logging in directly as a superuser, and use of this option allows
        dumps to be made without violating the policy.
       </p></dd></dl></div><p>
  </p></div><div class="refsect1" id="id-1.9.4.13.7"><h2>Environment</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="envar">PGHOST</code><br /></span><span class="term"><code class="envar">PGOPTIONS</code><br /></span><span class="term"><code class="envar">PGPORT</code><br /></span><span class="term"><code class="envar">PGUSER</code></span></dt><dd><p>
      Default connection parameters
     </p></dd></dl></div><p>
   This utility, like most other <span class="productname">PostgreSQL</span> utilities,
   also uses the environment variables supported by <span class="application">libpq</span>
   (see <a class="xref" href="libpq-envars.html" title="34.14. Environment Variables">Section 34.14</a>).
  </p></div><div class="refsect1" id="id-1.9.4.13.8"><h2>Notes</h2><p>
   Since <span class="application">pg_dumpall</span> calls
   <span class="application">pg_dump</span> internally, some diagnostic
   messages will refer to <span class="application">pg_dump</span>.
  </p><p>
   The <code class="option">--clean</code> option can be useful even when your
   intention is to restore the dump script into a fresh cluster.  Use of
   <code class="option">--clean</code> authorizes the script to drop and re-create the
   built-in <code class="literal">postgres</code> and <code class="literal">template1</code>
   databases, ensuring that those databases will retain the same properties
   (for instance, locale and encoding) that they had in the source cluster.
   Without the option, those databases will retain their existing
   database-level properties, as well as any pre-existing contents.
  </p><p>
   Once restored, it is wise to run <code class="command">ANALYZE</code> on each
   database so the optimizer has useful statistics. You
   can also run <code class="command">vacuumdb -a -z</code> to analyze all
   databases.
  </p><p>
   The dump script should not be expected to run completely without errors.
   In particular, because the script will issue <code class="command">CREATE ROLE</code>
   for every role existing in the source cluster, it is certain to get a
   <span class="quote">“<span class="quote">role already exists</span>”</span> error for the bootstrap superuser,
   unless the destination cluster was initialized with a different bootstrap
   superuser name.  This error is harmless and should be ignored.  Use of
   the <code class="option">--clean</code> option is likely to produce additional
   harmless error messages about non-existent objects, although you can
   minimize those by adding <code class="option">--if-exists</code>.
  </p><p>
   <span class="application">pg_dumpall</span> requires all needed
   tablespace directories to exist before the restore;  otherwise,
   database creation will fail for databases in non-default
   locations.
  </p></div><div class="refsect1" id="APP-PG-DUMPALL-EX"><h2>Examples</h2><p>
   To dump all databases:

</p><pre class="screen">
<code class="prompt">$</code> <strong class="userinput"><code>pg_dumpall &gt; db.out</code></strong>
</pre><p>
  </p><p>
   To reload database(s) from this file, you can use:
</p><pre class="screen">
<code class="prompt">$</code> <strong class="userinput"><code>psql -f db.out postgres</code></strong>
</pre><p>
   It is not important to which database you connect here since the
   script file created by <span class="application">pg_dumpall</span> will
   contain the appropriate commands to create and connect to the saved
   databases.  An exception is that if you specified <code class="option">--clean</code>,
   you must connect to the <code class="literal">postgres</code> database initially;
   the script will attempt to drop other databases immediately, and that
   will fail for the database you are connected to.
  </p></div><div class="refsect1" id="id-1.9.4.13.10"><h2>See Also</h2><p>
    Check <a class="xref" href="app-pgdump.html" title="pg_dump"><span class="refentrytitle">pg_dump</span></a> for details on possible
    error conditions.
  </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="app-pgdump.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="reference-client.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="app-pg-isready.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">pg_dump </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> <span class="application">pg_isready</span></td></tr></table></div></body></html>