-- DBMS_LOGREP_EXP / DBMS_LOGREP_IMP compatibility coverage.
|
--
|
-- Oracle stand checks used here:
|
-- VERSION_VAR2_2_NUMBER('19.1.0.0.0') = 19.1
|
-- VERSION_VAR2_2_NUMBER('001.002.003') = 1.002003
|
-- VERSION_VAR2_2_NUMBER(NULL) = NULL
|
-- invalid version text raises a numeric conversion error.
|
|
CREATE FUNCTION pg_temp.caught_exception(command text)
|
RETURNS boolean
|
LANGUAGE plpgsql
|
AS $$
|
BEGIN
|
EXECUTE command;
|
RETURN false;
|
EXCEPTION WHEN OTHERS THEN
|
RETURN true;
|
END;
|
$$;
|
|
-- Test 1: DBMS_LOGREP_EXP.VERSION_VAR2_2_NUMBER keeps the first dot
|
-- as a decimal separator and removes subsequent dots.
|
-- Expected: values match Oracle behavior observed on the stand.
|
SELECT
|
dbms_logrep_exp_version_var2_2_number('19.1.0.0.0') AS version_19,
|
dbms_logrep_exp_version_var2_2_number('21.0.0.0.0') AS version_21,
|
dbms_logrep_exp_version_var2_2_number('12.2') AS version_12_2,
|
dbms_logrep_exp_version_var2_2_number('1') AS version_1,
|
dbms_logrep_exp_version_var2_2_number('001.002.003') AS version_leading_zeroes;
|
|
-- Test 2: NULL and empty string map to NULL, matching Oracle VARCHAR2 semantics.
|
-- Expected: both boolean flags are true.
|
SELECT
|
dbms_logrep_exp_version_var2_2_number(NULL) IS NULL AS null_version_is_null,
|
dbms_logrep_exp_version_var2_2_number('') IS NULL AS empty_version_is_null;
|
|
-- Test 3: invalid version text is rejected.
|
-- Expected: invalid_version_rejected = true.
|
SELECT pg_temp.caught_exception(
|
'SELECT dbms_logrep_exp_version_var2_2_number(''bad'')'
|
) AS invalid_version_rejected;
|
|
-- Test 4: DBMS_LOGREP_IMP import hooks are accepted as compatibility no-ops.
|
-- A fresh session has IS_IMPORT_INSTANTIATION false, so INSTANTIATE_SCHEMA
|
-- returns before CHECK_PRIVILEGES; tests 65-67 cover the gated path.
|
-- Expected: calls do not raise and the test reaches the boolean result.
|
DO $$
|
BEGIN
|
PERFORM dbms_logrep_imp_instantiate_schema(NULL, NULL, NULL);
|
PERFORM dbms_logrep_imp_instantiate_schema('NO_SUCH_SCHEMA_FOR_TEST', 'NO_SUCH_DB', 1);
|
PERFORM dbms_logrep_imp_bump_scn(NULL);
|
PERFORM dbms_logrep_imp_bump_scn(0);
|
END;
|
$$;
|
|
SELECT true AS logrep_imp_noop_hooks_completed;
|
|
-- Test 5: SQL-visible package entry points are registered.
|
-- Expected: all thirty-four functions exist in pg_catalog.
|
SELECT count(*) = 34 AS logrep_functions_registered
|
FROM pg_proc
|
WHERE pronamespace = 'pg_catalog'::regnamespace
|
AND proname IN (
|
'dbms_logrep_exp_version_var2_2_number',
|
'dbms_logrep_imp_bump_scn',
|
'dbms_logrep_imp_instantiate_schema',
|
'dbms_logrep_imp_set_import_mode',
|
'dbms_logrep_imp_is_import_configuration',
|
'dbms_logrep_imp_is_import_instantiation',
|
'dbms_logrep_imp_date_convert',
|
'dbms_logrep_imp_create_capture',
|
'dbms_logrep_imp_prepare_object',
|
'dbms_logrep_imp_prepare_ddl',
|
'dbms_logrep_imp_set_capture_param',
|
'dbms_logrep_imp_create_propagation',
|
'dbms_logrep_imp_create_apply',
|
'dbms_logrep_imp_apply_milestone',
|
'dbms_logrep_imp_apply_progress',
|
'dbms_logrep_imp_set_key_columns',
|
'dbms_logrep_imp_apply_error',
|
'dbms_logrep_imp_apply_error_txn',
|
'dbms_logrep_imp_start_queue',
|
'dbms_logrep_imp_start_capture',
|
'dbms_logrep_imp_start_apply',
|
'dbms_logrep_imp_instantiate',
|
'dbms_logrep_imp_create_sync_capture',
|
'dbms_logrep_imp_prepare_sync_object',
|
'dbms_logrep_imp_include_extra_attribute',
|
'dbms_logrep_imp_streams_rules',
|
'dbms_logrep_imp_privileged_user',
|
'dbms_logrep_imp_message_consumers',
|
'dbms_logrep_imp_message_rules',
|
'dbms_logrep_imp_set_apply_param',
|
'dbms_logrep_imp_set_apply_source_obj',
|
'dbms_logrep_imp_set_apply_source_schema',
|
'dbms_logrep_imp_set_dml_handler',
|
'dbms_logrep_imp_set_update_conflict_handler'
|
);
|
|
-- Test 6: import-mode defaults are asymmetric in a fresh session.
|
-- Oracle: IMPORT_INSTANTIATION := FALSE, IMPORT_CONFIGURATION := TRUE.
|
-- Expected: configuration_default = true, instantiation_default = false.
|
SELECT
|
dbms_logrep_imp_is_import_configuration() AS configuration_default,
|
dbms_logrep_imp_is_import_instantiation() AS instantiation_default;
|
|
-- Test 7: each of the four documented modes sets both flags.
|
-- MODE_ALL=1, MODE_NONE=2, MODE_INSTANTIATION_ONLY=3, MODE_CONFIGURATION_ONLY=4.
|
-- Expected: one row per mode, flags as in the Oracle package body.
|
SELECT dbms_logrep_imp_set_import_mode(1);
|
SELECT
|
1 AS mode,
|
dbms_logrep_imp_is_import_configuration() AS is_configuration,
|
dbms_logrep_imp_is_import_instantiation() AS is_instantiation;
|
|
SELECT dbms_logrep_imp_set_import_mode(2);
|
SELECT
|
2 AS mode,
|
dbms_logrep_imp_is_import_configuration() AS is_configuration,
|
dbms_logrep_imp_is_import_instantiation() AS is_instantiation;
|
|
SELECT dbms_logrep_imp_set_import_mode(3);
|
SELECT
|
3 AS mode,
|
dbms_logrep_imp_is_import_configuration() AS is_configuration,
|
dbms_logrep_imp_is_import_instantiation() AS is_instantiation;
|
|
SELECT dbms_logrep_imp_set_import_mode(4);
|
SELECT
|
4 AS mode,
|
dbms_logrep_imp_is_import_configuration() AS is_configuration,
|
dbms_logrep_imp_is_import_instantiation() AS is_instantiation;
|
|
-- Test 8: the Oracle IF/ELSIF chain has no ELSE branch, so an unrecognized
|
-- or NULL mode leaves the session state untouched rather than raising.
|
-- State on entry is MODE_CONFIGURATION_ONLY from test 7.
|
-- Expected: is_configuration = true, is_instantiation = false in both rows.
|
SELECT dbms_logrep_imp_set_import_mode(NULL);
|
SELECT
|
dbms_logrep_imp_is_import_configuration() AS is_configuration_after_null,
|
dbms_logrep_imp_is_import_instantiation() AS is_instantiation_after_null;
|
|
SELECT dbms_logrep_imp_set_import_mode(99);
|
SELECT
|
dbms_logrep_imp_is_import_configuration() AS is_configuration_after_unknown,
|
dbms_logrep_imp_is_import_instantiation() AS is_instantiation_after_unknown;
|
|
-- Test 9: DATE_CONVERT keeps the time component. Oracle returns DATE, which
|
-- carries a time; plain PostgreSQL to_date() would truncate it.
|
-- Expected: full_timestamp = true, date_only = true, both NULL flags true.
|
SELECT
|
dbms_logrep_imp_date_convert('2024-01-01 13:45:59', 'YYYY-MM-DD HH24:MI:SS')
|
= timestamp '2024-01-01 13:45:59' AS full_timestamp,
|
dbms_logrep_imp_date_convert('2024-01-01', 'YYYY-MM-DD')
|
= timestamp '2024-01-01 00:00:00' AS date_only,
|
dbms_logrep_imp_date_convert(NULL, 'YYYY-MM-DD') IS NULL AS null_day_is_null,
|
dbms_logrep_imp_date_convert('2024-01-01', NULL) IS NULL AS null_format_is_null;
|
|
-- Test 10: unparsable input is rejected.
|
-- Expected: bad_date_rejected = true.
|
SELECT pg_temp.caught_exception(
|
'SELECT dbms_logrep_imp_date_convert(''not-a-date'', ''YYYY-MM-DD HH24:MI:SS'')'
|
) AS bad_date_rejected;
|
|
-- Test 11: the exact call text DBMS_LOGREP_EXP emits for start_date/end_date,
|
-- including the space after the opening parenthesis. This breaks if the
|
-- signature ever drifts from what a real export dump contains.
|
SELECT dbms_logrep_imp_date_convert( '2026-09-21 14:09:00','YYYY-MM-DD HH24:MI:SS')
|
AS exp_emitted_date_convert;
|
|
-- Test 12: the Phase 1 catalog tables exist. Each one mirrors an Oracle
|
-- DBA_/_DBA_ view that DBMS_LOGREP_EXP reads back out.
|
SELECT c.relname
|
FROM pg_class c
|
JOIN pg_namespace n ON n.oid = c.relnamespace
|
WHERE n.nspname = 'pg_catalog'
|
AND c.relkind = 'r'
|
AND c.relname LIKE 'dbms\_logrep\_%'
|
ORDER BY 1;
|
|
-- Test 13: every catalog table carries exactly one unique constraint and it is
|
-- NULLS NOT DISTINCT. DBMS_LOGREP_EXP legitimately emits NULL key parts --
|
-- prepare_ddl(schema_name=>null) is the database-level row -- so plain NULL
|
-- semantics would let a replayed dump insert duplicates.
|
SELECT c.relname, i.indisunique, i.indnullsnotdistinct
|
FROM pg_class c
|
JOIN pg_namespace n ON n.oid = c.relnamespace
|
JOIN pg_index i ON i.indrelid = c.oid
|
WHERE n.nspname = 'pg_catalog'
|
AND c.relkind = 'r'
|
AND c.relname LIKE 'dbms\_logrep\_%'
|
ORDER BY 1;
|
|
-- Test 14: replaying the same call twice leaves one row even when the whole key
|
-- is NULL. Rolled back so the catalog is left untouched.
|
--
|
-- ON CONFLICT cannot be used here: the tables are created during initdb, so
|
-- IsCatalogRelation() treats them as system catalogs and the parser rejects the
|
-- clause outright (src/backend/parser/parse_clause.c:3321-3326). The port uses
|
-- the WHERE NOT EXISTS guard below instead, and IS NOT DISTINCT FROM reproduces
|
-- the NULLS NOT DISTINCT semantics of the unique constraint.
|
-- Expected: database_level_rows = 1.
|
BEGIN;
|
INSERT INTO pg_catalog.dbms_logrep_prepared_schemas(schema_name, flags)
|
VALUES (NULL, 15);
|
INSERT INTO pg_catalog.dbms_logrep_prepared_schemas(schema_name, flags)
|
SELECT NULL, 15
|
WHERE NOT EXISTS (SELECT 1 FROM pg_catalog.dbms_logrep_prepared_schemas
|
WHERE schema_name IS NOT DISTINCT FROM NULL);
|
SELECT count(*) AS database_level_rows FROM pg_catalog.dbms_logrep_prepared_schemas;
|
ROLLBACK;
|
|
-- Test 14a: the clause the port cannot use, asserted explicitly so the reason
|
-- is recorded rather than rediscovered.
|
-- Expected: on_conflict_rejected_on_catalog_table = true.
|
SELECT pg_temp.caught_exception(
|
'INSERT INTO pg_catalog.dbms_logrep_prepared_schemas(schema_name, flags)
|
VALUES (NULL, 15) ON CONFLICT DO NOTHING'
|
) AS on_conflict_rejected_on_catalog_table;
|
|
-- Tests 15-19 cover DBMS_LOGREP_IMP.CREATE_CAPTURE. Each one runs inside a
|
-- transaction that is rolled back, so the shared catalog is left untouched.
|
|
-- Test 15: the call text a real DBMS_LOGREP_EXP dump contains -- named
|
-- parameters, Oracle-canonical (upper-case) identifiers and the nested
|
-- date_convert() calls (SYS.DBMS_LOGREP_EXP.pls:631-647).
|
-- Expected: one row, identifiers folded to lower case, use_database_link and
|
-- logfile_assignment stored in the form EXP reads back.
|
BEGIN;
|
SELECT dbms_logrep_imp_create_capture(queue_owner=>'STRMADMIN', queue_name=>'STREAMS_QUEUE', capture_name=>'CAPTURE_HR', ruleset_owner=>'STRMADMIN', ruleset_name=>'RULESET$_1', capture_username=>'STRMADMIN', source_database=>'ORCL.EXAMPLE.COM', use_database_link=>'NO', logfile_assignment=>'IMPLICIT', negative_ruleset_owner=>'STRMADMIN', negative_ruleset_name=>'RULESET$_2', i_customer_id=>0, start_date=> dbms_logrep_imp_date_convert('2024-01-01 00:00:00','YYYY-MM-DD HH24:MI:SS') , end_date=> dbms_logrep_imp_date_convert('2024-12-31 23:59:59','YYYY-MM-DD HH24:MI:SS') );
|
|
SELECT capture_name, queue_owner, queue_name, ruleset_owner, ruleset_name,
|
capture_username, start_date, end_date, source_database,
|
logfile_assignment, use_database_link,
|
negative_ruleset_owner, negative_ruleset_name, i_customer_id,
|
synchronous, status, slot_name
|
FROM pg_catalog.dbms_logrep_capture;
|
ROLLBACK;
|
|
-- Test 16: replaying the same dump line twice leaves one row. Oracle swallows
|
-- ORA-26665 (STREAMS_PROCESS_ALREADY_EXISTS); here it is the WHERE NOT EXISTS
|
-- guard built by LogrepCatalog::Insert::conflictKey (see test 14 for why
|
-- ON CONFLICT is unavailable on these tables).
|
-- Expected: capture_rows = 1.
|
BEGIN;
|
SELECT dbms_logrep_imp_create_capture('STRMADMIN', 'STREAMS_QUEUE', 'CAPTURE_HR',
|
NULL, NULL, 'STRMADMIN');
|
SELECT dbms_logrep_imp_create_capture('STRMADMIN', 'STREAMS_QUEUE', 'CAPTURE_HR',
|
NULL, NULL, 'STRMADMIN');
|
SELECT count(*) AS capture_rows FROM pg_catalog.dbms_logrep_capture;
|
ROLLBACK;
|
|
-- Test 17: with IS_IMPORT_CONFIGURATION false the procedure returns before
|
-- touching anything (SYS.DBMS_LOGREP_IMP.pls:545-547). MODE_NONE = 2.
|
-- Expected: capture_rows_when_disabled = 0.
|
BEGIN;
|
SELECT dbms_logrep_imp_set_import_mode(2);
|
SELECT dbms_logrep_imp_create_capture('STRMADMIN', 'STREAMS_QUEUE', 'CAPTURE_HR',
|
NULL, NULL, 'STRMADMIN');
|
SELECT count(*) AS capture_rows_when_disabled FROM pg_catalog.dbms_logrep_capture;
|
ROLLBACK;
|
|
-- Session state is package state in Oracle: it survives ROLLBACK. Restore the
|
-- default that the remaining tests rely on.
|
SELECT dbms_logrep_imp_set_import_mode(4);
|
|
-- Test 18: a name pair is gated on its owner alone. With a NULL ruleset_owner
|
-- Oracle leaves the composite RULESET NULL and loses ruleset_name even when it
|
-- was supplied (SYS.DBMS_LOGREP_IMP.pls:555-557).
|
-- Expected: both ruleset columns NULL, both negative_ruleset columns NULL.
|
BEGIN;
|
SELECT dbms_logrep_imp_create_capture(
|
queue_owner=>'STRMADMIN', queue_name=>'STREAMS_QUEUE',
|
capture_name=>'CAPTURE_HR',
|
ruleset_owner=>NULL, ruleset_name=>'RULESET$_1',
|
capture_username=>'STRMADMIN',
|
negative_ruleset_owner=>NULL, negative_ruleset_name=>'RULESET$_2');
|
SELECT ruleset_owner IS NULL AS ruleset_owner_null,
|
ruleset_name IS NULL AS ruleset_name_dropped,
|
negative_ruleset_name IS NULL AS negative_ruleset_name_dropped
|
FROM pg_catalog.dbms_logrep_capture;
|
ROLLBACK;
|
|
-- Test 19: the parameters Oracle validates before recording anything
|
-- (SYS.DBMS_CAPTURE_ADM_INTERNAL.pls:605-615).
|
-- Expected: all three flags true.
|
SELECT
|
pg_temp.caught_exception(
|
'SELECT dbms_logrep_imp_create_capture(NULL, ''Q'', ''C'', NULL, NULL, ''U'')'
|
) AS null_queue_owner_rejected,
|
pg_temp.caught_exception(
|
'SELECT dbms_logrep_imp_create_capture(''S'', NULL, ''C'', NULL, NULL, ''U'')'
|
) AS null_queue_name_rejected,
|
pg_temp.caught_exception(
|
'SELECT dbms_logrep_imp_create_capture(''S'', ''Q'', NULL, NULL, NULL, ''U'')'
|
) AS null_capture_name_rejected;
|
|
-- Tests 20-24 cover DBMS_LOGREP_IMP.PREPARE_OBJECT. As above, each one runs
|
-- inside a transaction that is rolled back.
|
|
-- Test 20: the call text a real DBMS_LOGREP_EXP dump contains -- named
|
-- parameters, Oracle-canonical (upper-case) identifiers and the supplemental
|
-- logging bitmask built by the C_PREPARE_OBJECT cursor
|
-- (SYS.DBMS_LOGREP_EXP.pls:146-156, :687-695). flags => 15 is
|
-- SUPPLOG_PK + SUPPLOG_UI + SUPPLOG_FK + SUPPLOG_ALL.
|
-- Expected: one row, identifiers folded to lower case, flags stored verbatim.
|
BEGIN;
|
SELECT dbms_logrep_imp_prepare_object(table_owner=>'HR', table_name=>'EMPLOYEES', flags=>15);
|
SELECT table_owner, table_name, flags
|
FROM pg_catalog.dbms_logrep_prepared_tables;
|
ROLLBACK;
|
|
-- Test 21: NVL(FLAGS, 0) (SYS.DBMS_LOGREP_IMP.pls:653). An omitted flags is
|
-- the pre-10.2 export path -- DBMS_LOGREP_EXP appends the parameter only when
|
-- NUM_VERSION >= DB_EXPORT_VERSION102 (SYS.DBMS_LOGREP_EXP.pls:691-693) -- and
|
-- an explicit NULL reaches the body the same way. Both must store 0.
|
-- Expected: two rows, flags = 0 in each, no NULLs.
|
BEGIN;
|
SELECT dbms_logrep_imp_prepare_object('HR', 'DEPARTMENTS');
|
SELECT dbms_logrep_imp_prepare_object('HR', 'JOBS', NULL);
|
SELECT table_owner, table_name, flags
|
FROM pg_catalog.dbms_logrep_prepared_tables
|
ORDER BY table_name;
|
ROLLBACK;
|
|
-- Test 22: replaying the same dump line twice leaves one row. Oracle has no
|
-- exception handler here, but the table carries UNIQUE NULLS NOT DISTINCT, so
|
-- the port guards the insert with WHERE NOT EXISTS (see test 14 for why
|
-- ON CONFLICT is unavailable on these tables).
|
-- Expected: prepared_tables_rows = 1.
|
BEGIN;
|
SELECT dbms_logrep_imp_prepare_object('HR', 'EMPLOYEES', 15);
|
SELECT dbms_logrep_imp_prepare_object('HR', 'EMPLOYEES', 15);
|
SELECT count(*) AS prepared_tables_rows
|
FROM pg_catalog.dbms_logrep_prepared_tables;
|
ROLLBACK;
|
|
-- Test 23: with IS_IMPORT_CONFIGURATION false the procedure returns before
|
-- touching anything (SYS.DBMS_LOGREP_IMP.pls:644-646). MODE_NONE = 2.
|
-- Expected: prepared_tables_rows_when_disabled = 0.
|
BEGIN;
|
SELECT dbms_logrep_imp_set_import_mode(2);
|
SELECT dbms_logrep_imp_prepare_object('HR', 'EMPLOYEES', 15);
|
SELECT count(*) AS prepared_tables_rows_when_disabled
|
FROM pg_catalog.dbms_logrep_prepared_tables;
|
ROLLBACK;
|
|
-- Session state is package state in Oracle: it survives ROLLBACK. Restore the
|
-- default that the remaining tests rely on.
|
SELECT dbms_logrep_imp_set_import_mode(4);
|
|
-- Test 24: a NULL table name is recorded rather than rejected. Oracle never
|
-- reaches this case -- VALIDATE_PREPARE_TABLE ("knlIsPreObj",
|
-- SYS.DBMS_CAPTURE_ADM_INTERNAL.pls:1574-1583) checks the name against a real
|
-- table -- but the metadata-only port has nothing to validate against, so it
|
-- stores what the dump said and relies on NULLS NOT DISTINCT for idempotency.
|
-- Expected: null_named_rows = 1 after two identical calls.
|
BEGIN;
|
SELECT dbms_logrep_imp_prepare_object(NULL, NULL, 15);
|
SELECT dbms_logrep_imp_prepare_object(NULL, NULL, 15);
|
SELECT count(*) AS null_named_rows
|
FROM pg_catalog.dbms_logrep_prepared_tables;
|
ROLLBACK;
|
|
-- Tests 25-29 cover DBMS_LOGREP_IMP.PREPARE_DDL. As above, each one runs
|
-- inside a transaction that is rolled back.
|
|
-- Test 25: the schema-level call text a real DBMS_LOGREP_EXP dump contains.
|
-- It is the first branch of the C_PREPARE_DDL union, over
|
-- DBA_CAPTURE_PREPARED_SCHEMAS (SYS.DBMS_LOGREP_EXP.pls:162-172, :744-750).
|
-- flags => 15 is SUPPLOG_PK + SUPPLOG_UI + SUPPLOG_FK + SUPPLOG_ALL.
|
-- Expected: one row, identifier folded to lower case, flags stored verbatim.
|
BEGIN;
|
SELECT dbms_logrep_imp_prepare_ddl(schema_name=>'HR', flags=>15);
|
SELECT schema_name, flags
|
FROM pg_catalog.dbms_logrep_prepared_schemas;
|
ROLLBACK;
|
|
-- Test 26: the database-level call. The second branch of the same union reads
|
-- DBA_CAPTURE_PREPARED_DATABASE and selects the constant '' into SCHEMA_NAME
|
-- (SYS.DBMS_LOGREP_EXP.pls:173-183), which ADD_SINGLE_QUOTE (:562-565) emits as
|
-- schema_name=>''. In Oracle that literal is NULL; in rudb it is a zero-length
|
-- string, so the port maps it back (see emptyAsNull). Both spellings must name
|
-- the same single row -- otherwise the database level would have two of them.
|
-- Expected: database_level_rows = 1 and stored_as_null = 1.
|
BEGIN;
|
SELECT dbms_logrep_imp_prepare_ddl(schema_name=>'', flags=>15);
|
SELECT dbms_logrep_imp_prepare_ddl(schema_name=>NULL, flags=>15);
|
SELECT count(*) AS database_level_rows,
|
count(*) FILTER (WHERE schema_name IS NULL) AS stored_as_null
|
FROM pg_catalog.dbms_logrep_prepared_schemas;
|
ROLLBACK;
|
|
-- Test 27: an absent flags. Unlike PREPARE_OBJECT the Oracle body applies no
|
-- NVL -- FLAGS reaches DBMS_LOGREP_IMP_INTERNAL.PREPARE_DDL unchanged
|
-- (SYS.DBMS_LOGREP_IMP.pls:695) -- but the round trip is what is observable,
|
-- and EXP rebuilds the mask with DECODE over SUPPLEMENTAL_LOG_DATA_*, which
|
-- yields 0 rather than an empty value. An omitted flags is the pre-10.2 export
|
-- path (SYS.DBMS_LOGREP_EXP.pls:748-750); an explicit NULL reaches the body the
|
-- same way. Both must store 0.
|
-- Expected: two rows, flags = 0 in each, no NULLs.
|
BEGIN;
|
SELECT dbms_logrep_imp_prepare_ddl('HR');
|
SELECT dbms_logrep_imp_prepare_ddl('OE', NULL);
|
SELECT schema_name, flags
|
FROM pg_catalog.dbms_logrep_prepared_schemas
|
ORDER BY schema_name;
|
ROLLBACK;
|
|
-- Test 28: replaying the same dump line twice leaves one row. Here the Oracle
|
-- original says so itself -- the body swallows DUP_VAL_ON_INDEX
|
-- (SYS.DBMS_LOGREP_IMP.pls:696-698). The port gets the same effect from
|
-- WHERE NOT EXISTS (see test 14 for why ON CONFLICT is unavailable on these
|
-- tables).
|
-- Expected: prepared_schemas_rows = 1.
|
BEGIN;
|
SELECT dbms_logrep_imp_prepare_ddl('HR', 15);
|
SELECT dbms_logrep_imp_prepare_ddl('HR', 15);
|
SELECT count(*) AS prepared_schemas_rows
|
FROM pg_catalog.dbms_logrep_prepared_schemas;
|
ROLLBACK;
|
|
-- Test 29: with IS_IMPORT_CONFIGURATION false the procedure returns before
|
-- touching anything (SYS.DBMS_LOGREP_IMP.pls:687-689). MODE_NONE = 2.
|
-- Expected: prepared_schemas_rows_when_disabled = 0.
|
BEGIN;
|
SELECT dbms_logrep_imp_set_import_mode(2);
|
SELECT dbms_logrep_imp_prepare_ddl('HR', 15);
|
SELECT count(*) AS prepared_schemas_rows_when_disabled
|
FROM pg_catalog.dbms_logrep_prepared_schemas;
|
ROLLBACK;
|
|
-- Session state is package state in Oracle: it survives ROLLBACK. Restore the
|
-- default that the remaining tests rely on.
|
SELECT dbms_logrep_imp_set_import_mode(4);
|
|
-- Tests 30-35 cover DBMS_LOGREP_IMP.SET_CAPTURE_PARAM. As above, each one runs
|
-- inside a transaction that is rolled back.
|
|
-- Test 30: the call text a real DBMS_LOGREP_EXP dump contains. One line per
|
-- row of DBA_CAPTURE_PARAMETERS with SET_BY_USER = 'YES' (C_CAPTURE_PARAM,
|
-- SYS.DBMS_LOGREP_EXP.pls:185-193; emitter :777-782), Oracle-canonical
|
-- upper-case names. set_by_user is not a parameter of the procedure: every
|
-- call through it is by definition user-set, and that is the column default.
|
-- Expected: one row, both names folded to lower case, value verbatim,
|
-- set_by_user = t.
|
BEGIN;
|
SELECT dbms_logrep_imp_set_capture_param(capture_name=>'CAPTURE_HR',
|
parameter_name=>'PARALLELISM',
|
parameter_value=>'4');
|
SELECT capture_name, parameter, value, set_by_user
|
FROM pg_catalog.dbms_logrep_capture_params;
|
ROLLBACK;
|
|
-- Test 31: the value is a value, not a name. Unlike capture_name and
|
-- parameter it is never canonicalized -- Oracle passes it to
|
-- DBMS_CAPTURE_ADM.SET_PARAMETER unquoted and unchanged
|
-- (SYS.DBMS_LOGREP_IMP.pls:720), and a folded 'Y' or 'IMPLICIT' would come back
|
-- out of the export wrong.
|
-- Expected: both values keep their upper case.
|
BEGIN;
|
SELECT dbms_logrep_imp_set_capture_param('CAPTURE_HR', 'DISABLE_ON_LIMIT', 'Y');
|
SELECT dbms_logrep_imp_set_capture_param('CAPTURE_HR', 'MESSAGE_TRACKING_FREQUENCY', 'IMPLICIT');
|
SELECT parameter, value
|
FROM pg_catalog.dbms_logrep_capture_params
|
ORDER BY parameter;
|
ROLLBACK;
|
|
-- Test 32: last write wins. This is where SET_CAPTURE_PARAM parts company with
|
-- its neighbours (tests 14, 22, 28, which all keep the first row): Oracle's
|
-- delegate is DBMS_CAPTURE_ADM.SET_PARAMETER, a setter, so a second call with a
|
-- different value leaves the second value. That is also why the Oracle body
|
-- carries no DUP_VAL_ON_INDEX handler -- there is no insert to collide.
|
-- Expected: capture_params_rows = 1 and value = 8.
|
BEGIN;
|
SELECT dbms_logrep_imp_set_capture_param('CAPTURE_HR', 'PARALLELISM', '4');
|
SELECT dbms_logrep_imp_set_capture_param('CAPTURE_HR', 'PARALLELISM', '8');
|
SELECT count(*) AS capture_params_rows, max(value) AS value
|
FROM pg_catalog.dbms_logrep_capture_params;
|
ROLLBACK;
|
|
-- Test 33: the key is case-insensitive, because the parameter name is folded
|
-- like every other name in the port. Oracle keeps it upper-case -- it passes
|
-- the name double-quoted (SYS.DBMS_LOGREP_IMP.pls:719) -- so the two spellings
|
-- would be two distinct parameters there; here they are one row.
|
-- Expected: capture_params_rows = 1, parameter = parallelism, value = 8.
|
BEGIN;
|
SELECT dbms_logrep_imp_set_capture_param('CAPTURE_HR', 'PARALLELISM', '4');
|
SELECT dbms_logrep_imp_set_capture_param('capture_hr', 'parallelism', '8');
|
SELECT count(*) AS capture_params_rows, max(parameter) AS parameter, max(value) AS value
|
FROM pg_catalog.dbms_logrep_capture_params;
|
ROLLBACK;
|
|
-- Test 34: NULL tolerance. A NULL value is stored as it came: in Oracle it
|
-- resets the parameter to its default, after which the row drops out of the
|
-- export cursor's SET_BY_USER = 'YES' filter, but rudb stores no defaults and a
|
-- real dump never emits one. A NULL capture_name is not rejected either --
|
-- nothing is validated here, the check is external C in Oracle
|
-- (SYS.DBMS_LOGREP_UTIL.pls:1883-1902). Replaying both leaves them alone.
|
-- Expected: capture_params_rows = 2, null_valued = 2.
|
BEGIN;
|
SELECT dbms_logrep_imp_set_capture_param('CAPTURE_HR', 'TRACE_LEVEL', NULL);
|
SELECT dbms_logrep_imp_set_capture_param('CAPTURE_HR', 'TRACE_LEVEL', NULL);
|
SELECT dbms_logrep_imp_set_capture_param(NULL, NULL, NULL);
|
SELECT dbms_logrep_imp_set_capture_param(NULL, NULL, NULL);
|
SELECT count(*) AS capture_params_rows,
|
count(*) FILTER (WHERE value IS NULL) AS null_valued
|
FROM pg_catalog.dbms_logrep_capture_params;
|
ROLLBACK;
|
|
-- Test 35: with IS_IMPORT_CONFIGURATION false the procedure returns before
|
-- touching anything (SYS.DBMS_LOGREP_IMP.pls:713-715). MODE_NONE = 2.
|
-- Expected: capture_params_rows_when_disabled = 0.
|
BEGIN;
|
SELECT dbms_logrep_imp_set_import_mode(2);
|
SELECT dbms_logrep_imp_set_capture_param('CAPTURE_HR', 'PARALLELISM', '4');
|
SELECT count(*) AS capture_params_rows_when_disabled
|
FROM pg_catalog.dbms_logrep_capture_params;
|
ROLLBACK;
|
|
-- Session state is package state in Oracle: it survives ROLLBACK. Restore the
|
-- default that the remaining tests rely on.
|
SELECT dbms_logrep_imp_set_import_mode(4);
|
|
-- Test 36: the line DBMS_LOGREP_EXP emits for a modern dump
|
-- (SYS.DBMS_LOGREP_EXP.pls:843-862): ten named arguments plus queue_to_queue,
|
-- which the exporter adds only when it is TRUE. Every name is folded to lower
|
-- case; dest_dblink is the one exception (see the comment at the call site).
|
-- Expected: one row, names lower-cased, dblink verbatim, queue_to_queue = t.
|
BEGIN;
|
SELECT dbms_logrep_imp_create_propagation(
|
propagation_name=>'PROP_HR', src_queue_owner=>'STRMADMIN',
|
src_queue_name=>'Q_SRC', dest_queue_owner=>'STRMADMIN',
|
dest_queue_name=>'Q_DEST', dest_dblink=>'ORCL.EXAMPLE.COM',
|
ruleset_owner=>'STRMADMIN', ruleset_name=>'RS_POS',
|
negative_ruleset_owner=>'STRMADMIN', negative_ruleset_name=>'RS_NEG',
|
queue_to_queue=>true);
|
SELECT propagation_name, src_queue_owner, src_queue_name, dest_queue_owner,
|
dest_queue_name, dest_dblink, ruleset_owner, ruleset_name,
|
negative_ruleset_owner, negative_ruleset_name, queue_to_queue
|
FROM pg_catalog.dbms_logrep_propagation;
|
ROLLBACK;
|
|
-- Test 37: the pre-10.2 dump shape. DBMS_LOGREP_EXP omits negative_ruleset_*
|
-- below DB_EXPORT_VERSION100 and queue_to_queue below DB_EXPORT_VERSION102
|
-- (SYS.DBMS_LOGREP_EXP.pls:851-860), so the spec defaults must supply them
|
-- (SYS.DBMS_LOGREP_IMP.pls:84-87).
|
-- Expected: negative ruleset both NULL, queue_to_queue = f.
|
BEGIN;
|
SELECT dbms_logrep_imp_create_propagation(
|
propagation_name=>'PROP_OLD', src_queue_owner=>'STRMADMIN',
|
src_queue_name=>'Q_SRC', dest_queue_owner=>'STRMADMIN',
|
dest_queue_name=>'Q_DEST', dest_dblink=>'ORCL.EXAMPLE.COM',
|
ruleset_owner=>'STRMADMIN', ruleset_name=>'RS_POS');
|
SELECT propagation_name, negative_ruleset_owner, negative_ruleset_name,
|
queue_to_queue
|
FROM pg_catalog.dbms_logrep_propagation;
|
ROLLBACK;
|
|
-- Test 38: a NULL owner leaves the composite name NULL and so loses the name
|
-- half as well (SYS.DBMS_LOGREP_IMP.pls:808-820). The same rule CREATE_CAPTURE
|
-- already follows, applied here to all four owner/name pairs.
|
-- Expected: src_queue_name and negative_ruleset_name are NULL although both
|
-- were supplied.
|
BEGIN;
|
SELECT dbms_logrep_imp_create_propagation(
|
propagation_name=>'PROP_PARTIAL', src_queue_owner=>NULL,
|
src_queue_name=>'Q_SRC', dest_queue_owner=>'STRMADMIN',
|
dest_queue_name=>'Q_DEST', dest_dblink=>NULL,
|
ruleset_owner=>'STRMADMIN', ruleset_name=>'RS_POS',
|
negative_ruleset_owner=>NULL, negative_ruleset_name=>'RS_NEG');
|
SELECT src_queue_owner, src_queue_name, dest_queue_name,
|
ruleset_name, negative_ruleset_owner, negative_ruleset_name
|
FROM pg_catalog.dbms_logrep_propagation;
|
ROLLBACK;
|
|
-- Test 39: replaying a dump twice. Oracle swallows -23600
|
-- (PROPAGATION_ALREADY_EXISTS, SYS.DBMS_LOGREP_IMP.pls:822-824), so the second
|
-- call does nothing at all -- it does not overwrite, unlike SET_CAPTURE_PARAM
|
-- in test 32.
|
-- Expected: one row, holding the dblink from the FIRST call.
|
BEGIN;
|
SELECT dbms_logrep_imp_create_propagation(
|
'PROP_HR', 'STRMADMIN', 'Q_SRC', 'STRMADMIN', 'Q_DEST',
|
'FIRST.EXAMPLE.COM', 'STRMADMIN', 'RS_POS');
|
SELECT dbms_logrep_imp_create_propagation(
|
'PROP_HR', 'STRMADMIN', 'Q_SRC', 'STRMADMIN', 'Q_DEST',
|
'SECOND.EXAMPLE.COM', 'STRMADMIN', 'RS_POS');
|
SELECT count(*) AS propagation_rows, min(dest_dblink) AS surviving_dblink
|
FROM pg_catalog.dbms_logrep_propagation;
|
ROLLBACK;
|
|
-- Test 40: NULL tolerance. queue_to_queue keeps a NULL rather than collapsing
|
-- to false, and a NULL dest_dblink is the local channel DBMS_LOGREP_EXP writes
|
-- for 'AQ$_LOCAL' (SYS.DBMS_LOGREP_EXP.pls:836-841). The key is the one thing
|
-- that may not be NULL.
|
-- Expected: one row with both columns NULL, then ORA-23605.
|
BEGIN;
|
SELECT dbms_logrep_imp_create_propagation(
|
propagation_name=>'PROP_LOCAL', src_queue_owner=>'STRMADMIN',
|
src_queue_name=>'Q_SRC', dest_queue_owner=>'STRMADMIN',
|
dest_queue_name=>'Q_DEST', dest_dblink=>NULL,
|
ruleset_owner=>'STRMADMIN', ruleset_name=>'RS_POS',
|
queue_to_queue=>NULL);
|
SELECT dest_dblink IS NULL AS dblink_is_null,
|
queue_to_queue IS NULL AS queue_to_queue_is_null
|
FROM pg_catalog.dbms_logrep_propagation;
|
SELECT dbms_logrep_imp_create_propagation(
|
NULL, 'STRMADMIN', 'Q_SRC', 'STRMADMIN', 'Q_DEST',
|
NULL, 'STRMADMIN', 'RS_POS');
|
ROLLBACK;
|
|
-- Test 41: with IS_IMPORT_CONFIGURATION false the procedure returns before
|
-- touching anything (SYS.DBMS_LOGREP_IMP.pls:801-803). MODE_NONE = 2.
|
-- Expected: propagation_rows_when_disabled = 0.
|
BEGIN;
|
SELECT dbms_logrep_imp_set_import_mode(2);
|
SELECT dbms_logrep_imp_create_propagation(
|
'PROP_HR', 'STRMADMIN', 'Q_SRC', 'STRMADMIN', 'Q_DEST',
|
'ORCL.EXAMPLE.COM', 'STRMADMIN', 'RS_POS');
|
SELECT count(*) AS propagation_rows_when_disabled
|
FROM pg_catalog.dbms_logrep_propagation;
|
ROLLBACK;
|
|
-- Session state is package state in Oracle: it survives ROLLBACK. Restore the
|
-- default that the remaining tests rely on.
|
SELECT dbms_logrep_imp_set_import_mode(4);
|
|
-- Test 42: the line DBMS_LOGREP_EXP emits for a modern dump
|
-- (SYS.DBMS_LOGREP_EXP.pls:1121-1166): every argument named, dates through
|
-- date_convert, i_customer_id quoted. Names are folded to lower case;
|
-- apply_dblink and apply_tag are stored verbatim.
|
-- Expected: one row, apply_captured = 1, dates set, error fields NULL.
|
BEGIN;
|
SELECT dbms_logrep_imp_create_apply(apply_name=>'APPLY_HR', queue_owner=>'STRMADMIN', queue_name=>'STREAMS_QUEUE', apply_captured=>1, ruleset_owner=>'STRMADMIN', ruleset_name=>'RULESET$_3', apply_user=>'STRMADMIN', apply_dblink=>'ORCL.Example.COM', apply_tag=>'00AB', ddl_handler=>'STRMADMIN.DDL_H', message_handler=>'STRMADMIN.MSG_H', precommit_handler=>'STRMADMIN.PRE_H', negative_ruleset_owner=>'STRMADMIN', negative_ruleset_name=>'RULESET$_4', error_number=>NULL, error_message=>NULL , start_date=> dbms_logrep_imp_date_convert('2024-01-01 00:00:00','YYYY-MM-DD HH24:MI:SS') , end_date=> dbms_logrep_imp_date_convert('2024-12-31 23:59:59','YYYY-MM-DD HH24:MI:SS') , i_customer_id=>'0', uan_handler=>'STRMADMIN.UAN_H', ua_ruleset_owner=>'STRMADMIN', ua_ruleset_name=>'RULESET$_5');
|
SELECT apply_name, queue_owner, queue_name, apply_captured, ruleset_owner,
|
ruleset_name, apply_user, apply_dblink, apply_tag, ddl_handler,
|
message_handler, precommit_handler, start_date, end_date,
|
negative_ruleset_owner, negative_ruleset_name, error_number,
|
error_message, i_customer_id, uan_handler, ua_ruleset_owner,
|
ua_ruleset_name, status
|
FROM pg_catalog.dbms_logrep_apply;
|
ROLLBACK;
|
|
-- Test 43: the pre-10.0 dump shape. DBMS_LOGREP_EXP emits only the first
|
-- eleven arguments below DB_EXPORT_VERSION100 (SYS.DBMS_LOGREP_EXP.pls:1134),
|
-- so the spec defaults must supply the rest (SYS.DBMS_LOGREP_IMP.pls:142-152).
|
-- Expected: optional columns NULL, i_customer_id = 0.
|
BEGIN;
|
SELECT dbms_logrep_imp_create_apply(
|
'APPLY_OLD', 'STRMADMIN', 'STREAMS_QUEUE', 0, 'STRMADMIN',
|
'RULESET$_3', 'STRMADMIN', NULL, NULL, NULL, NULL);
|
SELECT apply_name, apply_captured, precommit_handler, start_date, end_date,
|
negative_ruleset_owner, error_number, i_customer_id, uan_handler,
|
ua_ruleset_owner
|
FROM pg_catalog.dbms_logrep_apply;
|
ROLLBACK;
|
|
-- Test 44: DBMS_LOGREP_EXP writes a NULL varchar2 as '' (ADD_SINGLE_QUOTE,
|
-- SYS.DBMS_LOGREP_EXP.pls:562-565). In Oracle that is NULL, so '' is folded
|
-- to NULL here too. A NULL owner then blanks the name half of its pair
|
-- (SYS.DBMS_LOGREP_IMP.pls:1096-1111).
|
-- Expected: every column below is NULL although the names were supplied.
|
BEGIN;
|
SELECT dbms_logrep_imp_create_apply(apply_name=>'APPLY_EMPTY', queue_owner=>'', queue_name=>'STREAMS_QUEUE', apply_captured=>1, ruleset_owner=>'', ruleset_name=>'RULESET$_3', apply_user=>'STRMADMIN', apply_dblink=>'', apply_tag=>'', ddl_handler=>'', message_handler=>'', precommit_handler=>'', negative_ruleset_owner=>'', negative_ruleset_name=>'RULESET$_4', error_message=>'', uan_handler=>'', ua_ruleset_owner=>NULL, ua_ruleset_name=>'RULESET$_5');
|
SELECT queue_owner IS NULL AS queue_owner_null,
|
queue_name IS NULL AS queue_name_null,
|
ruleset_name IS NULL AS ruleset_name_null,
|
apply_dblink IS NULL AS dblink_null,
|
apply_tag IS NULL AS tag_null,
|
ddl_handler IS NULL AS ddl_handler_null,
|
negative_ruleset_name IS NULL AS negative_ruleset_name_null,
|
error_message IS NULL AS error_message_null,
|
ua_ruleset_name IS NULL AS ua_ruleset_name_null
|
FROM pg_catalog.dbms_logrep_apply;
|
ROLLBACK;
|
|
-- Test 45: replaying a dump twice. The create step swallows -26665
|
-- (STREAMS_PROCESS_ALREADY_EXISTS, SYS.DBMS_LOGREP_IMP.pls:1133-1136), but
|
-- UPDATE_APPLY_PROCESS runs unconditionally afterwards (:1138), so the second
|
-- call keeps the row yet overwrites its error fields.
|
-- Expected: one row, queue from the FIRST call, error fields from the SECOND.
|
BEGIN;
|
SELECT dbms_logrep_imp_create_apply(
|
'APPLY_HR', 'STRMADMIN', 'FIRST_QUEUE', 1, 'STRMADMIN', 'RULESET$_3',
|
'STRMADMIN', NULL, NULL, NULL, NULL,
|
error_number=>100, error_message=>'first');
|
SELECT dbms_logrep_imp_create_apply(
|
'APPLY_HR', 'STRMADMIN', 'SECOND_QUEUE', 1, 'STRMADMIN', 'RULESET$_3',
|
'STRMADMIN', NULL, NULL, NULL, NULL,
|
error_number=>26714, error_message=>'ORA-26714: User error encountered');
|
SELECT count(*) AS apply_rows, min(queue_name) AS surviving_queue,
|
min(error_number) AS error_number, min(error_message) AS error_message
|
FROM pg_catalog.dbms_logrep_apply;
|
ROLLBACK;
|
|
-- Test 46: apply_captured is reduced to APPLY_CAPTURED = 1
|
-- (SYS.DBMS_LOGREP_IMP.pls:1092-1094): anything but 1, NULL included, is
|
-- FALSE. The key is the one thing that may not be NULL.
|
-- Expected: three rows with apply_captured = 0, then ORA-23605.
|
BEGIN;
|
SELECT dbms_logrep_imp_create_apply(
|
'APPLY_ZERO', 'STRMADMIN', 'Q', 0, NULL, NULL, 'STRMADMIN',
|
NULL, NULL, NULL, NULL);
|
SELECT dbms_logrep_imp_create_apply(
|
'APPLY_SEVEN', 'STRMADMIN', 'Q', 7, NULL, NULL, 'STRMADMIN',
|
NULL, NULL, NULL, NULL);
|
SELECT dbms_logrep_imp_create_apply(
|
'APPLY_NULL', 'STRMADMIN', 'Q', NULL, NULL, NULL, 'STRMADMIN',
|
NULL, NULL, NULL, NULL);
|
SELECT apply_name, apply_captured
|
FROM pg_catalog.dbms_logrep_apply ORDER BY apply_name;
|
SELECT dbms_logrep_imp_create_apply(
|
NULL, 'STRMADMIN', 'Q', 1, NULL, NULL, 'STRMADMIN',
|
NULL, NULL, NULL, NULL);
|
ROLLBACK;
|
|
-- Test 47: with IS_IMPORT_CONFIGURATION false the procedure returns before
|
-- touching anything (SYS.DBMS_LOGREP_IMP.pls:1085-1087). MODE_NONE = 2.
|
-- Expected: apply_rows_when_disabled = 0.
|
BEGIN;
|
SELECT dbms_logrep_imp_set_import_mode(2);
|
SELECT dbms_logrep_imp_create_apply(
|
'APPLY_HR', 'STRMADMIN', 'Q', 1, NULL, NULL, 'STRMADMIN',
|
NULL, NULL, NULL, NULL);
|
SELECT count(*) AS apply_rows_when_disabled
|
FROM pg_catalog.dbms_logrep_apply;
|
ROLLBACK;
|
|
SELECT dbms_logrep_imp_set_import_mode(4);
|
|
-- Test 48: the line DBMS_LOGREP_EXP emits for a modern (11.0+) dump
|
-- (SYS.DBMS_LOGREP_EXP.pls:1195-1219). Every argument goes through
|
-- ADD_SINGLE_QUOTE, numbers included. Times arrive as
|
-- 'YYYY-MM-DD:HH24:MI:SS' strings, with a colon after the date.
|
-- Expected: names folded to lower case, times parsed, values verbatim.
|
BEGIN;
|
SELECT dbms_logrep_imp_apply_milestone(apply_name=>'APPLY_HR', source_db=>'ORCL.EXAMPLE.COM', oldest_scn=>'1000', commit_scn=>'1010', synch_scn=>'0', epoch=>'3', processed_scn=>'1005', apply_time=>'2024-03-15:10:20:30', msg_create_time=>'2024-03-15:10:20:00', spare1=>'0', start_scn=>'900', oldest_transaction_id=>'5.12.345', spill_lwm_scn=>'950', lwm_external_pos=>'00AB', spare2=>'7', spare3=>'Spare Text');
|
SELECT apply_name, source_db, oldest_scn, commit_scn, synch_scn, epoch,
|
processed_scn, apply_time, msg_create_time, spare1, start_scn,
|
oldest_transaction_id, spill_lwm_scn, lwm_external_pos, spare2, spare3
|
FROM pg_catalog.dbms_logrep_apply_milestone;
|
ROLLBACK;
|
|
-- Test 49: the pre-10.2 dump shape carries only the first eleven arguments.
|
-- An empty varchar2 is NULL, as in Oracle. A replay is swallowed
|
-- (DUP_VAL_ON_INDEX, SYS.DBMS_LOGREP_IMP.pls:1204-1207). The key may not be
|
-- NULL.
|
-- Expected: one row with the FIRST call's commit_scn, NULL times and
|
-- defaults, then ORA-23605.
|
BEGIN;
|
SELECT dbms_logrep_imp_apply_milestone(apply_name=>'APPLY_HR', source_db=>'ORCL', oldest_scn=>'1', commit_scn=>'10', synch_scn=>'0', epoch=>'0', processed_scn=>'5', apply_time=>'', msg_create_time=>NULL, spare1=>NULL, start_scn=>'0');
|
SELECT dbms_logrep_imp_apply_milestone(apply_name=>'APPLY_HR', source_db=>'ORCL', oldest_scn=>'2', commit_scn=>'20', synch_scn=>'0', epoch=>'0', processed_scn=>'5', apply_time=>'', msg_create_time=>'', spare1=>NULL, start_scn=>'0');
|
SELECT count(*) AS milestone_rows, min(commit_scn) AS commit_scn,
|
bool_and(apply_time IS NULL) AS apply_time_null,
|
bool_and(msg_create_time IS NULL) AS msg_create_time_null,
|
bool_and(oldest_transaction_id IS NULL AND spill_lwm_scn IS NULL
|
AND lwm_external_pos IS NULL AND spare2 IS NULL
|
AND spare3 IS NULL) AS defaults_null
|
FROM pg_catalog.dbms_logrep_apply_milestone;
|
SELECT dbms_logrep_imp_apply_milestone(NULL, 'ORCL', 1, 10, 0, 0, 5, NULL, NULL, NULL, 0);
|
ROLLBACK;
|
|
-- Test 50: APPLY_PROGRESS as DBMS_LOGREP_EXP emits it
|
-- (SYS.DBMS_LOGREP_EXP.pls:1243-1252). Oracle has no handler here
|
-- (SYS.DBMS_LOGREP_IMP.pls:1235-1242), but the port skips a replayed
|
-- transaction so that a dump can be replayed twice. Another transaction
|
-- of the same apply is a separate row.
|
-- Expected: two rows, the replay keeps commit_scn = 1010, then ORA-23605.
|
BEGIN;
|
SELECT dbms_logrep_imp_apply_progress(apply_name=>'APPLY_HR', source_db=>'ORCL.EXAMPLE.COM', xidusn=>'5', xidslt=>'12', xidsqn=>'345', commit_scn=>'1010', spare1=>'0');
|
SELECT dbms_logrep_imp_apply_progress(apply_name=>'APPLY_HR', source_db=>'ORCL.EXAMPLE.COM', xidusn=>'5', xidslt=>'12', xidsqn=>'345', commit_scn=>'9999', spare1=>'0');
|
SELECT dbms_logrep_imp_apply_progress(apply_name=>'APPLY_HR', source_db=>'ORCL.EXAMPLE.COM', xidusn=>'5', xidslt=>'13', xidsqn=>'346', commit_scn=>'1020', spare1=>NULL);
|
SELECT apply_name, source_db, xidusn, xidslt, xidsqn, commit_scn, spare1
|
FROM pg_catalog.dbms_logrep_apply_progress ORDER BY xidslt;
|
SELECT dbms_logrep_imp_apply_progress(NULL, 'ORCL', 5, 12, 345, 1010, 0);
|
ROLLBACK;
|
|
-- Test 51: SET_KEY_COLUMNS is an accumulator (SYS.DBMS_LOGREP_IMP.pls:
|
-- 1354-1378). DBMS_LOGREP_EXP emits one call per column, ordered by object
|
-- (C_APPLY_KEY_COLS, SYS.DBMS_LOGREP_EXP.pls:411-415). A set is written only
|
-- when the object changes, and the last one only on the all-NULL sentinel
|
-- (APPLY_KEY_COLS_FINAL, :1389).
|
-- Expected: after the first object's columns, nothing is written. The
|
-- second object flushes the first, and the sentinel flushes the second.
|
-- Positions follow arrival order.
|
BEGIN;
|
SELECT dbms_logrep_imp_set_key_columns(object_owner=>'HR', object_name=>'EMPLOYEES', column_name=>'FIRST_NAME', apply_dblink=>'');
|
SELECT dbms_logrep_imp_set_key_columns(object_owner=>'HR', object_name=>'EMPLOYEES', column_name=>'LAST_NAME', apply_dblink=>'');
|
SELECT count(*) AS key_rows_before_object_change
|
FROM pg_catalog.dbms_logrep_apply_key_columns;
|
SELECT dbms_logrep_imp_set_key_columns(object_owner=>'HR', object_name=>'JOBS', column_name=>'JOB_TITLE', apply_dblink=>'');
|
SELECT dbms_logrep_imp_set_key_columns(object_owner=>'HR', object_name=>'JOBS', column_name=>'MIN_SALARY', apply_dblink=>'');
|
SELECT dbms_logrep_imp_set_key_columns(object_owner=>'HR', object_name=>'JOBS', column_name=>'MAX_SALARY', apply_dblink=>'');
|
SELECT object_name, column_name, column_position
|
FROM pg_catalog.dbms_logrep_apply_key_columns ORDER BY 1, 3;
|
SELECT dbms_logrep_imp_set_key_columns(object_owner=>null, object_name=>null, column_name=>null, apply_dblink=>null);
|
SELECT object_owner, object_name, column_name, apply_database_link,
|
apply_name, column_position
|
FROM pg_catalog.dbms_logrep_apply_key_columns ORDER BY 2, 6;
|
ROLLBACK;
|
|
-- Test 52: the flush is DBMS_APPLY_ADM.SET_KEY_COLUMNS, which replaces an
|
-- object's key set. So a replay rewrites the set rather than adding to it.
|
-- The dblink is part of the object identity: equal, or both NULL
|
-- (:1361-1362). It is stored verbatim.
|
-- Expected: employees holds only EMAIL (the second run). The dblink copy of
|
-- employees is a separate set.
|
BEGIN;
|
SELECT dbms_logrep_imp_set_key_columns('HR', 'EMPLOYEES', 'FIRST_NAME', NULL);
|
SELECT dbms_logrep_imp_set_key_columns('HR', 'EMPLOYEES', 'LAST_NAME', NULL);
|
SELECT dbms_logrep_imp_set_key_columns(NULL, NULL, NULL, NULL);
|
SELECT dbms_logrep_imp_set_key_columns('HR', 'EMPLOYEES', 'EMAIL', NULL);
|
SELECT dbms_logrep_imp_set_key_columns('HR', 'EMPLOYEES', 'EMPLOYEE_ID', 'Remote.Example.COM');
|
SELECT dbms_logrep_imp_set_key_columns('HR', 'EMPLOYEES', 'HIRE_DATE', 'Remote.Example.COM');
|
SELECT dbms_logrep_imp_set_key_columns(NULL, NULL, NULL, NULL);
|
SELECT object_name, column_name, apply_database_link, column_position
|
FROM pg_catalog.dbms_logrep_apply_key_columns ORDER BY 3 NULLS FIRST, 4;
|
ROLLBACK;
|
|
-- Test 53: APPLY_ERROR as DBMS_LOGREP_EXP emits it for a 10.2+ dump
|
-- (SYS.DBMS_LOGREP_EXP.pls:1456-1485), with error_creation_time through
|
-- date_convert. Transaction ids are values, not names, and are stored
|
-- verbatim. A replay is swallowed (DUP_VAL_ON_INDEX, SYS.DBMS_LOGREP_IMP.pls:
|
-- 1509-1512). The key may not be NULL.
|
-- Expected: one row with the first call's message, then ORA-23605.
|
BEGIN;
|
SELECT dbms_logrep_imp_apply_error(local_tid=>'5.12.345', source_tid=>'1.2.3', source_db=>'ORCL.EXAMPLE.COM', queue_owner=>'STRMADMIN', queue_name=>'STREAMS_QUEUE', apply_name=>'APPLY_HR', message_number=>'1', message_count=>'3', min_step_no=>'0', recipient_name=>'STRMADMIN', source_commit_scn=>'1010', error_number=>'1403', error_message=>'ORA-01403: no data found', aq_tid=>'AQ.1.2', spare1=>'0', spare2=>'0', spare3=>'0', error_creation_time=> dbms_logrep_imp_date_convert('2024-03-15 10:20:30','YYYY-MM-DD HH24:MI:SS'));
|
SELECT dbms_logrep_imp_apply_error(local_tid=>'5.12.345', source_tid=>'1.2.3', source_db=>'ORCL.EXAMPLE.COM', queue_owner=>'STRMADMIN', queue_name=>'STREAMS_QUEUE', apply_name=>'APPLY_HR', message_number=>'1', message_count=>'3', min_step_no=>'0', recipient_name=>'STRMADMIN', source_commit_scn=>'1010', error_number=>'1', error_message=>'replayed', aq_tid=>'', spare1=>NULL, spare2=>NULL, spare3=>NULL );
|
SELECT local_tid, source_tid, source_db, queue_owner, queue_name, apply_name,
|
message_number, message_count, min_step_no, recipient_name,
|
source_commit_scn, error_number, error_message, aq_tid,
|
spare1, spare2, spare3, error_creation_time
|
FROM pg_catalog.dbms_logrep_apply_error;
|
SELECT dbms_logrep_imp_apply_error(NULL, NULL, NULL, NULL, NULL, 'APPLY_HR', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
ROLLBACK;
|
|
-- Test 54: APPLY_ERROR_TXN in its two dump shapes
|
-- (SYS.DBMS_LOGREP_EXP.pls:1514-1548). Before 11.2 only the first three
|
-- arguments are emitted. txn_message_number is emitted unquoted.
|
-- position is a rudb keyword, so the named argument must be quoted. An
|
-- empty RAW is NULL, as in Oracle. rudb uses the PostgreSQL default
|
-- standard_conforming_strings=on, so the bytea hex prefix is written '\x'.
|
-- A replay is swallowed
|
-- (SYS.DBMS_LOGREP_IMP.pls:1587-1590).
|
-- Expected: two rows. Message 1 keeps its first error_message. Object
|
-- names are folded, and the raw values are byte-exact. Then ORA-23605.
|
BEGIN;
|
SELECT dbms_logrep_imp_apply_error_txn(local_tid=>'5.12.345', msgid=>'\x8f3a01', txn_message_number=>1, error_number=>'1403', error_message=>'ORA-01403: no data found', flags=>'0', spare1=>NULL, spare2=>NULL, spare3=>'', spare4=>'', spare5=>'', spare6=> dbms_logrep_imp_date_convert('2024-03-15 10:20:30','YYYY-MM-DD HH24:MI:SS'), src_obj_owner=>'HR', src_obj_name=>'EMPLOYEES', dest_obj_owner=>'HR_COPY', dest_obj_name=>'EMPLOYEES', primary_key=>'EMPLOYEE_ID=100', "position"=>'\x00ff', message_flags=>'0', operation=>'UPDATE');
|
SELECT dbms_logrep_imp_apply_error_txn(local_tid=>'5.12.345', msgid=>'\x8f3a02', txn_message_number=>2);
|
SELECT dbms_logrep_imp_apply_error_txn(local_tid=>'5.12.345', msgid=>'\x8f3a01', txn_message_number=>1, error_message=>'replayed');
|
SELECT local_tid, msgid, txn_message_number, error_number, error_message,
|
flags, spare3, spare4, spare5, spare6, src_obj_owner, src_obj_name,
|
dest_obj_owner, dest_obj_name, primary_key, "position",
|
message_flags, operation
|
FROM pg_catalog.dbms_logrep_apply_error_txn ORDER BY txn_message_number;
|
SELECT dbms_logrep_imp_apply_error_txn(local_tid=>NULL, msgid=>'\x01', txn_message_number=>1);
|
ROLLBACK;
|
|
-- Test 55: with IS_IMPORT_CONFIGURATION false all five return before
|
-- touching anything, and SET_KEY_COLUMNS does not even seed its batch.
|
-- MODE_NONE = 2.
|
-- Expected: zero rows in every table, and still zero after a sentinel once
|
-- import is re-enabled.
|
BEGIN;
|
SELECT dbms_logrep_imp_set_import_mode(2);
|
SELECT dbms_logrep_imp_apply_milestone('APPLY_HR', 'ORCL', 1, 10, 0, 0, 5, NULL, NULL, NULL, 0);
|
SELECT dbms_logrep_imp_apply_progress('APPLY_HR', 'ORCL', 5, 12, 345, 1010, 0);
|
SELECT dbms_logrep_imp_set_key_columns('HR', 'EMPLOYEES', 'FIRST_NAME', NULL);
|
SELECT dbms_logrep_imp_apply_error('5.12.345', NULL, NULL, NULL, NULL, 'APPLY_HR', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
SELECT dbms_logrep_imp_apply_error_txn('5.12.345', '\x01', 1);
|
SELECT dbms_logrep_imp_set_import_mode(4);
|
SELECT dbms_logrep_imp_set_key_columns(NULL, NULL, NULL, NULL);
|
SELECT (SELECT count(*) FROM pg_catalog.dbms_logrep_apply_milestone) AS milestone_rows,
|
(SELECT count(*) FROM pg_catalog.dbms_logrep_apply_progress) AS progress_rows,
|
(SELECT count(*) FROM pg_catalog.dbms_logrep_apply_key_columns) AS key_column_rows,
|
(SELECT count(*) FROM pg_catalog.dbms_logrep_apply_error) AS error_rows,
|
(SELECT count(*) FROM pg_catalog.dbms_logrep_apply_error_txn) AS error_txn_rows;
|
ROLLBACK;
|
|
SELECT dbms_logrep_imp_set_import_mode(4);
|
|
-- Tests 56-61 cover phase 5, activation: START_QUEUE, START_CAPTURE and
|
-- START_APPLY. DBMS_LOGREP_EXP emits them last (STATE_START_QUEUE ..
|
-- STATE_START_APPLY, SYS.DBMS_LOGREP_EXP.pls:94-96). Each test runs inside a
|
-- transaction that is rolled back.
|
|
-- Test 56: START_QUEUE as DBMS_LOGREP_EXP emits it (SYS.DBMS_LOGREP_EXP.pls:
|
-- 1680-1685): the flags arrive as quoted literals. The AQ delegate is a stub
|
-- in rudb, so the flags are recorded in dbms_logrep_queues.
|
-- Expected: one row, names folded to lower case, both flags true.
|
BEGIN;
|
SELECT dbms_logrep_imp_start_queue(queue_owner=>'STRMADMIN', queue_name=>'STREAMS_QUEUE', enqueue_enabled=>'1', dequeue_enabled=>'1');
|
SELECT queue_owner, queue_name, enqueue_enabled, dequeue_enabled
|
FROM pg_catalog.dbms_logrep_queues;
|
ROLLBACK;
|
|
-- Test 57: DBMS_AQADM.START_QUEUE reads FALSE as "leave the current setting
|
-- alone", so a flag can be turned on but never off. Only 1 is true
|
-- (SYS.DBMS_LOGREP_IMP.pls:1676-1681): NULL and 7 are false. The key is
|
-- folded before comparison, and it may not be NULL.
|
-- Expected: after (1,0) enqueue only. After (0,1), (0,0) and (NULL,NULL)
|
-- one row with both true. A second queue with (NULL,7) has both false.
|
-- Then ORA-23605.
|
BEGIN;
|
SELECT dbms_logrep_imp_start_queue('STRMADMIN', 'Q', 1, 0);
|
SELECT enqueue_enabled, dequeue_enabled FROM pg_catalog.dbms_logrep_queues;
|
SELECT dbms_logrep_imp_start_queue('strmadmin', 'q', 0, 1);
|
SELECT dbms_logrep_imp_start_queue('STRMADMIN', 'Q', 0, 0);
|
SELECT dbms_logrep_imp_start_queue('STRMADMIN', 'Q', NULL, NULL);
|
SELECT dbms_logrep_imp_start_queue('STRMADMIN', 'Q2', NULL, 7);
|
SELECT queue_owner, queue_name, enqueue_enabled, dequeue_enabled
|
FROM pg_catalog.dbms_logrep_queues ORDER BY queue_name;
|
SELECT dbms_logrep_imp_start_queue(NULL, 'Q', 1, 1);
|
ROLLBACK;
|
|
-- Test 58: START_CAPTURE turns a created capture from DISABLED to ENABLED.
|
-- A replay is a no-op: Oracle swallows CANNOT_ALTER_STREAMS_PROCESS
|
-- (-26666, SYS.DBMS_LOGREP_IMP.pls:1702-1705). A missing process is
|
-- ORA-26701, which Oracle does not swallow. A NULL name reaches Oracle as '""'
|
-- and fails the same way.
|
-- Expected: DISABLED, then one ENABLED row after two calls with differently
|
-- cased names, null_capture_rejected = true, then ORA-26701.
|
BEGIN;
|
SELECT dbms_logrep_imp_create_capture('STRMADMIN', 'STREAMS_QUEUE', 'CAPTURE_HR', NULL, NULL, 'STRMADMIN');
|
SELECT capture_name, status FROM pg_catalog.dbms_logrep_capture;
|
SELECT dbms_logrep_imp_start_capture(capture_name=>'CAPTURE_HR');
|
SELECT dbms_logrep_imp_start_capture('capture_hr');
|
SELECT capture_name, status FROM pg_catalog.dbms_logrep_capture;
|
SELECT pg_temp.caught_exception(
|
'SELECT dbms_logrep_imp_start_capture(NULL)'
|
) AS null_capture_rejected;
|
SELECT dbms_logrep_imp_start_capture(capture_name=>'NO_SUCH_CAPTURE');
|
ROLLBACK;
|
|
-- Test 59: START_APPLY, the same contract on the apply side
|
-- (SYS.DBMS_LOGREP_IMP.pls:1708-1728). An empty name is NULL, as in Oracle.
|
-- Expected: DISABLED, then one ENABLED row, empty_apply_rejected = true, then
|
-- ORA-26701.
|
BEGIN;
|
SELECT dbms_logrep_imp_create_apply(
|
'APPLY_HR', 'STRMADMIN', 'STREAMS_QUEUE', 1, NULL, NULL, 'STRMADMIN',
|
NULL, NULL, NULL, NULL);
|
SELECT apply_name, status FROM pg_catalog.dbms_logrep_apply;
|
SELECT dbms_logrep_imp_start_apply(apply_name=>'APPLY_HR');
|
SELECT dbms_logrep_imp_start_apply(apply_name=>'APPLY_HR');
|
SELECT apply_name, status FROM pg_catalog.dbms_logrep_apply;
|
SELECT pg_temp.caught_exception(
|
'SELECT dbms_logrep_imp_start_apply(apply_name=>'''')'
|
) AS empty_apply_rejected;
|
SELECT dbms_logrep_imp_start_apply('NO_SUCH_APPLY');
|
ROLLBACK;
|
|
-- Test 60: the tail of a dump replayed in DBMS_LOGREP_EXP order, twice.
|
-- Expected: one capture, one apply and one queue, all started.
|
BEGIN;
|
SELECT dbms_logrep_imp_create_capture(queue_owner=>'STRMADMIN', queue_name=>'STREAMS_QUEUE', capture_name=>'CAPTURE_HR', ruleset_owner=>'STRMADMIN', ruleset_name=>'RULESET$_1', capture_username=>'STRMADMIN');
|
SELECT dbms_logrep_imp_create_apply(apply_name=>'APPLY_HR', queue_owner=>'STRMADMIN', queue_name=>'STREAMS_QUEUE', apply_captured=>'1', ruleset_owner=>'STRMADMIN', ruleset_name=>'RULESET$_3', apply_user=>'STRMADMIN', apply_dblink=>'', apply_tag=>'', ddl_handler=>'', message_handler=>'');
|
SELECT dbms_logrep_imp_start_queue(queue_owner=>'STRMADMIN', queue_name=>'STREAMS_QUEUE', enqueue_enabled=>'1', dequeue_enabled=>'1');
|
SELECT dbms_logrep_imp_start_capture(capture_name=>'CAPTURE_HR');
|
SELECT dbms_logrep_imp_start_apply(apply_name=>'APPLY_HR');
|
SELECT dbms_logrep_imp_start_queue(queue_owner=>'STRMADMIN', queue_name=>'STREAMS_QUEUE', enqueue_enabled=>'1', dequeue_enabled=>'1');
|
SELECT dbms_logrep_imp_start_capture(capture_name=>'CAPTURE_HR');
|
SELECT dbms_logrep_imp_start_apply(apply_name=>'APPLY_HR');
|
SELECT c.capture_name, c.status AS capture_status,
|
a.apply_name, a.status AS apply_status,
|
q.queue_owner, q.queue_name, q.enqueue_enabled, q.dequeue_enabled
|
FROM pg_catalog.dbms_logrep_capture c
|
JOIN pg_catalog.dbms_logrep_queues q
|
ON q.queue_owner = c.queue_owner AND q.queue_name = c.queue_name
|
JOIN pg_catalog.dbms_logrep_apply a
|
ON a.queue_owner = q.queue_owner AND a.queue_name = q.queue_name;
|
ROLLBACK;
|
|
-- Test 61: with IS_IMPORT_CONFIGURATION false all three return before
|
-- touching anything (SYS.DBMS_LOGREP_IMP.pls:1671-1673, :1695-1697,
|
-- :1716-1718). Nothing is raised even for a process that does not exist.
|
-- MODE_NONE = 2.
|
-- Expected: no queue rows, and the capture stays DISABLED.
|
BEGIN;
|
SELECT dbms_logrep_imp_create_capture('STRMADMIN', 'STREAMS_QUEUE', 'CAPTURE_HR', NULL, NULL, 'STRMADMIN');
|
SELECT dbms_logrep_imp_set_import_mode(2);
|
SELECT dbms_logrep_imp_start_queue('STRMADMIN', 'STREAMS_QUEUE', 1, 1);
|
SELECT dbms_logrep_imp_start_capture('CAPTURE_HR');
|
SELECT dbms_logrep_imp_start_capture('NO_SUCH_CAPTURE');
|
SELECT dbms_logrep_imp_start_apply('NO_SUCH_APPLY');
|
SELECT (SELECT count(*) FROM pg_catalog.dbms_logrep_queues) AS queue_rows,
|
(SELECT status FROM pg_catalog.dbms_logrep_capture) AS capture_status;
|
ROLLBACK;
|
|
SELECT dbms_logrep_imp_set_import_mode(4);
|
|
-- Tests 62-64 cover the replay stubs: procedures outside the port's scope
|
-- that DBMS_LOGREP_EXP emits between the states the port implements. Each
|
-- one traces, checks the import mode and checks privileges, then returns.
|
|
-- Test 62: every stub accepts the call text DBMS_LOGREP_EXP emits for it
|
-- (SYS.DBMS_LOGREP_EXP.pls:650-656, :712-714, :806-810, :887-905, :930-933,
|
-- :957-966, :990-998, :1277-1281, :1307-1316, :1340-1347, :1417-1427,
|
-- :1574-1582, :2273-2280). The all-NULL form is accepted too. Nothing is
|
-- recorded.
|
-- Known limitation: DBMS_LOGREP_EXP writes a NULL number as '', which the
|
-- number and binary_integer input functions reject. So the numeric
|
-- arguments here are never NULL.
|
-- Expected: every call completes and every catalog table stays empty.
|
BEGIN;
|
SELECT dbms_logrep_imp_create_sync_capture(queue_owner=>'STRMADMIN', queue_name=>'STREAMS_QUEUE', capture_name=>'SYNC_CAPTURE', ruleset_owner=>'STRMADMIN', ruleset_name=>'RULESET$_5', capture_username=>'STRMADMIN');
|
SELECT dbms_logrep_imp_prepare_sync_object(table_owner=>'HR', table_name=>'EMPLOYEES');
|
SELECT dbms_logrep_imp_include_extra_attribute(capture_name=>'CAPTURE_HR', attribute_name=>'USERNAME', include=>'YES');
|
SELECT dbms_logrep_imp_streams_rules(streams_name=>'CAPTURE_HR', streams_type=>'1', rule_type=>'1', include_tagged_lcr=>'0', source_database=>'ORCL.EXAMPLE.COM', rule_owner=>'STRMADMIN', rule_name=>'EMPLOYEES1', rule_condition=>'((:dml.get_object_owner() = ''HR''))', dml_condition=>'', subsetting_operation=>'0', schema_name=>'HR', object_name=>'EMPLOYEES', object_type=>'1', spare1=>'0', spare2=>'0', spare3=>'0', source_root_name=>'');
|
SELECT dbms_logrep_imp_privileged_user(canon_username=>'STRMADMIN', privs=>'1');
|
SELECT dbms_logrep_imp_message_rules(canon_streams_name=>'MSG_CLIENT',streams_type=>'3',canon_msg_type_owner=>'STRMADMIN',canon_msg_type_name=>'ORDER_T',canon_msg_rule_var=>'VAR$_1',canon_rule_owner=>'STRMADMIN',canon_rule_name=>'ORDER_RULE',rule_condition=>':VAR$_1.AMOUNT > 100');
|
SELECT dbms_logrep_imp_message_consumers(canon_streams_name=>'MSG_CLIENT',canon_queue_owner=>'STRMADMIN',canon_queue_name=>'STREAMS_QUEUE',canon_rset_owner=>'STRMADMIN',canon_rset_name=>'RULESET$_7',canon_neg_rset_owner=>'',canon_neg_rset_name=>'');
|
SELECT dbms_logrep_imp_set_apply_param(apply_name=>'APPLY_HR', parameter_name=>'DISABLE_ON_ERROR', parameter_value=>'N');
|
SELECT dbms_logrep_imp_set_apply_source_obj(source_db=>'ORCL.EXAMPLE.COM', owner=>'HR', name=>'EMPLOYEES', type=>2, inst_scn=>'1000', ignore_scn=>'0', dblink=>'', spare1=>'0');
|
SELECT dbms_logrep_imp_set_apply_source_schema(source_db=>'ORCL.EXAMPLE.COM', global_flag=>'0', name=>'HR', dblink=>'', inst_scn=>'1000', spare1=>'0');
|
SELECT dbms_logrep_imp_set_dml_handler(object_owner=>'HR', object_name=>'EMPLOYEES', operation_name=>'UPDATE', user_procedure=>'"STRMADMIN"."EMP_HANDLER"', error_handler=>'0', apply_dblink=>'', apply_name=>'APPLY_HR', assemble_lobs=>'1');
|
SELECT dbms_logrep_imp_set_update_conflict_handler(object_owner=>'HR', object_name=>'EMPLOYEES', resolution_id=>'1', method_name=>'MAXIMUM', resolution_column=>'SALARY', column_name=>'SALARY', dblink=>'');
|
SELECT dbms_logrep_imp_set_import_mode(1);
|
SELECT dbms_logrep_imp_instantiate(object_owner=>'HR', object_name=>'EMPLOYEES', object_type=>'2', export_db_name=>'ORCL.EXAMPLE.COM', inst_scn=>'1000', ignore_scn=>'0');
|
DO $$
|
BEGIN
|
PERFORM dbms_logrep_imp_instantiate(NULL, NULL, NULL, NULL, NULL, NULL);
|
PERFORM dbms_logrep_imp_create_sync_capture(NULL, NULL, NULL, NULL, NULL, NULL);
|
PERFORM dbms_logrep_imp_prepare_sync_object(NULL, NULL);
|
PERFORM dbms_logrep_imp_include_extra_attribute(NULL, NULL, NULL);
|
PERFORM dbms_logrep_imp_streams_rules(NULL, NULL, NULL, NULL, NULL, NULL,
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
PERFORM dbms_logrep_imp_privileged_user(NULL, NULL);
|
PERFORM dbms_logrep_imp_message_rules(NULL, NULL, NULL, NULL, NULL, NULL,
|
NULL, NULL);
|
PERFORM dbms_logrep_imp_message_consumers(NULL, NULL, NULL, NULL, NULL,
|
NULL, NULL);
|
PERFORM dbms_logrep_imp_set_apply_param(NULL, NULL, NULL);
|
PERFORM dbms_logrep_imp_set_apply_source_obj(NULL, NULL, NULL, NULL, NULL,
|
NULL, NULL, NULL);
|
PERFORM dbms_logrep_imp_set_apply_source_schema(NULL, NULL, NULL, NULL,
|
NULL, NULL);
|
PERFORM dbms_logrep_imp_set_dml_handler(NULL, NULL, NULL, NULL, NULL);
|
PERFORM dbms_logrep_imp_set_update_conflict_handler(NULL, NULL, NULL, NULL,
|
NULL, NULL, NULL);
|
END;
|
$$;
|
SELECT (SELECT count(*) FROM pg_catalog.dbms_logrep_capture)
|
+ (SELECT count(*) FROM pg_catalog.dbms_logrep_capture_params)
|
+ (SELECT count(*) FROM pg_catalog.dbms_logrep_prepared_tables)
|
+ (SELECT count(*) FROM pg_catalog.dbms_logrep_prepared_schemas)
|
+ (SELECT count(*) FROM pg_catalog.dbms_logrep_propagation)
|
+ (SELECT count(*) FROM pg_catalog.dbms_logrep_apply)
|
+ (SELECT count(*) FROM pg_catalog.dbms_logrep_apply_milestone)
|
+ (SELECT count(*) FROM pg_catalog.dbms_logrep_apply_progress)
|
+ (SELECT count(*) FROM pg_catalog.dbms_logrep_apply_key_columns)
|
+ (SELECT count(*) FROM pg_catalog.dbms_logrep_apply_error)
|
+ (SELECT count(*) FROM pg_catalog.dbms_logrep_apply_error_txn)
|
+ (SELECT count(*) FROM pg_catalog.dbms_logrep_queues) AS catalog_rows;
|
ROLLBACK;
|
|
SELECT dbms_logrep_imp_set_import_mode(4);
|
|
-- Test 63: the gates, made visible through CHECK_PRIVILEGES. A role with
|
-- neither superuser nor pg_read_all_data fails the check (decision 3 of the
|
-- plan). So a call raises ORA-26723 exactly when its gate lets it through:
|
-- * configuration procedures run only under IS_IMPORT_CONFIGURATION;
|
-- * PRIVILEGED_USER has no gate at all (SYS.DBMS_LOGREP_IMP.pls:903-926);
|
-- * INSTANTIATE runs only under IS_IMPORT_INSTANTIATION, and passes
|
-- CHECK_PRIVILEGES the object owner, so an owner equal to the current
|
-- user needs no role.
|
-- None of these calls writes anything, so no transaction is needed.
|
-- Expected: mode 4 -- three errors, then instantiate passes. Mode 2 --
|
-- only privileged_user fails. Mode 3 -- set_apply_param passes, instantiate
|
-- fails for HR and passes for the role's own schema.
|
CREATE ROLE regress_logrep_nopriv;
|
SET ROLE regress_logrep_nopriv;
|
SELECT dbms_logrep_imp_set_import_mode(4);
|
SELECT dbms_logrep_imp_set_apply_param('APPLY_HR', 'DISABLE_ON_ERROR', 'N');
|
SELECT dbms_logrep_imp_start_queue('STRMADMIN', 'STREAMS_QUEUE', 1, 1);
|
SELECT dbms_logrep_imp_privileged_user('STRMADMIN', 1);
|
SELECT dbms_logrep_imp_instantiate('HR', 'EMPLOYEES', 2, 'ORCL', 1000, 0);
|
SELECT dbms_logrep_imp_set_import_mode(2);
|
SELECT dbms_logrep_imp_set_apply_param('APPLY_HR', 'DISABLE_ON_ERROR', 'N');
|
SELECT dbms_logrep_imp_start_queue('STRMADMIN', 'STREAMS_QUEUE', 1, 1);
|
SELECT dbms_logrep_imp_privileged_user('STRMADMIN', 1);
|
SELECT dbms_logrep_imp_set_import_mode(3);
|
SELECT dbms_logrep_imp_set_apply_param('APPLY_HR', 'DISABLE_ON_ERROR', 'N');
|
SELECT dbms_logrep_imp_instantiate('HR', 'EMPLOYEES', 2, 'ORCL', 1000, 0);
|
SELECT dbms_logrep_imp_instantiate('REGRESS_LOGREP_NOPRIV', 'T', 2, 'ORCL', 1000, 0);
|
RESET ROLE;
|
DROP ROLE regress_logrep_nopriv;
|
|
SELECT dbms_logrep_imp_set_import_mode(4);
|
|
-- Test 64: INSTANTIATE keeps the one check its own body makes before the
|
-- delegate: IGNORE_SCN > INST_SCN raises NO_DATA_FOUND
|
-- (SYS.DBMS_LOGREP_IMP.pls:409-414). The comparison is three-valued, so a
|
-- NULL on either side passes. Without IS_IMPORT_INSTANTIATION the check is
|
-- never reached. MODE_ALL = 1.
|
-- Expected: under mode 1, two silent calls and then ORA-01403. Under mode 4,
|
-- the same call is silent.
|
SELECT dbms_logrep_imp_set_import_mode(1);
|
SELECT dbms_logrep_imp_instantiate('HR', 'EMPLOYEES', 2, 'ORCL', 1000, 1000);
|
SELECT dbms_logrep_imp_instantiate('HR', 'EMPLOYEES', 2, 'ORCL', 1000, NULL);
|
SELECT dbms_logrep_imp_instantiate('HR', 'EMPLOYEES', 2, 'ORCL', 1000, 1001);
|
SELECT dbms_logrep_imp_set_import_mode(4);
|
SELECT dbms_logrep_imp_instantiate('HR', 'EMPLOYEES', 2, 'ORCL', 1000, 1001);
|
|
-- Tests 65-67 cover INSTANTIATE_SCHEMA (SYS.DBMS_LOGREP_IMP.pls:457-492):
|
-- trace, IS_IMPORT_INSTANTIATION gate, CHECK_PRIVILEGES(schema_name), then
|
-- the delegate, which the port omits (decision 1 of the plan).
|
|
-- Test 65: the signature follows the house style (varchar2/number), and the
|
-- function is not strict, so a NULL argument still reaches the gate and the
|
-- privilege check.
|
-- Expected: 'varchar2 varchar2 number', not strict.
|
SELECT oid, proargtypes::regtype[] AS argtypes, proisstrict
|
FROM pg_proc
|
WHERE proname = 'dbms_logrep_imp_instantiate_schema';
|
|
-- Test 66: the call text DBMS_LOGREP_EXP emits for a database export
|
-- (SYS.DBMS_LOGREP_EXP.pls:2131-2139), under MODE_ALL = 1. The SCN arrives
|
-- as a quoted literal. Nothing is recorded.
|
-- Expected: both calls complete and every catalog table stays empty.
|
BEGIN;
|
SELECT dbms_logrep_imp_set_import_mode(1);
|
SELECT dbms_logrep_imp_instantiate_schema(schema_name=>NULL, export_db_name=>'ORCL.EXAMPLE.COM', inst_scn=>'1234567');
|
SELECT dbms_logrep_imp_bump_scn(scn=>'1234567');
|
SELECT dbms_logrep_imp_instantiate_schema(schema_name=>'HR', export_db_name=>'ORCL.EXAMPLE.COM', inst_scn=>'1234567');
|
SELECT (SELECT count(*) FROM pg_catalog.dbms_logrep_capture)
|
+ (SELECT count(*) FROM pg_catalog.dbms_logrep_apply)
|
+ (SELECT count(*) FROM pg_catalog.dbms_logrep_queues) AS catalog_rows;
|
ROLLBACK;
|
|
SELECT dbms_logrep_imp_set_import_mode(4);
|
|
-- Test 67: the gate and the privilege check, made visible with a role that
|
-- has neither superuser nor pg_read_all_data (decision 3 of the plan).
|
-- * Under modes 4 and 2 IS_IMPORT_INSTANTIATION is false: every call
|
-- returns before CHECK_PRIVILEGES.
|
-- * Under modes 3 and 1 CHECK_PRIVILEGES runs with SCHEMA_NAME. NULL (the
|
-- database-export form) and another user's schema need the role; the
|
-- role's own schema passes, in any case, because the name is folded.
|
-- Expected: mode 4 and mode 2 -- silent. Mode 3 -- ORA-26723 for NULL and
|
-- HR, silent for the own schema in both cases. Mode 1 -- ORA-26723 for NULL.
|
CREATE ROLE regress_logrep_nopriv;
|
SET ROLE regress_logrep_nopriv;
|
SELECT dbms_logrep_imp_set_import_mode(4);
|
SELECT dbms_logrep_imp_instantiate_schema(NULL, 'ORCL', 1000);
|
SELECT dbms_logrep_imp_instantiate_schema('HR', 'ORCL', 1000);
|
SELECT dbms_logrep_imp_set_import_mode(2);
|
SELECT dbms_logrep_imp_instantiate_schema(NULL, 'ORCL', 1000);
|
SELECT dbms_logrep_imp_set_import_mode(3);
|
SELECT dbms_logrep_imp_instantiate_schema(NULL, 'ORCL', 1000);
|
SELECT dbms_logrep_imp_instantiate_schema('HR', 'ORCL', 1000);
|
SELECT dbms_logrep_imp_instantiate_schema('REGRESS_LOGREP_NOPRIV', 'ORCL', 1000);
|
SELECT dbms_logrep_imp_instantiate_schema('regress_logrep_nopriv', NULL, NULL);
|
SELECT dbms_logrep_imp_set_import_mode(1);
|
SELECT dbms_logrep_imp_instantiate_schema(NULL, 'ORCL', 1000);
|
RESET ROLE;
|
DROP ROLE regress_logrep_nopriv;
|
|
SELECT dbms_logrep_imp_set_import_mode(4);
|