Skip to main content

How to export schema or table statistics in oracle


<<Back to Oracle DATAPUMP Main Page

How to export schema or table statistics in oracle

Step1> create an staging table to hold the stats
BEGIN
  DBMS_STATS.CREATE_STAT_TABLE (
    ownname => 'TEST'
,   stattab => 'SCHEMA_STAT_TEST'
,   tblspace => 'USERS'
);
END;
/

PL/SQL procedure successfully completed.

Step2> Verify the Staging Table Details
SQL> select owner,table_name from dba_tables where table_name='SCHEMA_STAT_TEST'
OWNER                          TABLE_NAME
------------------------------ ----------------------------------------
TEST                       SCHEMA_STAT_TEST
1 row selected.
 SQL> select count(*) from TEST.SCHEMA_STAT_TEST;
  COUNT(*)
----------
         0
1 row selected.
To see the structure of the table you can describe it
SQL> desc TEST.SCHEMA_STAT_TEST
Now that we are done with the table prepration that is going to hold the stats, lets export the stats of schema TEST in table SCHEMA_STAT_TEST
Step3> Export Schema Stats.
BEGIN
  DBMS_STATS.EXPORT_SCHEMA_STATS (
    ownname => 'TEST'
,   stattab => 'SCHEMA_STAT_TEST'
);
END;
/

PL/SQL procedure successfully completed.

OR
Export Table Stats.
To export Table Stats run below procedure
BEGIN
  DBMS_STATS.EXPORT_TABLE_STATS (
    ownname => 'TEST'
, tabname => 'EMPLOYEES'
,   stattab => 'SCHEMA_STAT_TEST'
);
END;
/

Step3> export the table SCHEMA_STAT_TEST using expdp utility
Now since the table SCHEMA_STAT_TEST is populated with Status you  can simply export this table using expdp command and you are done.
$cat parfile=export.par
directory=EXT
dumpfile=EXP_TEST_SCHEMA_STATS_%U.dmp
FILESIZE=20G
logfile=EXP_TEST_SCHEMA_STATS_.log
tables=TEST.SCHEMA_STAT_TEST
$  expdp system@TST1P parfile=export.par
Export: Release 12.1.0.2.0 - Production on Fri Feb 8 11:16:29 2019
Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.
Password:
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, Oracle Label Security,
OLAP, Advanced Analytics and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_TABLE_01":  system/********@TST1P parfile=export.par
........................................................
........................................................
 . exported "TEST"."SCHEMA_STAT_TEST"           612.4 MB 4005725 rows
Master table "SYSTEM"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_TABLE_01 is:
  /u01/app/oracle/backup/EXT/EXP_TEST_SCHEMA_STATS_01.dmp
Job "SYSTEM"."SYS_EXPORT_TABLE_01" successfully completed at Fri Feb 8 11:17:41 2019 elapsed 0 00:01:05

Step4> Optionally drop the staging stats table
BEGIN
  DBMS_STATS.DROP_STAT_TABLE (
    ownname => 'TEST'
,   stattab => 'SCHEMA_STAT_TEST'
);
END;
/

Comments

Popular posts from this blog

ORA-28374: typed master key not found in wallet

<<Back to Oracle DB Security Main Page ORA-46665: master keys not activated for all PDBs during REKEY SQL> ADMINISTER KEY MANAGEMENT SET KEY FORCE KEYSTORE IDENTIFIED BY xxxx WITH BACKUP CONTAINER = ALL ; ADMINISTER KEY MANAGEMENT SET KEY FORCE KEYSTORE IDENTIFIED BY xxxx WITH BACKUP CONTAINER = ALL * ERROR at line 1: ORA-46665: master keys not activated for all PDBs during REKEY I found following in the trace file REKEY: Create Key in PDB 3 resulted in error 46658 *** 2019-02-06T15:27:04.667485+01:00 (CDB$ROOT(1)) REKEY: Activation of Key AdnU5OzNP08Qv1mIyXhP/64AAAAAAAAAAAAAAAAAAAAAAAAAAAAA in PDB 3 resulted in error 28374 REKEY: Keystore needs to be restored from the REKEY backup.Aborting REKEY! Cause: All this hassle started because I accidently deleted the wallet and all wallet backup files too and also forgot the keystore password. There was no way to restore the wallet back. Fortunately in my case the PDB which had encrypted data was supposed to be deco...

