forked from dimitri/pgcopydb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement filtering support. (dimitri#19)
* Implement a parser for filtering settings, and filter table lists. * Apply filters to listing sequences. We filter only those sequences that have a link dependency to the selected tables. There is no way at the moment to select a sequence that's not tracked to a specific default value for a column that doesn't belong to one of the selected tables. That said, when filtering is not used, all sequences are processed, even those not attached to any table. Which means that `pgcopydb copy sequences` in the use case where filtering is needed for tables, but not for sequences. * Implement pgcopydb list ... --list-skipped. This option allows debugging the filtering setup, and is also needed to implement pg_restore catalog editing (--use-list) to avoid installing objects that are filtered-out in the setup. * Document filtering setup. * Add a test for the filtering capabilities. * Improve filtering of pg_restore list entries without an OID. Some pg_restore --list entries such as INDEX ATTACH miss both the catalog and the object oid, and then we need to match them by their pg_restore list name, which is a compound of the schema name, object name, and owner name. Adding to that, the way pg_restore builds that compound name is with using a single space as a separator, and replacing \n and \r characters with a single space. This makes the pg_restore list output unfriendly to machine parsing, and so instead we generate the list name from the Postgres catalogs in our catalog queries. Then we can use an hash table on the OIDs and another one on the compound names and find out if an INDEX ATTACH catalog entry refers to an index that has been filtered-out by filtering rules, and comment it out then. * Add a pg_depend recursive walker facility. This allows filtering from pg_restore --list objects that depend on tables that have been filtered out.
- Loading branch information
Showing
41 changed files
with
6,151 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ their own manual page. | |
pgcopydb_restore | ||
pgcopydb_list | ||
pgcopydb_copy | ||
pgcopydb_config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
.. _config: | ||
|
||
pgcopydb configuration | ||
====================== | ||
|
||
Manual page for the configuration of pgcopydb. The ``pgcopydb`` command | ||
accepts sub-commands and command line options, see the manual for those | ||
commands for details. The only setup that ``pgcopydb`` commands accept is | ||
the filtering. | ||
|
||
.. _filtering: | ||
|
||
Filtering | ||
--------- | ||
|
||
Filtering allows to skip some object definitions and data when copying from | ||
the source to the target database. The pgcopydb commands that accept the | ||
option ``--filter`` (or ``--filters``) expect an existing filename as the | ||
option argument. The given filename is read in the INI file format, but only | ||
uses sections and option keys. Option values are not used. | ||
|
||
Here is an inclusion based filter configuration example: | ||
|
||
.. code-block:: ini | ||
:linenos: | ||
[include-only-table] | ||
public.allcols | ||
public.csv | ||
public.serial | ||
public.xzero | ||
[exclude-index] | ||
public.foo_gin_tsvector | ||
[exclude-table-data] | ||
public.csv | ||
Here is an exclusion based filter configuration example: | ||
|
||
.. code-block:: ini | ||
:linenos: | ||
[exclude-schema] | ||
foo | ||
bar | ||
expected | ||
[exclude-table] | ||
"schema"."name" | ||
schema.othername | ||
err.errors | ||
public.serial | ||
[exclude-index] | ||
schema.indexname | ||
[exclude-table-data] | ||
public.bar | ||
nsitra.test1 | ||
Filtering can be done with pgcopydb by using the following rules, which are | ||
also the name of the sections of the INI file. | ||
|
||
include-only-tables | ||
^^^^^^^^^^^^^^^^^^^ | ||
|
||
This section allows listing the exclusive list of the source tables to copy | ||
to the target database. No other table will be processed by pgcopydb. | ||
|
||
Each line in that section should be a schema-qualified table name. `Postgres | ||
identifier quoting rules`__ can be used to avoid ambiguity. | ||
|
||
__ https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS | ||
|
||
When the section ``include-only-tables`` is used in the filtering | ||
configuration then the sections ``exclude-schema`` and ``exclude-table`` are | ||
disallowed. We would not know how to handle tables that exist on the source | ||
database and are not part of any filter. | ||
|
||
exclude-schema | ||
^^^^^^^^^^^^^^ | ||
|
||
This section allows adding schemas (Postgres namespaces) to the exclusion | ||
filters. All the tables that belong to any listed schema in this section are | ||
going to be ignored by the pgcopydb command. | ||
|
||
This section is not allowed when the section ``include-only-tables`` is | ||
used. | ||
|
||
exclude-table | ||
^^^^^^^^^^^^^ | ||
|
||
This section allows to add a list of qualified table names to the exclusion | ||
filters. All the tables that are listed in the ``exclude-table`` section are | ||
going to be ignored by the pgcopydb command. | ||
|
||
This section is not allowed when the section ``include-only-tables`` is | ||
used. | ||
|
||
exclude-index | ||
^^^^^^^^^^^^^ | ||
|
||
This section allows to add a list of qualified index names to the exclusion | ||
filters. It is then possible for pgcopydb to operate on a table and skip a | ||
single index definition that belong to a table that is still processed. | ||
|
||
exclude-table-data | ||
^^^^^^^^^^^^^^^^^^ | ||
|
||
This section allows to skip copying the data from a list of qualified table | ||
names. The schema, index, constraints, etc of the table are still copied | ||
over. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.