Publish tables¶
Who needs this
Oracle sources: yes. Every new Oracle Capture Agent requires its tables to be published before SQDR can
subscribe to them. Other sources: no, unless you turn on requirePublication for the agent (see Why
publish).
Publishing tells a Capture Agent which source tables SQDR may replicate, and prepares them for capture: it can grant the agent user access to them and, for Oracle, turn on supplemental logging.
Publish tables¶
- In the SQDR Control Center, select the agent, open its Publications tab and click Add Publication.
- For Db2 for i and Oracle, the first time in a session, enter a privileged
user: one with enough authority to grant access and change the tables, for example
QSECOFRon Db2 for i orSYSTEMon Oracle. It's kept only for your Control Center session. For the other sources, the agent's own user does the work. - In Add Publications, search for the tables (
%matches any characters,_one character), select them, keep Grant access to "agent user" selected, and click Finish. To publish a long list, use Import. - Wait until the tables show Published on the Publications tab (see Publication states).
Publication states¶
Add Publication writes the table to the agent's catalog on the source as Initial. The Capture Agent then sets the table up for capture, creates its staging table, and moves it through these states:
| State | What it means |
|---|---|
| Initial | Published, not yet processed by the Capture Agent (for example because the agent is stopped). |
| Subscribed | The Capture Agent has set the table up for capture. |
| Published | Ready: SQDR can subscribe to the table. |
| Published* | Ready, but the Capture Agent couldn't get an exclusive lock on the table when it set it up. retryPublishLock=true makes the agent keep trying for the lock instead. |
| Failed | Setting the table up failed; Detail shows the error. The Capture Agent tries again. |
Detail can also show IMAGES(*AFTER) for a Db2 for i table journaled with after images only.
Add Publications options¶
| Field | What it's for |
|---|---|
| Schema, Table Name | A name or an SQL search pattern (% any characters, _ one character). Search lists only tables that aren't published yet. |
| Journal | Db2 for i only: as LIBRARY/JOURNAL. |
| Grant access to "agent user": | Grants the agent user access to the published tables and, for Oracle, adds supplemental logging (see below). Shown for Db2 for i, Oracle (checked by default) and Informix. |
| Export to SQL script: | Changes nothing at the source: the statements publishing would run are written to a script you download (pyymmddhhmm.txt), for a DBA to run. The tables appear on Publications once the script has run. |
What Grant access does, by source:
| Source | Statements run for each table |
|---|---|
| Db2 for i | GRTOBJAUT ... OBJTYPE(*FILE) AUT(*ALL) on the file and, once per library, GRTOBJAUT ... OBJTYPE(*LIB) AUT(*CHANGE), both to the agent user. A table that can't be granted (missing authority or a lock) is still published; the failure is written to the Control Center log. |
| Oracle | Adds supplemental logging if the table doesn't have it (ALTER TABLE ... ADD SUPPLEMENTAL LOG DATA, as set by the agent's supplementalLogging property), then GRANT SELECT to the agent user. |
| Informix | GRANT SELECT ... TO the agent user AS the table owner. |
Uncheck Grant access when the privileged user can't run these statements, or when you grant authority yourself (for example when you publish many Db2 for i tables at once and want to avoid the delay). For Oracle, unchecking it also skips the supplemental logging, so add it yourself.
Importing a list of tables¶
To publish many tables, list them in a text file:
SCHEMA1 TABLE1 TABLE
SCHEMA1 TABLE2 TABLE
SCHEMA2 ORDERS TABLE
- One table per line: schema, table name and the word
TABLE, separated by spaces, tabs or semicolons (the format of the Data Replicator Manager's Subscription Wizard). - Schema and table names must match the source exactly, including case.
- The file can be up to 10 MB.
In Add Publications, set Grant access and Export to SQL script as needed, click Import and submit the
file. A line in the wrong format stops the import with Invalid file format on line n. Tables that don't exist or are
already published are skipped: the Task List shows how many couldn't be imported, and each one is named in the
Jetty log (C:\ProgramData\StarQuest\sqdrplus\jetty\logs\wrapper.log).
Unpublishing tables¶
Delete Publication also deletes selected tables that a filter hides. The tables are removed from the catalog and
can't be added to new subscriptions while requirePublication is on; existing subscriptions aren't affected.
Viewing how tables are logged¶
The View Metadata file (mdyymmddhhmm.txt) has one line per table:
| Source | What's shown |
|---|---|
| Db2 for i | The journal (LIBRARY/JOURNAL) and whether it records *BOTH or *AFTER images, or Not Journaled. |
| Db2 LUW | The table's DATA CAPTURE setting. |
| SQL Server | Whether Change Tracking and Change Data Capture are on for the table. |
| Oracle | The supplemental log groups of the table. |
| Informix, MySQL, PostgreSQL | No metadata is available. |
Why publish¶
- Publishing is required when the agent property
requirePublicationistrue: for every new Oracle agent, and for another agent when you set it on its Configuration tab. - Oracle: publishing is the usual way to give the agent user (
SQDR) read access to the source tables and to add the supplemental logging the agent needs. - Db2 for i: publishing can grant the agent user authority to many tables at once.
- Other sources: for a central list of the tables that may be replicated.
Publishing and unpublishing affect only new subscriptions: existing subscriptions keep running when their table is unpublished.
When publishing is required, adding a subscription for a table that isn't published fails: the message says the
ADDSUBSCRIPTION stored procedure failed with "Subscription not allowed, Table not published". Publish the table
first (see Publishing tables), or ask whoever administers the Capture Agent to publish it.
PowerShell¶
The Capture PowerShell cmdlets list, publish and unpublish tables, for example in a script that sets up many agents.
They call the SQDR Manager API web application, installed with Stelo Capture in the Control Center's Jetty server. In
the examples, <folder> is the folder that holds the Capture PowerShell files (see
Script Capture Agents with PowerShell).
-
Load the module and sign in with a Control Center user:
Import-Module '<folder>\Tools\CapturePowerShell\CapturePowerShell.dll' Request-Login -BaseUrl 'http://localhost:8080' -UserId 'SQDR' -Password '<password>' -
List the tables in a JSON file:
{ "tables": [ { "schema": "MYSCHEMA", "name": "MYTABLE" } ], "grant": false } -
Run the cmdlet, naming the agent as it appears in the Control Center tree:
Add-Publication -Name 'MYDB%SQDR@myhost' -JsonFile '<folder>\examples\data\add-publication.json'
| Cmdlet | What it does |
|---|---|
Show-Publications -Name agent |
Lists the agent's publications. -Schema and -Table filter the list; -JsonFileOut file writes it to a JSON file instead. |
Add-Publication -Name agent -JsonFile file |
Publishes the tables in the file, like Finish in Add Publications. Each table must exist and not be published yet, with schema and name exactly as on the source; otherwise nothing is published and the cmdlet reports the table. |
Add-Publication ... -ScriptFileOut file |
Publishes nothing: writes the statements that publishing would run to file, like Export to SQL script:. |
Remove-Publication -Name agent -JsonFile file |
Unpublishes the tables in the file, like Delete Publication. Every table in the file must be published. |
"grant": true in the file grants the agent user access to the tables, like Grant access to "agent user":
(false when omitted). Every cmdlet also takes -BaseUrl (default http://127.0.0.1:8080) and
-TrustServerCertificate $true (to accept the server's certificate on an HTTPS address).
Related¶
- Configuration properties (
requirePublication,retryPublishLock,supplementalLogging) - Subscriptions
- Prepare an Oracle database and Prepare the IBM i