Home Explore Blog CI



postgresql

7th chunk of `doc/src/sgml/ref/pg_dump.sgml`
8948604b8f1ebb4bf9f3c557a5150d0d749c91e8b9c109f50000000100000fa9
 class="parameter">pattern</replaceable>; this selects both the
        schema itself, and all its contained objects.  When this option is
        not specified, all non-system schemas in the target database will be
        dumped.  Multiple schemas can be
        selected by writing multiple <option>-n</option> switches.  The
        <replaceable class="parameter">pattern</replaceable> parameter is
        interpreted as a pattern according to the same rules used by
        <application>psql</application>'s <literal>\d</literal> commands
        (see <xref linkend="app-psql-patterns"/>),
        so multiple schemas can also be selected by writing wildcard characters
        in the pattern.  When using wildcards, be careful to quote the pattern
        if needed to prevent the shell from expanding the wildcards;  see
        <xref linkend="pg-dump-examples"/> below.
       </para>

       <note>
        <para>
         When <option>-n</option> is specified, <application>pg_dump</application>
         makes no attempt to dump any other database objects that the selected
         schema(s) might depend upon. Therefore, there is no guarantee
         that the results of a specific-schema dump can be successfully
         restored by themselves into a clean database.
        </para>
       </note>

       <note>
        <para>
         Non-schema objects such as large objects are not dumped when <option>-n</option> is
         specified.  You can add large objects back to the dump with the
         <option>--large-objects</option> switch.
        </para>
       </note>

      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>-N <replaceable class="parameter">pattern</replaceable></option></term>
      <term><option>--exclude-schema=<replaceable class="parameter">pattern</replaceable></option></term>
      <listitem>
       <para>
        Do not dump any schemas matching <replaceable
        class="parameter">pattern</replaceable>.  The pattern is
        interpreted according to the same rules as for <option>-n</option>.
        <option>-N</option> can be given more than once to exclude schemas
        matching any of several patterns.
       </para>

       <para>
        When both <option>-n</option> and <option>-N</option> are given, the behavior
        is to dump just the schemas that match at least one <option>-n</option>
        switch but no <option>-N</option> switches.  If <option>-N</option> appears
        without <option>-n</option>, then schemas matching <option>-N</option> are
        excluded from what is otherwise a normal dump.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>-O</option></term>
      <term><option>--no-owner</option></term>
      <listitem>
       <para>
        Do not output commands to set
        ownership of objects to match the original database.
        By default, <application>pg_dump</application> issues
        <command>ALTER OWNER</command> or
        <command>SET SESSION AUTHORIZATION</command>
        statements to set ownership of created database objects.
        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 <option>-O</option>.
       </para>

       <para>
        This option is ignored when emitting an archive (non-text) output
        file.  For the archive formats, you can specify the option when you
        call <command>pg_restore</command>.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>-R</option></term>
      <term><option>--no-reconnect</option></term>
      <listitem>
       <para>
        This option is obsolete but still accepted for backwards
        compatibility.
       </para>
      </listitem>
     </varlistentry>

Title: pg_dump Schema Selection, Exclusion, and Ownership Options
Summary
This section explains the -n/--schema option for selecting schemas to dump, noting that pg_dump doesn't attempt to dump dependencies outside the selected schemas and doesn't dump non-schema objects like large objects unless --large-objects is used. It also describes the -N/--exclude-schema option for excluding schemas, detailing how it interacts with -n. Finally, it discusses the -O/--no-owner option, which prevents the output of commands that set object ownership, allowing restoration by any user, and the obsolete -R/--no-reconnect option.