Archives June 2023

RMAN-04006: error from auxiliary database: ORA-01017: invalid username/password; logon denied

This error may occur 95% of the time due to wrong listener entry in the network configuration files. The error itself is some what misleading to the original cause.

Steps taken for ora-01017 – Multiple times changed the password for sys user, recreated password files and also copied from primary to standby. It frustrate a lot with waste of valuable time for this simple error with no solution.

Even though the error states that the user credentials and password are incorrect, still this error may occur due to dynamic listener registration.

[oracle@xstdby dbs]$ rman target sys/password@db9zx auxiliary sys/password@xstdb

Recovery Manager: Release 19.0.0.0.0 - Production on Mon Jun 26 10:08:23 2023
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

connected to target database: DB9ZX (DBID=1041852011)
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00554: initialization of internal recovery manager package failed
RMAN-04006: error from auxiliary database: ORA-01017: invalid username/password; logon denied

In listener status, there are two output’s, one with unknown and other with blocked. This says that the listener is not dynamically registered and need to statistically configured. Even though there are lot of formats for static registration of listener over the internet, none of them works properly due to spaces or parenthesis etc.

[oracle@xstdby admin]$ lsnrctl status

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 26-JUN-2023 10:13:45

Copyright (c) 1991, 2019, Oracle.  All rights reserved.

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date                26-JUN-2023 10:11:54
Uptime                    0 days 0 hr. 1 min. 52 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/19.0.0/db_home/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/xstdby/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=xstdby)(PORT=1521)))
Services Summary...
Service "XSTDB" has 2 instance(s).
  Instance "xstdb", status UNKNOWN, has 1 handler(s) for this service...
  Instance "xstdb", status BLOCKED, has 1 handler(s) for this service...
The command completed successfully

Use the below format for static listener configuration which works correctly.

LISTENER =
 (DESCRIPTION_LIST =
   (DESCRIPTION =
     (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.1)(PORT = 1521))
     (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
   )
 )
SID_LIST_LISTENER=
   (SID_LIST=
     (SID_DESC=
      (GLOBAL_DBNAME=xstdb)
      (SID_NAME=xstdb)
      (ORACLE_HOME=/u01/app/oracle/product/19.0.0/db_home/)
 )
 )
STATIC LISTENER ENTRY FORMAT IN ORACLE

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME=ORCL)
      (SID_NAME = orcldg)
      (ORACLE_HOME = /grid/base/product/12.1.0/grid)
      (PROGRAM = extproc)
    )

    (SID_DESC =
      (GLOBAL_DBNAME=ORCL)
      (SID_NAME = orcldgp)
      (ORACLE_HOME = /grid/base/product/12.1.0/grid)
      (PROGRAM = extproc)
    )
  )
TNS-12541: TNS:no listener

During tnsping, the following error is expected if the source listener is not running.

[oracle@xhydra dbs]$ tnsping db9zx

TNS Ping Utility for Linux: Version 19.0.0.0.0 - Production on 17-JUN-2023 07:32:39

Copyright (c) 1997, 2019, Oracle.  All rights reserved.

Used parameter files:


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = <host>)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = db9zx)))
TNS-12541: TNS:no listener

Error utility says the following.

[oracle@xhydra dbs]$ oerr ora 12541
12541, 00000, "TNS:no listener"
// *Cause: The connection request could not be completed because the listener
// is not running.
// *Action: Ensure that the supplied destination address matches one of
// the addresses used by the listener - compare the TNSNAMES.ORA entry with
// the appropriate LISTENER.ORA file (or TNSNAV.ORA if the connection is to
// go by way of an Interchange). Start the listener on the remote machine.

Start the listener in source.

[oracle@xhydra ~]$ lsnrctl start

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 17-JUN-2023 07:33:14

Copyright (c) 1991, 2019, Oracle.  All rights reserved.

Starting /u01/app/oracle/product/19.0.0/dbhome_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 19.0.0.0.0 - Production
System parameter file is /u01/app/oracle/product/19.0.0/dbhome_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/xhydra/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=xhydra)(PORT=1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xhydra)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date                17-JUN-2023 07:33:14
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/19.0.0/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/xhydra/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=xhydra)(PORT=1521)))
The listener supports no services
The command completed successfully

Tnsping works perfectly.

SERVICE_NAME = db9zx)))
OK (510 msec)
FIND OUT IF AN INIT PARAMETER IS MODIFIED OR NOT

There are multiple ways to identify a human change of system parameter in oracle database. This is really essential for any DBA because of security reasons and to avoid any future impacts due to repercussions of the change unknowingly or intentionally by junior guy or external hackers.

Modify the parameter value for parallel_max_servers

SQL> set time on
14:09:03 SQL> show parameter parallel_max_ser

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
parallel_max_servers                 integer     40
14:09:09 SQL> alter system set parallel_max_servers=80;

