Skip to content

Commit 9b0e098

Browse files
committed
Introduce new pgcopydb config get|set commands.
Those commands only work when the config.ini file can be found on-disk, which is to say when a pgcopydb command has been started already. The commands allow to review and edit the current settings being used. At the moment editing the values still has no impact on the running processes.
1 parent 1c45750 commit 9b0e098

File tree

9 files changed

+601
-107
lines changed

9 files changed

+601
-107
lines changed

docs/conf.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def __init__(self, **options):
8484
# (source start file, name, description, authors, manual section).
8585
man_pages = [
8686
("ref/pgcopydb", "pgcopydb", "pgcopydb", [author], 1),
87-
("ref/pgcopydb_config", "pgcopydb", "pgcopydb", [author], 5,),
87+
("ref/pgcopydb_filtering", "pgcopydb", "pgcopydb", [author], 5,),
8888
(
8989
"ref/pgcopydb_clone",
9090
"pgcopydb clone",
@@ -113,6 +113,13 @@ def __init__(self, **options):
113113
[author],
114114
1,
115115
),
116+
(
117+
"ref/pgcopydb_config",
118+
"pgcopydb config",
119+
"pgcopydb config",
120+
[author],
121+
1,
122+
),
116123
(
117124
"ref/pgcopydb_copy",
118125
"pgcopydb copy",

docs/ref/manual.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ their own manual page.
2020
pgcopydb_list
2121
pgcopydb_stream
2222
pgcopydb_config
23+
pgcopydb_filtering

docs/ref/pgcopydb_config.rst

Lines changed: 81 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,117 @@
1-
.. _config:
1+
.. _pgcopydb_config:
22

3-
pgcopydb configuration
4-
======================
3+
pgcopydb config
4+
===============
55

6-
Manual page for the configuration of pgcopydb. The ``pgcopydb`` command
7-
accepts sub-commands and command line options, see the manual for those
8-
commands for details. The only setup that ``pgcopydb`` commands accept is
9-
the filtering.
6+
pgcopydb config - Get and Set configuration options for pgcopydb
107

11-
.. _filtering:
8+
This command prefixes the following sub-commands:
129

13-
Filtering
14-
---------
10+
::
1511

16-
Filtering allows to skip some object definitions and data when copying from
17-
the source to the target database. The pgcopydb commands that accept the
18-
option ``--filter`` (or ``--filters``) expect an existing filename as the
19-
option argument. The given filename is read in the INI file format, but only
20-
uses sections and option keys. Option values are not used.
12+
pgcopydb config
13+
get Get configuration option value
14+
set Set configuration option value
2115

22-
Here is an inclusion based filter configuration example:
2316

24-
.. code-block:: ini
25-
:linenos:
17+
The ``pgcopydb config`` commands are used to review or edit configuration
18+
options for a currently running pgcopydb process. At start time, the
19+
``pgcopydb clone`` command (and ``pgcopydb copy`` sub-commands) create a
20+
configuration file with the pgcopydb.index-jobs and pgcopydb.table-jobs
21+
settings that are used. It is possible to review those while the command is
22+
running, and also to edit them using ``pgcopydb config set``.
2623

27-
[include-only-table]
28-
public.allcols
29-
public.csv
30-
public.serial
31-
public.xzero
24+
The new value for the settings is only allowed to be greater than the
25+
current value, that is to say, pgcopydb knows how to create new
26+
sub-processes while running, but will not kill already running processes.
3227

33-
[exclude-index]
34-
public.foo_gin_tsvector
28+
.. _pgcopydb_config_get:
3529

36-
[exclude-table-data]
37-
public.csv
30+
pgcopydb config get
31+
--------------------
3832

39-
Here is an exclusion based filter configuration example:
33+
pgcopydb config get - Get configuration option value
4034

41-
.. code-block:: ini
42-
:linenos:
35+
The command ``pgcopydb config get`` finds the configuration file created by
36+
a previous pgcopydb command, possibly still running, and displays its
37+
contents.
4338

44-
[exclude-schema]
45-
foo
46-
bar
47-
expected
39+
::
4840

49-
[exclude-table]
50-
"schema"."name"
51-
schema.othername
52-
err.errors
53-
public.serial
41+
pgcopydb config get: Get configuration option value
42+
usage: pgcopydb config get [ option-name ]
5443

55-
[exclude-index]
56-
schema.indexname
44+
--json Format the output using JSON
5745

58-
[exclude-table-data]
59-
public.bar
60-
nsitra.test1
46+
.. _pgcopydb_config_set:
6147

62-
Filtering can be done with pgcopydb by using the following rules, which are
63-
also the name of the sections of the INI file.
48+
pgcopydb config set
49+
--------------------
6450

65-
include-only-tables
66-
^^^^^^^^^^^^^^^^^^^
51+
pgcopydb config set - Set configuration option value
6752

68-
This section allows listing the exclusive list of the source tables to copy
69-
to the target database. No other table will be processed by pgcopydb.
53+
The command ``pgcopydb config set`` finds the configuration file created by
54+
a previous pgcopydb command, possibly still running, and edits the given
55+
setting to the new value.
7056

71-
Each line in that section should be a schema-qualified table name. `Postgres
72-
identifier quoting rules`__ can be used to avoid ambiguity.
57+
::
7358

74-
__ https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
59+
pgcopydb config set: Set configuration option value
60+
usage: pgcopydb config set option-name value
7561

76-
When the section ``include-only-tables`` is used in the filtering
77-
configuration then the sections ``exclude-schema`` and ``exclude-table`` are
78-
disallowed. We would not know how to handle tables that exist on the source
79-
database and are not part of any filter.
8062

81-
exclude-schema
82-
^^^^^^^^^^^^^^
63+
Options
64+
-------
8365

84-
This section allows adding schemas (Postgres namespaces) to the exclusion
85-
filters. All the tables that belong to any listed schema in this section are
86-
going to be ignored by the pgcopydb command.
66+
--dir
8767

88-
This section is not allowed when the section ``include-only-tables`` is
89-
used.
68+
During its normal operations pgcopydb creates a lot of temporary files to
69+
track sub-processes progress. Temporary files are created in the directory
70+
location given by this option, or defaults to
71+
``${TMPDIR}/pgcopydb`` when the environment variable is set, or
72+
then to ``/tmp/pgcopydb``.
9073

91-
exclude-table
92-
^^^^^^^^^^^^^
74+
--json
9375

94-
This section allows to add a list of qualified table names to the exclusion
95-
filters. All the tables that are listed in the ``exclude-table`` section are
96-
going to be ignored by the pgcopydb command.
76+
The output of the command is formatted in JSON, when supported. Ignored
77+
otherwise.
9778

98-
This section is not allowed when the section ``include-only-tables`` is
99-
used.
79+
--verbose, --notice
10080

101-
exclude-index
102-
^^^^^^^^^^^^^
81+
Increase current verbosity. The default level of verbosity is INFO. In
82+
ascending order pgcopydb knows about the following verbosity levels:
83+
FATAL, ERROR, WARN, INFO, NOTICE, DEBUG, TRACE.
10384

104-
This section allows to add a list of qualified index names to the exclusion
105-
filters. It is then possible for pgcopydb to operate on a table and skip a
106-
single index definition that belong to a table that is still processed.
85+
--debug
10786

108-
exclude-table-data
109-
^^^^^^^^^^^^^^^^^^
87+
Set current verbosity to DEBUG level.
11088

111-
This section allows to skip copying the data from a list of qualified table
112-
names. The schema, index, constraints, etc of the table are still copied
113-
over.
89+
--trace
11490

115-
Reviewing and Debugging the filters
116-
-----------------------------------
91+
Set current verbosity to TRACE level.
11792

118-
Filtering a ``pg_restore`` archive file is done through rewriting the
119-
archive catalog obtained with ``pg_restore --list``. That's a little hackish
120-
at times, and we also have to deal with dependencies in pgcopydb itself.
93+
--quiet
12194

122-
The following commands can be used to explore a set of filtering rules:
95+
Set current verbosity to ERROR level.
12396

124-
- :ref:`pgcopydb_list_depends`
125-
- :ref:`pgcopydb_restore_parse_list`
97+
98+
Examples
99+
--------
100+
101+
::
102+
103+
$ pgcopydb config get --json
104+
13:23:11 3342 INFO Running pgcopydb version 0.11.37.g119d619.dirty from "/Applications/Postgres.app/Contents/Versions/12/bin/pgcopydb"
105+
13:23:11 3342 INFO A previous run has run through completion
106+
{
107+
"pgcopydb": {
108+
"table-jobs": 4,
109+
"index-jobs": 8
110+
}
111+
}
112+
113+
114+
::
115+
116+
$ pgcopydb config set --quiet pgcopydb.index-jobs 4
117+
4

docs/ref/pgcopydb_filtering.rst

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
.. _config:
2+
3+
pgcopydb configuration
4+
======================
5+
6+
Manual page for the configuration of pgcopydb. The ``pgcopydb`` command
7+
accepts sub-commands and command line options, see the manual for those
8+
commands for details. The only setup that ``pgcopydb`` commands accept is
9+
the filtering.
10+
11+
.. _filtering:
12+
13+
Filtering
14+
---------
15+
16+
Filtering allows to skip some object definitions and data when copying from
17+
the source to the target database. The pgcopydb commands that accept the
18+
option ``--filter`` (or ``--filters``) expect an existing filename as the
19+
option argument. The given filename is read in the INI file format, but only
20+
uses sections and option keys. Option values are not used.
21+
22+
Here is an inclusion based filter configuration example:
23+
24+
.. code-block:: ini
25+
:linenos:
26+
27+
[include-only-table]
28+
public.allcols
29+
public.csv
30+
public.serial
31+
public.xzero
32+
33+
[exclude-index]
34+
public.foo_gin_tsvector
35+
36+
[exclude-table-data]
37+
public.csv
38+
39+
Here is an exclusion based filter configuration example:
40+
41+
.. code-block:: ini
42+
:linenos:
43+
44+
[exclude-schema]
45+
foo
46+
bar
47+
expected
48+
49+
[exclude-table]
50+
"schema"."name"
51+
schema.othername
52+
err.errors
53+
public.serial
54+
55+
[exclude-index]
56+
schema.indexname
57+
58+
[exclude-table-data]
59+
public.bar
60+
nsitra.test1
61+
62+
Filtering can be done with pgcopydb by using the following rules, which are
63+
also the name of the sections of the INI file.
64+
65+
include-only-tables
66+
^^^^^^^^^^^^^^^^^^^
67+
68+
This section allows listing the exclusive list of the source tables to copy
69+
to the target database. No other table will be processed by pgcopydb.
70+
71+
Each line in that section should be a schema-qualified table name. `Postgres
72+
identifier quoting rules`__ can be used to avoid ambiguity.
73+
74+
__ https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
75+
76+
When the section ``include-only-tables`` is used in the filtering
77+
configuration then the sections ``exclude-schema`` and ``exclude-table`` are
78+
disallowed. We would not know how to handle tables that exist on the source
79+
database and are not part of any filter.
80+
81+
exclude-schema
82+
^^^^^^^^^^^^^^
83+
84+
This section allows adding schemas (Postgres namespaces) to the exclusion
85+
filters. All the tables that belong to any listed schema in this section are
86+
going to be ignored by the pgcopydb command.
87+
88+
This section is not allowed when the section ``include-only-tables`` is
89+
used.
90+
91+
exclude-table
92+
^^^^^^^^^^^^^
93+
94+
This section allows to add a list of qualified table names to the exclusion
95+
filters. All the tables that are listed in the ``exclude-table`` section are
96+
going to be ignored by the pgcopydb command.
97+
98+
This section is not allowed when the section ``include-only-tables`` is
99+
used.
100+
101+
exclude-index
102+
^^^^^^^^^^^^^
103+
104+
This section allows to add a list of qualified index names to the exclusion
105+
filters. It is then possible for pgcopydb to operate on a table and skip a
106+
single index definition that belong to a table that is still processed.
107+
108+
exclude-table-data
109+
^^^^^^^^^^^^^^^^^^
110+
111+
This section allows to skip copying the data from a list of qualified table
112+
names. The schema, index, constraints, etc of the table are still copied
113+
over.
114+
115+
Reviewing and Debugging the filters
116+
-----------------------------------
117+
118+
Filtering a ``pg_restore`` archive file is done through rewriting the
119+
archive catalog obtained with ``pg_restore --list``. That's a little hackish
120+
at times, and we also have to deal with dependencies in pgcopydb itself.
121+
122+
The following commands can be used to explore a set of filtering rules:
123+
124+
- :ref:`pgcopydb_list_depends`
125+
- :ref:`pgcopydb_restore_parse_list`

src/bin/pgcopydb/cli_common.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,8 +1045,6 @@ cli_copy_prepare_specs(CopyDataSpec *copySpecs, CopyDataSection section)
10451045
exit(EXIT_CODE_INTERNAL_ERROR);
10461046
}
10471047

1048-
strlcpy(copyDBoptions.dir, copySpecs->cfPaths.topdir, MAXPGPATH);
1049-
10501048
(void) config_init(&copyDBoptions);
10511049

10521050
if (!config_write_file(&copyDBoptions, copySpecs->cfPaths.conffile))

0 commit comments

Comments
 (0)