[FATAL] [INS-30024] Oracle Grid Infrastructure Installation

<<Back to DB Administration Main Page [FATAL] [INS-30024] Installer has detected that the location determined as Oracle Grid Infrastructure home is not a valid Oracle home $ /u01/grid/12.2.0.1/grid/gridSetup.sh -silent -ignorePrereqFailure  -responseFile /u01/grid/12.2.0.1/grid/install/response/gridsetup.r sp Launching Oracle Grid Infrastructure Setup Wizard... [FATAL] [INS-30024] Installer has detected that the location determined as Oracle Grid Infrastructure home (/u01/app/12.1.0.2/grid/grid), is not a valid Oracle home. ACTION: Ensure that either there are no environment variables pointing to this invalid location or register the location as an Oracle home in the central inventory. Solution: Rename  olr.loc and  ocr.loc and unset the oracle related variables and re-run the installation #  mv /etc/oracle/olr.loc /etc/oracle/olr.loc_orig #  mv /etc/oracle/ocr.loc /etc/oracle/ocr.loc_orig $unset ORACLE_HOME $unset ORACLE_BASE $unset ORACLE_SI...

INS-30508 Invalid ASM disks

<<Back to Oracle ASM Main Page [FATAL] [INS-30508] Invalid ASM disks.    CAUSE: The disks [/dev/xvdc8] were not valid.    ACTION: Please choose or enter valid ASM disks. Solution: Solution of  this problem is to provide valid ASM disks. You can provide ASM instance a valid ASM disks in following ways. Solution1: Configure udev rules for raw devices and use them for ASM disk #cd /etc/udev/rules.d #vi 60-raw.rules and add entry like this in 60-raw.rules. Make one entry for each disk ACTION=="add", KERNEL=="xvdc9", RUN+="/bin/raw /dev/raw/raw9 %N" ACTION=="add", KERNEL=="raw*", OWNER=="oracle", GROUP=="oinstall",MODE=="0660" save and exit Start Udev Service # start_udev Starting udev:                                             [  OK  ] # udevadm control --reload-rules # ls -ltr /dev/raw/raw9 crw-rw-...

How to Find VIP of an Oracle RAC Cluster

<<Back to Oracle RAC Main Page How to Find Out VIP of an Oracle RAC Cluster Login clusterware owner (oracle) and execute the below command to find out the VIP hostname used in Oracle RAC $ olsnodes -i node1     node1-vip node2     node2-vip OR $ srvctl config nodeapps -viponly Network 1 exists Subnet IPv4: 10.0.0.0/255.255.0.0/bondeth0, static Subnet IPv6: Ping Targets: Network is enabled Network is individually enabled on nodes: Network is individually disabled on nodes: VIP exists: network number 1, hosting node node1 VIP Name: node1-vip VIP IPv4 Address: 10.0.0.1 VIP IPv6 Address: VIP is enabled. VIP is individually enabled on nodes: VIP is individually disabled on nodes: VIP exists: network number 1, hosting node node2 VIP Name: node2-vip VIP IPv4 Address: 10.0.0.2 VIP IPv6 Address: VIP is enabled. VIP is individually enabled on nodes: VIP is individually disabled on nodes:

ORA-65104: operation not allowed on an inactive pluggable database alter pluggable database open

<<Back to DB Administration Main Page ORA-65104: operation not allowed on an inactive pluggable database SQL> alter pluggable database TEST_CLON open; alter pluggable database TEST_CLON open * ERROR at line 1: ORA-65104: operation not allowed on an inactive pluggable database Cause The pluggable database status was UNUSABLE. It was still being created or there was an error during the create operation. A PDB can only be opened if it is successfully created and its status is marked as NEW in cdb_pdbs.status column SQL> select PDB_NAME,STATUS from cdb_pdbs; PDB_NAME             STATUS -------------------- --------------------------- PDB$SEED             NORMAL TEST_CLON            UNUSABLE Solution:  Drop the PDB and create it again. Related Posts How to Clone Oracle PDB (Pluggable Database) with in the Same Container

How to Install JAVA JVM Component into an Existing Oracle Database