System altered.

1)Check dba_hist_parameter to check the modified status of the parameter. This view depends on AWR snapshots and its retention. If the retention period is expired, then there is no use of this method.

14:39:32 SQL> SELECT SNAP_ID,PARAMETER_NAME,VALUE,ISDEFAULT,ISMODIFIED from dba_hist_parameter WHERE PARAMETER_NAME='parallel_max_servers' and ISMODIFIED='MODIFIED' order by SNAP_ID asc;

   SNAP_ID PARAMETER_NAME       VALUE                ISDEFAULT ISMODIFIED
---------- -------------------- -------------------- --------- ----------
       100 parallel_max_servers 80                   TRUE      MODIFIED

2) Probe the alert log for change of parameter. This is because, alert log is the bible to refer for any parameter change in the database. There are some exceptional cases where alert log may miss the changes.

[oracle@xhydra ~]$ grep 'parallel_max_servers' /u01/app/oracle/diag/rdbms/db9zx/db9zx/trace/alert_db9zx.log
ALTER SYSTEM SET parallel_max_servers=80 SCOPE=BOTH;

3)Another way is to enable 10046 system trace in the database all the time. This may record all the happenings in the database and may need an extra storage. This trace can be periodically compressed with extreme compression to counter storage issues. But the benefits of using this trace outweighs the issue itself. Just to identify an ‘ONCE IN A BLUEMOON’ happening, it is not necessary to enable trace all the time. But 10046 trace also has other performance diagnostics which can balance the benefits to drawback.

SQL> alter system set tracefile_identifier='10046';

Session altered.

SQL> alter system set events '10046 trace name context forever,level 2';

Session altered.

...


*** 2023-06-17T07:50:58.502863+05:30 (CDB$ROOT(1))
WAIT #140609190796088: nam='SQL*Net message from client' ela= 12117882 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=6439910440
CLOSE #140609190796088:c=6,e=6,dep=0,type=1,tim=6439910526
=====================
PARSING IN CURSOR #140609190794448 len=40 dep=0 uid=0 oct=49 lid=0 tim=6439910690 hv=3012368407 ad='0' sqlid='bvkx42utsu60r'
alter system set parallel_max_servers=80 <==================
END OF STMT
PARSE #140609190794448:c=144,e=144,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,plh=0,tim=6439910690
WAIT #140609190794448: nam='reliable message' ela= 169 channel context=2023208056 channel handle=2023112368 broadcast message=2026347512 obj#=-1 tim=6439911255
WAIT #140609190794448: nam='Disk file operations I/O' ela= 86 FileOperation=2 fileno=0 filetype=13 obj#=-1 tim=6439911404
WAIT #140609190794448: nam='Parameter File I/O' ela= 8 blkno=1 #blks=1 read/write=1 obj#=-1 tim=6439911431
WAIT #140609190794448: nam='Parameter File I/O' ela= 2 blkno=2 #blks=3 read/write=1 obj#=-1 tim=6439911496
WAIT #140609190794448: nam='Parameter File I/O' ela= 8226 blkno=5 #blks=3 read/write=2 obj#=-1 tim=6439920451
WAIT #140609190794448: nam='Parameter File I/O' ela= 753 blkno=1 #blks=1 read/write=2 obj#=-1 tim=6439921293
WAIT #140609190794448: nam='Parameter File I/O' ela= 6 blkno=5 #blks=3 read/write=1 obj#=-1 tim=6439921336
WAIT #140609190794448: nam='Parameter File I/O' ela= 674 blkno=2 #blks=3 read/write=2 obj#=-1 tim=6439922021
WAIT #140609190794448: nam='Parameter File I/O' ela= 581 blkno=1 #blks=1 read/write=2 obj#=-1 tim=6439922633
WAIT #140609190794448: nam='Parameter File I/O' ela= 926 blkno=5 #blks=3 read/write=2 obj#=-1 tim=6439923582
WAIT #140609190794448: nam='Disk file operations I/O' ela= 14 FileOperation=5 fileno=0 filetype=13 obj#=-1 tim=6439923618
WAIT #140609190794448: nam='Disk file operations I/O' ela= 20 FileOperation=8 fileno=0 filetype=8 obj#=-1 tim=6439923976
EXEC #140609190794448:c=2131,e=13302,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,plh=0,tim=6439924018
WAIT #140609190794448: nam='SQL*Net message to client' ela= 3 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=6439924076

4) Use audit trails

ORA-39083: Object type MATERIALIZED_VIEW:”KISH”.”MVREMOTE” failed to create with error:ORA-00942: table or view does not exist

Cause:

The error is expected behavior because of missing dependent container table of the mview.

[oracle@xhydra ~]$ impdp \'/ as sysdba\' directory=home dumpfile=mview.dmp logfile=mview.log remap_schema=KISH:KISH

