1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
.. _pgcopydb_dump:
pgcopydb dump
=============
pgcopydb dump - Dump database objects from a Postgres instance
This command prefixes the following sub-commands:
.. include:: ../include/dump.rst
.. _pgcopydb_dump_schema:
pgcopydb dump schema
--------------------
pgcopydb dump schema - Dump source database schema as custom files in target directory
The command ``pgcopydb dump schema`` uses pg_dump to export SQL schema
definitions from the given source Postgres instance.
.. include:: ../include/dump-schema.rst
.. _pgcopydb_dump_roles:
pgcopydb dump roles
-------------------
pgcopydb dump roles - Dump source database roles as custome file in work directory
The command ``pgcopydb dump roles`` uses pg_dumpall --roles-only to export
SQL definitions of the roles found on the source Postgres instance.
.. include:: ../include/dump-roles.rst
The ``pg_dumpall --roles-only`` is used to fetch the list of roles from the
source database, and this command includes support for passwords. As a
result, this operation requires the superuser privileges.
It is possible to use the option ``--no-role-passwords`` to operate without
superuser privileges. In that case though, the passwords are not part of the
dump and authentication might fail until passwords have been setup properly.
Description
-----------
The ``pgcopydb dump schema`` command implements the first step of the full
database migration and fetches the schema definitions from the source
database.
When the command runs, it calls ``pg_dump`` to get the pre-data schema and
the post-data schema output in a Postgres custom file called ``schema.dump``.
The output files are written to the ``schema`` sub-directory of the
``--target`` directory.
Options
-------
The following options are available to ``pgcopydb dump schema`` subcommand:
--source
Connection string to the source Postgres instance. See the Postgres
documentation for `connection strings`__ for the details. In short both
the quoted form ``"host=... dbname=..."`` and the URI form
``postgres://user@host:5432/dbname`` are supported.
__ https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
--target
Connection string to the target Postgres instance.
--dir
During its normal operations pgcopydb creates a lot of temporary files to
track sub-processes progress. Temporary files are created in the directory
specified by this option, or defaults to
``${TMPDIR}/pgcopydb`` when the environment variable is set, or
otherwise to ``/tmp/pgcopydb``.
--no-role-passwords
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 pg_roles instead of
pg_authid. Therefore, this option also helps if access to pg_authid is
restricted by some security policy.
--snapshot
Instead of exporting its own snapshot by calling the PostgreSQL function
``pg_export_snapshot()`` it is possible for pgcopydb to re-use an already
exported snapshot.
--verbose
Increase current verbosity. The default level of verbosity is INFO. In
ascending order pgcopydb knows about the following verbosity levels:
FATAL, ERROR, WARN, INFO, NOTICE, DEBUG, TRACE.
--debug
Set current verbosity to DEBUG level.
--trace
Set current verbosity to TRACE level.
--quiet
Set current verbosity to ERROR level.
Environment
-----------
PGCOPYDB_SOURCE_PGURI
Connection string to the source Postgres instance. When ``--source`` is
ommitted from the command line, then this environment variable is used.
Examples
--------
First, using ``pgcopydb dump schema``
::
$ pgcopydb dump schema --source "port=5501 dbname=demo" --target /tmp/target
09:35:21 3926 INFO Dumping database from "port=5501 dbname=demo"
09:35:21 3926 INFO Dumping database into directory "/tmp/target"
09:35:21 3926 INFO Found a stale pidfile at "/tmp/target/pgcopydb.pid"
09:35:21 3926 WARN Removing the stale pid file "/tmp/target/pgcopydb.pid"
09:35:21 3926 INFO Using pg_dump for Postgres "12.9" at "/Applications/Postgres.app/Contents/Versions/12/bin/pg_dump"
09:35:21 3926 INFO /Applications/Postgres.app/Contents/Versions/12/bin/pg_dump -Fc --section pre-data --section post-data --file /tmp/target/schema/schema.dump 'port=5501 dbname=demo'
Once the previous command is finished, the pg_dump output file can be found
in ``/tmp/target/schema`` and is named ``schema.dump``. Additionally, other files
and directories have been created.
::
$ find /tmp/target
/tmp/target
/tmp/target/pgcopydb.pid
/tmp/target/schema
/tmp/target/schema/schema.dump
/tmp/target/run
/tmp/target/run/tables
/tmp/target/run/indexes
|