<<Back to DB Administration Main Page How to Add the JVM Component to an Existing Oracle Database Followed oracle Doc ID 1461562.1 and installed oracle JVM component in multitenant database, the script installed JVM component in CDB$ROOT container only and the component was still missing in PDB$SEED and all pluggable database. Since the script and steps mentioned in Doc ID 1461562.1 did not install the component in PDB$SEED , all future PDBs create in the container also inherited the issue and eventually JVM  component was not installed in any of the PDBs. Scroll down to see how to install JVM component in a Multitenant Database environment using catcon.pl How to Verify if JVM component is installed or not select comp_name, version, status from dba_registry where comp_name like '%JAVA%' ; COMP_NAME                           ...

How to Export and Import TDE Master Encryption Key

<<Back to Oracle DB Security Main Page In many cases you need to export the TDE Master Encryption Key and Import it in same or different database. For Example: If you want to migrate a PDB (Using Encryption) from one CDB to another, you must export the TDE Keys from source CDB and import it in Target CDB. How To Export TDE Master Encryption Key SQL> ADMINISTER KEY MANAGEMENT EXPORT ENCRYPTION KEYS WITH SECRET "any password to protect export file" TO 'file_path' IDENTIFIED BY keystore_password If you run the above statement in PDB it will export the keys for that PDB only SQL> alter session set container=PDB01 ; Session altered. SQL> ADMINISTER KEY MANAGEMENT EXPORT ENCRYPTION KEYS WITH SECRET "mysecret" TO '/home/dbatst1/Wallet/PDB01_TDE.KEY' IDENTIFIED BY keystore_password; keystore altered. NOTE : You can only export the keys if the password based wallet is open in case AUTOLOGIN wallet is open you can export the keys eit...

ORA-46630: keystore cannot be created at the specified location

<<Back to DB Administration Main Page ORA-46630: keystore cannot be created at the specified location CDB011> ADMINISTER KEY MANAGEMENT CREATE KEYSTORE '+DATAC4/CDB01/wallet/' IDENTIFIED BY "xxxxxxx"; ADMINISTER KEY MANAGEMENT CREATE KEYSTORE '+DATAC4/CDB01/wallet/' IDENTIFIED BY "EncTest123" * ERROR at line 1: ORA-46630: keystore cannot be created at the specified location Cause  Creating a keystore at a location where there is already a keystore exists Solution To solve the problem, use a different location to create a keystore (use ENCRYPTION_WALLET_LOCATION in sqlnet.ora file to specify the keystore location), or move this ewallet.p12 file to some other location. Note: Oracle does not recommend deleting keystore file (ewallet.p12) that belongs to a database. If you have multiple keystores, you can choose to merge them rather than deleting either of them.

ORA-46655: no valid keys in the file from which keys are to be imported

<<Back to DB Administration Main Page SQL> administer key management import encryption keys with secret "xxxx" from '/tmp/pdb02_tde_key.exp' force keystore identified by "xxxx" with backup; administer key management import encryption keys with secret "xxxxxx" from '/tmp/pdb02_tde_key.exp' force keystore identified by "xxxxxx" with backup * ERROR at line 1: ORA-46655: no valid keys in the file from which keys are to be imported Cause: Either the keys to be imported already present in the target database or correct container (PDB) is not set. Solution: In my case I got the error because I attempted to import the keys for newly plugged database PDB02 from CDB$ROOT container. To Solve the issue just switched to the correct container and re run the import. SQL> show con_name CON_NAME ------------------------------ CDB$ROOT <===Wrong Container selected  SQL> alter session set container=PDB02; Session alt...

WARNING - My Oracle Support Username/Email Address Not Specified

<<Back to DB Administration Main Page [WARNING] - My Oracle Support Username/Email Address Not Specified ./runInstaller -silent -ignoreSysPrereqs -showProgress -skipPrereqs -responseFile /u01/app/stage/database/response/db_install.rsp Starting Oracle Universal Installer... Checking Temp space: must be greater than 500 MB.   Actual 1204 MB    Passed Checking swap space: must be greater than 150 MB.   Actual 4095 MB    Passed Preparing to launch Oracle Universal Installer from /tmp/OraInstall2019-01-23_02-41-56PM. Please wait ... [WARNING] - My Oracle Support Username/Email Address Not Specified Solution: Set the following parameter in response file as shown below SECURITY_UPDATES_VIA_MYORACLESUPPORT=false DECLINE_SECURITY_UPDATES=true