Import: Release 19.0.0.0.0 - Production on Mon Jun 12 20:02:24 2023
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.
Password:

Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Warning: Oracle Data Pump operations are not typically needed when connected to the root or seed of a container database.

Master table "SYS"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYS"."SYS_IMPORT_FULL_01":  "/******** AS SYSDBA" directory=home dumpfile=mview.dmp logfile=mview.log remap_schema=KISH:KISH
Processing object type SCHEMA_EXPORT/MATERIALIZED_VIEW
ORA-39083: Object type MATERIALIZED_VIEW:"KISH"."MVREMOTE" failed to create with error:
ORA-00942: table or view does not exist

Failing sql is:
CREATE MATERIALIZED VIEW "KISH"."MVREMOTE" ("XNAME", "XID", "CITY", "COUNTRY", "DEPARTMENT", "DEP_ID", "XDATE", "SALARY") USING ("MVREMOTE", (10, 'DB9ZX', 1, 0, 0, "KISH", "YTBL", '2023-06-12 19:32:24', 262144, 73213, '1950-01-01 12:00:00', '', 1, 'FE01', 15319225, 0, NULL, (1, "XID", "XID", 2, 323, 0)), 2097249, 10, ('1950-01-01 12:00:00', 61, 0, 0, 15319225, 0, 0, 4194304, 2, NULL, NULL)) REFRESH COMPLETE WITH PRIMARY KEY AS SELECT "YTBL"."XNAME" "XNAME","YTBL"."XID" "XID","YTBL"."CITY" "CITY","YTBL"."COUNTRY" "COUNTRY","YTBL"."DEPARTMENT" "DEPARTMENT","YTBL"."DEP_ID" "DEP_ID","YTBL"."XDATE" "XDATE","YTBL"."SALARY" "SALARY" FROM "KISH"."YTBL" "YTBL"

All mviews are created along with a container table during initial phase. During export/import, the dependent container table should also be export/imported in database.

Solution:

Verify the container table.

SQL> col OWNER for a20
SQL> SELECT owner,object_name, object_type FROM dba_objects WHERE object_name = 'MVREMOTE';

OWNER                OBJECT_NAME          OBJECT_TYPE
-------------------- -------------------- --------------------

KISH                 MVREMOTE             TABLE
KISH                 MVREMOTE             MATERIALIZED VIEW

Export both container and its mview pair.

[oracle@xhydra ~]$ expdp \'/ as sysdba\' directory=home dumpfile=mview.dmp logfile=mview.log schemas=KISH include=TABLE:"IN('MVREMOTE')", MATERIALIZED_VIEW:"IN('MVREMOTE')" reuse_dumpfiles=Y

Export: Release 19.0.0.0.0 - Production on Mon Jun 12 20:24:30 2023
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.
Password:

Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Warning: Oracle Data Pump operations are not typically needed when connected to the root or seed of a container database.

Starting "SYS"."SYS_EXPORT_SCHEMA_01":  "/******** AS SYSDBA" directory=home dumpfile=mview.dmp logfile=mview.log schemas=KISH include=TABLE:IN('MVREMOTE'), MATERIALIZED_VIEW:IN('MVREMOTE') reuse_dumpfiles=Y
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/MATERIALIZED_VIEW
. . exported "KISH"."MVREMOTE"                           277.0 MB 5000000 rows
Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is:
  /home/oracle/mview.dmp
Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at Mon Jun 12 20:24:57 2023 elapsed 0 00:00:26

Import both container and mview.

[oracle@xhydra ~]$ impdp \'/ as sysdba\' directory=home dumpfile=mview.dmp logfile=mview.log INCLUDE=TABLE:"IN('MVREMOTE')", MATERIALIZED_VIEW:"IN('MVREMOTE')" table_exists_action=replace

Import: Release 19.0.0.0.0 - Production on Mon Jun 12 20:29:28 2023
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.
Password:

Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Warning: Oracle Data Pump operations are not typically needed when connected to the root or seed of a container database.

Master table "SYS"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYS"."SYS_IMPORT_FULL_01":  "/******** AS SYSDBA" directory=home dumpfile=mview.dmp logfile=mview.log INCLUDE=TABLE:IN('MVREMOTE'), MATERIALIZED_VIEW:IN('MVREMOTE') table_exists_action=replace
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "KISH"."MVREMOTE"                           277.0 MB 5000000 rows
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/MATERIALIZED_VIEW
Job "SYS"."SYS_IMPORT_FULL_01" successfully completed at Mon Jun 12 20:29:35 2023 elapsed 0 00:00:06
TNS-12543: TNS:destination host unreachable

There are multiple reasons for the error to occur due to unreachable host itself and there is nothing to do from database or listener.

[oracle@xhydra ~]$ tnsping xscalibal

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.1)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = xscalibal)(UR = A)))
TNS-12543: TNS:destination host unreachable

One of the main reason is firewall service which does not allow the connections.

[oracle@DBZX21 ~]$ service firewalld status
Redirecting to /bin/systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2023-06-13 12:47:34 IST; 1h 59min ago
     Docs: man:firewalld(1)
 Main PID: 877 (firewalld)
    Tasks: 2 (limit: 35835)
   Memory: 30.1M
   CGroup: /system.slice/firewalld.service
           └─877 /usr/libexec/platform-python -s /usr/sbin/firewalld --nofork --nopid
[oracle@DBZX21 ~]$ service firewalld stop
Redirecting to /bin/systemctl stop firewalld.service
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ====
Authentication is required to stop 'firewalld.service'.
Authenticating as: kishan
Password:
polkit-agent-helper-1: pam_authenticate failed: Authentication failure
==== AUTHENTICATION FAILED ====
Failed to stop firewalld.service: Access denied
See system logs and 'systemctl status firewalld.service' for details.
[oracle@DBZX21 ~]$ su
Password:
[root@DBZX21 oracle]# service firewalld stop
Redirecting to /bin/systemctl stop firewalld.service
[root@DBZX21 oracle]# service firewalld disable
The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.

After disabling firewall, tnsping worked fine.

[oracle@xhydra ~]$ tnsping xscalibal

(SERVICE_NAME = xscalibal)(UR = A)))
OK (0 msec)
FIND POWER OF TWO NUMBERS IN PYTHON

    def power(x, y):
        pow = x ** y
        return pow
CHECK IF A NUMBER IS PERFECT SQUARE OR NOT IN PYTHON

    def sqrt(x):
        sqrt = x ** (1/2)
        if x % (sqrt) == 0:
            return round(sqrt)
        else:
            return -1
EXPORT/IMPORT A MATERIALIZED VIEW

In this article, mview is exported from source and imported back to same source for demonstration and should not be performed in production.

Check the existing mview to be exported.

SQL> col OWNER for a20
SQL> col MVIEW_NAME for a20
SQL> SELECT OWNER,MVIEW_NAME,STALENESS,STALE_SINCE from dba_mviews WHERE MVIEW_NAME='MVREMOTE';

OWNER                MVIEW_NAME           STALENESS           STALE_SIN
-------------------- -------------------- ------------------- ---------
KISH                 MVREMOTE             FRESH

Can we export a materialized view using expdp ? Yes, it can be achieved by “INCLUDE” option.

SQL> conn kish/password
Connected.
SQL>
SQL>
SQL> CREATE MATERIALIZED VIEW mvremote BUILD IMMEDIATE REFRESH COMPLETE ON DEMAND AS SELECT * FROM KISH.YTBL;

Materialized view created.

SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
[oracle@xhydra ~]$ expdp \'/ as sysdba\' directory=home dumpfile=mview.dmp logfile=mview.log schemas=KISH include=MATERIALIZED_VIEW    
Export: Release 19.0.0.0.0 - Production on Mon Jun 12 19:33:06 2023
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.
Password:

Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Warning: Oracle Data Pump operations are not typically needed when connected to the root or seed of a container database.

Starting "SYS"."SYS_EXPORT_SCHEMA_01":  "/******** AS SYSDBA" directory=home dumpfile=mview.dmp logfile=mview.log schemas=KISH include=MATERIALIZED_VIEW
Processing object type SCHEMA_EXPORT/MATERIALIZED_VIEW
Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is:
  /home/oracle/mview.dmp
Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at Mon Jun 12 19:34:37 2023 elapsed 0 00:01:25

Also it is always advisable to export mview along with its container table as well to avoid any import errors with,

ORA-39083: Object type MATERIALIZED_VIEW:”KISH”.”MVREMOTE” failed to create with error:
ORA-00942: table or view does not exist

[oracle@xhydra ~]$ expdp \'/ as sysdba\' directory=home dumpfile=mview.dmp logfile=mview.log schemas=KISH include=TABLE:"IN('MVREMOTE')", MATERIALIZED_VIEW:"IN('MVREMOTE')" reuse_dumpfiles=Y

Export: Release 19.0.0.0.0 - Production on Mon Jun 12 20:24:30 2023
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.
Password:

Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Warning: Oracle Data Pump operations are not typically needed when connected to the root or seed of a container database.

Starting "SYS"."SYS_EXPORT_SCHEMA_01":  "/******** AS SYSDBA" directory=home dumpfile=mview.dmp logfile=mview.log schemas=KISH include=TABLE:IN('MVREMOTE'), MATERIALIZED_VIEW:IN('MVREMOTE') reuse_dumpfiles=Y
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/MATERIALIZED_VIEW
. . exported "KISH"."MVREMOTE"                           277.0 MB 5000000 rows
Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is:
  /home/oracle/mview.dmp
Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at Mon Jun 12 20:24:57 2023 elapsed 0 00:00:26

To identify the container table, use the below query.

SQL> col OWNER for a20
SQL> SELECT owner,object_name, object_type FROM dba_objects WHERE object_name = 'MVREMOTE';

OWNER                OBJECT_NAME          OBJECT_TYPE
-------------------- -------------------- --------------------
KISH                 MVREMOTE             TABLE
KISH                 MVREMOTE             MATERIALIZED VIEW

To import a materialized view, use the below steps.

[oracle@xhydra ~]$ impdp \'/ as sysdba\' directory=home dumpfile=mview.dmp logfile=mview.log INCLUDE=TABLE:"IN('MVREMOTE')", MATERIALIZED_VIEW:"IN('MVREMOTE')" table_exists_action=replace

Import: Release 19.0.0.0.0 - Production on Mon Jun 12 20:29:28 2023
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.
Password:

Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Warning: Oracle Data Pump operations are not typically needed when connected to the root or seed of a container database.

Master table "SYS"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYS"."SYS_IMPORT_FULL_01":  "/******** AS SYSDBA" directory=home dumpfile=mview.dmp logfile=mview.log INCLUDE=TABLE:IN('MVREMOTE'), MATERIALIZED_VIEW:IN('MVREMOTE') table_exists_action=replace
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "KISH"."MVREMOTE"                           277.0 MB 5000000 rows
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/MATERIALIZED_VIEW
Job "SYS"."SYS_IMPORT_FULL_01" successfully completed at Mon Jun 12 20:29:35 2023 elapsed 0 00:00:06

After importing the mview newly in the database, the staleness of mview becomes IMPORT because of the incomplete refresh. So a complete refresh need to be performed in order to synchronize the status to FRESH.

SQL> col OWNER for a20
SQL> col MVIEW_NAME for a20
SQL> SELECT OWNER,MVIEW_NAME,STALENESS,STALE_SINCE from dba_mviews WHERE MVIEW_NAME='MVREMOTE';

OWNER                MVIEW_NAME           STALENESS           STALE_SIN
-------------------- -------------------- ------------------- ---------
KISH                 MVREMOTE             IMPORT <===

Also, do we need to reregister the mview after import? No, since the container table is also imported with mview which are referenced objects, there is no need to register the mviews after import.

SQL> col NAME for a20
SQL> col OWNER for a20
SQL> col QUERY_TXT for a20
SQL> col MVIEW_SITE for a20
SQL> col VERSION for a20
SQL> set lines 200 pages 1000
SQL> select * from dba_registered_mviews where name ='MVREMOTE';

OWNER                NAME                 MVIEW_SITE           CAN UPD REFRESH_MET   MVIEW_ID VERSION              QUERY_TXT
-------------------- -------------------- -------------------- --- --- ----------- ---------- -------------------- --------------------
KISH                 MVREMOTE             EXHYDRA              YES NO  PRIMARY KEY         21 ORACLE 8 MATERIALIZE SELECT "YTBL"."XNAME
                                                                                              D VIEW               " "XNAME","YTBL"."XI
                                                                                                                   D" "XID","YTBL"."CIT
                                                                                                                   Y" "CITY","YTBL"."CO

KISH                 MVREMOTE             DB9ZX                YES NO  PRIMARY KEY         81 ORACLE 8 MATERIALIZE SELECT "YTBL"."XNAME
                                                                                              D VIEW               " "XNAME","YTBL"."XI
                                                                                                                   D" "XID","YTBL"."CIT
                                                                                                                   Y" "CITY","YTBL"."CO

All the registered mviews details are stored in internal table SYS.REG_SNAP$.

SQL> SELECT * from SYS.REG_SNAP$;


SOWNER
--------------------------------------------------------------------------------------------------------------------------------
SNAPNAME
--------------------------------------------------------------------------------------------------------------------------------
SNAPSITE                                                                                                                         SNAPSHOT_ID      FLAG   REP_TYPE
-------------------------------------------------------------------------------------------------------------------------------- ----------- ---------- ----------
COMMENT$
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
QUERY_TXT
--------------------
KISH
MVREMOTE
EXHYDRA                                                                                                                                 21     2097253          2

SELECT "YTBL"."XNAME
" "XNAME","YTBL"."XI
D" "XID","YTBL"."CIT
Y" "CITY","YTBL"."CO

KISH
MVREMOTE
DB9ZX                                                                                                                                   81     2097257          2

After a complete refresh, the mview is back to FRESH mode

SQL> show user
USER is "SYS"
SQL> conn kish/password
Connected.
SQL> EXEC dbms_mview.refresh('MVREMOTE');

PL/SQL procedure successfully completed.

SQL> SELECT OWNER,MVIEW_NAME,STALENESS,STALE_SINCE from dba_mviews WHERE MVIEW_NAME='MVREMOTE';

OWNER                MVIEW_NAME           STALENESS           STALE_SIN
-------------------- -------------------- ------------------- ---------
KISH                 MVREMOTE             FRESH

INFLUENCE PARALLEL DEGREE FOR SQL PROFILE

When it comes to sql profile, there are lot of questions which arise on the basic functionality. It is not always recommended to use a parallel sql profile in a on peak database because of the sudden burst of parallel spawns.

Even oracle itself ignored the parallel plan during the tuning process.

DBMS_SQLTUNE.REPORT_TUNING_TASK('A6BWKQ27KB1J2_TT')
----------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Schema Name   : SYS
Container Name: CDB$ROOT
SQL ID        : a6bwkq27kb1j2
SQL Text      : SELECT * from ytbl

-------------------------------------------------------------------------------
ADDITIONAL INFORMATION SECTION
-------------------------------------------------------------------------------
- SQL Profile "coe_a6bwkq27kb1j2_192604670" exists for this statement and was
  ignored during the tuning process.
  • Can we change parallel for sql profile manually?
  • Can multiple sql use same sql profile?
  • Can multiple sql profiles be used for one sql?
  • If sql id changes, then can sql profile be used for the different one?

Does sql profile has anything to do with parallel degree for a sql statement?

No matter the number of parallel degree used in the sql profile, if the table property has a degree of n, then parallel n is used for the sql statement during execution unless any hint is specified explicitly to override the table property.

Set the table property for parallel as 8.

SQL> ALTER TABLE ytbl parallel 8;

Table altered.

Execute the query and check the parallel used for the query. There are 8 parallel slaves spawned for the query.

SQL> SELECT * from ytbl;

SQL>col spid for a10
SQL>set lines 200 pages 1000
col NAME for a20
SELECT pxp.server_name,pxp.status,pxp.spid,
       pss.sid,pss.serial#,pss.qcsid,pss.qcserial#,
       pss.degree,pss.req_degree,sn.name,sum(pss.value) Value
FROM v$px_sesstat pss
INNER JOIN v$statname sn on ( pss.statistic# = sn.statistic# )
INNER JOIN v$px_process pxp on ( pxp.sid = pss.sid )
WHERE pss.value <> 0
AND name like '%physical reads%'
GROUP BY pss.sid,pss.serial#,pss.qcsid,pss.qcserial#,
         pss.degree,pss.req_degree,sn.name,
         pxp.server_name,pxp.status,pxp.spid
ORDER BY sn.name;SQL>SQL>  2    3    4    5    6    7    8    9   10   11   12

SERV STATUS    SPID              SID    SERIAL#      QCSID  QCSERIAL#     DEGREE REQ_DEGREE NAME                      VALUE
---- --------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -------------------- ----------
P004 IN USE    36800             265         28        237      48799          8          8 physical reads              341
P007 IN USE    36806              33       6187        237      48799          8          8 physical reads              312
P005 IN USE    36802             270      20347        237      48799          8          8 physical reads              312
P001 IN USE    26532              38      35986        237      48799          8          8 physical reads              312
P006 IN USE    36804              37      40124        237      48799          8          8 physical reads              312
P003 IN USE    26557             273      41465        237      48799          8          8 physical reads              312
P002 IN USE    26555              32      50163        237      48799          8          8 physical reads              312
P000 IN USE    26530             263      56350        237      48799          8          8 physical reads              312
P004 IN USE    36800             265         28        237      48799          8          8 physical reads direc        341
                                                                                            t

P007 IN USE    36806              33       6187        237      48799          8          8 physical reads direc        312
                                                                                            t

P005 IN USE    36802             270      20347        237      48799          8          8 physical reads direc        312
                                                                                            t

P001 IN USE    26532              38      35986        237      48799          8          8 physical reads direc        312
                                                                                            t

P006 IN USE    36804              37      40124        237      48799          8          8 physical reads direc        312
                                                                                            t

P003 IN USE    26557             273      41465        237      48799          8          8 physical reads direc        312
                                                                                            t

P002 IN USE    26555              32      50163        237      48799          8          8 physical reads direc        312
                                                                                            t

P000 IN USE    26530             263      56350        237      48799          8          8 physical reads direc        312
                                                                                            t


16 rows selected.

Check the sql id and hash value for the sql

SQL> SELECT SQL_ID,PLAN_HASH_VALUE from v$sql_plan WHERE sql_id='a6bwkq27kb1j2';

SQL_ID        PLAN_HASH_VALUE
------------- ---------------
a6bwkq27kb1j2       192604670
a6bwkq27kb1j2       192604670
a6bwkq27kb1j2       192604670
a6bwkq27kb1j2       192604670
a6bwkq27kb1j2       192604670

Check the execution plan for the sql. Degree 8 is used.

SQL> SELECT * from table(dbms_xplan.display_cursor());

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID  a6bwkq27kb1j2, child number 0
-------------------------------------
SELECT * from ytbl

Plan hash value: 192604670

--------------------------------------------------------------------------------------------------------------
| Id  | Operation            | Name     | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
--------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT     |          |       |       |   310 (100)|          |        |      |            |
|   1 |  PX COORDINATOR      |          |       |       |            |          |        |      |            |
|   2 |   PX SEND QC (RANDOM)| :TQ10000 |   986K|   217M|   310   (1)| 00:00:01 |  Q1,00 | P->S | QC (RAND)  |
|   3 |    PX BLOCK ITERATOR |          |   986K|   217M|   310   (1)| 00:00:01 |  Q1,00 | PCWC |            |
|*  4 |     TABLE ACCESS FULL| YTBL     |   986K|   217M|   310   (1)| 00:00:01 |  Q1,00 | PCWP |            |
--------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   4 - access(:Z>=:Z AND :Z<=:Z)

Note
-----
   - dynamic statistics used: dynamic sampling (level=2)
   - Degree of Parallelism is 8 because of table property


26 rows selected.

Merge the sql id and execution plan to create a sql profile script.

SQL> @coe_xfr_sql_profile.sql a6bwkq27kb1j2 192604670

Parameter 1:
SQL_ID (required)



PLAN_HASH_VALUE AVG_ET_SECS
--------------- -----------
      192604670       1.241
......
Execute coe_xfr_sql_profile_a6bwkq27kb1j2_192604670.sql
on TARGET system in order to create a custom SQL Profile
with plan 192604670 linked to adjusted sql_text.


COE_XFR_SQL_PROFILE completed.

SQL>@coe_xfr_sql_profile_a6bwkq27kb1j2_192604670.sql


... manual custom SQL Profile has been created


COE_XFR_SQL_PROFILE_a6bwkq27kb1j2_192604670 completed

Check if the sql profile is used for the sql.

SQL>col SQL_TEXT for a20
SQL>col SQL_PROFILE for a20
SQL>SELECT sql_id,sql_text,sql_profile FROM v$sql WHERE sql_id='a6bwkq27kb1j2';

SQL_ID        SQL_TEXT             SQL_PROFILE
------------- -------------------- --------------------
a6bwkq27kb1j2 SELECT * from ytbl   coe_a6bwkq27kb1j2_19
                                   2604670

SQL profile is executed with degree of parallelism from table property.

SQL> SELECT * from table(dbms_xplan.display_cursor());

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID  a6bwkq27kb1j2, child number 0
-------------------------------------
SELECT * from ytbl

Plan hash value: 192604670

--------------------------------------------------------------------------------------------------------------
| Id  | Operation            | Name     | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
--------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT     |          |       |       |   310 (100)|          |        |      |            |
|   1 |  PX COORDINATOR      |          |       |       |            |          |        |      |            |
|   2 |   PX SEND QC (RANDOM)| :TQ10000 |  1000K|    49M|   310   (1)| 00:00:01 |  Q1,00 | P->S | QC (RAND)  |
|   3 |    PX BLOCK ITERATOR |          |  1000K|    49M|   310   (1)| 00:00:01 |  Q1,00 | PCWC |            |
|*  4 |     TABLE ACCESS FULL| YTBL     |  1000K|    49M|   310   (1)| 00:00:01 |  Q1,00 | PCWP |            |
--------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   4 - access(:Z>=:Z AND :Z<=:Z)

Note
-----
   - Degree of Parallelism is 8 because of table property
   - SQL profile coe_a6bwkq27kb1j2_192604670 used for this statement


26 rows selected.

To check the contents of the sql profile, use the below query. Note that there is no parallel hints in the sql profile and parallelism is independent of sql profile created

SQL>SELECT extractvalue(VALUE(ohint), '.') "Outline hint" from DBMSHSXP_SQL_PROFILE_ATTR sp, TABLE(xmlsequence(extract(xmltype(sp.comp_data), '/outline_data/hint'))) ohint WHERE profile_name='coe_a6bwkq27kb1j2_192604670';

Outline hint
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('19.1.0')
DB_VERSION('19.1.0')
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
FULL(@"SEL$1" "YTBL"@"SEL$1")
END_OUTLINE_DATA

8 rows selected.

Increase the parallel at table level.

SQL>ALTER TABLE ytbl parallel 16;

Table altered.

Irrespective of the number of degree of parallel, sql profile is used for the query.

SQL> SELECT * from table(dbms_xplan.display_cursor());

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID  a6bwkq27kb1j2, child number 0
-------------------------------------
SELECT * from ytbl

Plan hash value: 192604670

--------------------------------------------------------------------------------------------------------------
| Id  | Operation            | Name     | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
--------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT     |          |       |       |   155 (100)|          |        |      |            |
|   1 |  PX COORDINATOR      |          |       |       |            |          |        |      |            |
|   2 |   PX SEND QC (RANDOM)| :TQ10000 |  1000K|    49M|   155   (1)| 00:00:01 |  Q1,00 | P->S | QC (RAND)  |
|   3 |    PX BLOCK ITERATOR |          |  1000K|    49M|   155   (1)| 00:00:01 |  Q1,00 | PCWC |            |
|*  4 |     TABLE ACCESS FULL| YTBL     |  1000K|    49M|   155   (1)| 00:00:01 |  Q1,00 | PCWP |            |
--------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   4 - access(:Z>=:Z AND :Z<=:Z)

Note
-----
   - Degree of Parallelism is 16 because of table property
   - SQL profile coe_a6bwkq27kb1j2_192604670 used for this statement


26 rows selected.

Check the parallel properties for degree.

SQL> show parameter parallel_degree

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
containers_parallel_degree           integer     65535
parallel_degree_limit                string      CPU
parallel_degree_policy               string      MANUAL

Change the parallel_degree_policy to auto and parallel degree limit to a value other than default value CPU.

SQL> ALTER SYSTEM set parallel_degree_policy=AUTO;

System altered.


SQL> ALTER SYSTEM set parallel_degree_limit=8;

System altered.

Disable the parallel for the table.

SQL> ALTER TABLE ytbl parallel 1;

Table altered.

Now, full table scan is used without parallel. Also same sql profile can be seen used for multiple plans as well.

SQL> SELECT * from table(dbms_xplan.display_cursor());

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID  a6bwkq27kb1j2, child number 1
-------------------------------------
SELECT * from ytbl

Plan hash value: 2390399380

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |       |       |  2232 (100)|          |
|   1 |  TABLE ACCESS FULL| YTBL |  1000K|    49M|  2232   (1)| 00:00:01 |
--------------------------------------------------------------------------

Note
-----
   - SQL profile coe_a6bwkq27kb1j2_192604670 used for this statement


17 rows selected.

Another observation is that, even if the sql id change for the query, still the profile is used!!

SQL> SELECT * from table(dbms_xplan.display_cursor());

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID  82fsp243u4fxg, child number 0
-------------------------------------
SELECT  * from ytbl

Plan hash value: 2390399380

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |       |       |  2232 (100)|          |
|   1 |  TABLE ACCESS FULL| YTBL |  1000K|    49M|  2232   (1)| 00:00:01 |
--------------------------------------------------------------------------

Note
-----
   - SQL profile coe_a6bwkq27kb1j2_192604670 used for this statement


17 rows selected.

After changing the query logic itself, the sql profile cannot be used.

SQL> SELECT * from table(dbms_xplan.display_cursor());

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID  9yhf852k9177m, child number 0
-------------------------------------
SELECT * from ytbl WHERE rownum < 5

Plan hash value: 1669163498

---------------------------------------------------------------------------
| Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |      |       |       |     2 (100)|          |
|*  1 |  COUNT STOPKEY     |      |       |       |            |          |
|   2 |   TABLE ACCESS FULL| YTBL |     4 |   208 |     2   (0)| 00:00:01 |
---------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter(ROWNUM<5)

Note
-----
   - automatic DOP: Computed Degree of Parallelism is 1 because of parallel threshold


23 rows selected.

Drop the sql profile.

SQL> BEGIN
DBMS_SQLTUNE.DROP_SQL_PROFILE('coe_a6bwkq27kb1j2_192604670');
END;
/  2    3    4

PL/SQL procedure successfully completed.

Another way to use parallel with sql profile is to use parallel hint in the sql and create a sql profile on top of the parallel plan.

SQL> ALTER table ytbl parallel 1;

Table altered.

SQL> SELECT /*+parallel(16)*/ * from ytbl;


SQL>SELECT * from table(dbms_xplan.display_cursor());

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID  68fn0x88bm4jc, child number 0
-------------------------------------
SELECT /*+parallel(16)*/ * from ytbl

Plan hash value: 192604670

--------------------------------------------------------------------------------------------------------------
| Id  | Operation            | Name     | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
--------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT     |          |       |       |   155 (100)|          |        |      |            |
|   1 |  PX COORDINATOR      |          |       |       |            |          |        |      |            |
|   2 |   PX SEND QC (RANDOM)| :TQ10000 |  1000K|    49M|   155   (1)| 00:00:01 |  Q1,00 | P->S | QC (RAND)  |
|   3 |    PX BLOCK ITERATOR |          |  1000K|    49M|   155   (1)| 00:00:01 |  Q1,00 | PCWC |            |
|*  4 |     TABLE ACCESS FULL| YTBL     |  1000K|    49M|   155   (1)| 00:00:01 |  Q1,00 | PCWP |            |
--------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   4 - access(:Z>=:Z AND :Z<=:Z)

Note
-----
   - Degree of Parallelism is 16 because of hint
   - SQL profile coe_68fn0x88bm4jc_192604670 used for this statement


26 rows selected.