Thursday, February 8, 2024
Optimizing Storage and Performance with Oracle Database Advanced Compression
Friday, September 13, 2019
import a single table from a full export backup in oracle
import a single table from a full export backup and remap it
impdp USERNAME/PASSWORD tables=SCHEMA.TABLE_NAME directory=DPUMP dumpfile=DUMPFILE_%U.dmp
remap_schema=SOURCE:TARGET
REMAP_TABLE=TABLE_NAME:TABLE_NAME_NEW
Optional things above :
- Remove remap if you don't want.
- Add ENCRYPTION_PASSWORD=IF_ANY
Friday, February 2, 2018
Restoring archive logs from an RMAN backup
Restoring archive logs from an RMAN backup is a common task when you need to recover database transactions to a specific point in time. The commands you've provided are examples of how to restore archive logs using RMAN (Recovery Manager). Below are explanations of each command:
1. Using RESTORE ARCHIVELOG FROM LOGSEQ ... UNTIL LOGSEQ ... THREAD
sql
RMAN> RESTORE ARCHIVELOG FROM LOGSEQ=37501 UNTIL LOGSEQ=37798 THREAD=1;
Purpose: This command restores archive logs from the RMAN backup, specifically those logs that fall between the log sequence numbers 37501 and 37798 for the specified thread (in this case, thread 1).
Parameters:
FROM LOGSEQ=37501: Specifies the starting sequence number of the archive logs you want to restore.UNTIL LOGSEQ=37798: Specifies the ending sequence number of the archive logs to restore.THREAD=1: Indicates the thread number (useful in RAC environments where there are multiple redo threads).
Use Case: This approach is ideal when you know the exact range of log sequences you need to restore and want to limit the restoration to a specific thread.
2. Using RESTORE ARCHIVELOG BETWEEN SEQUENCE ... AND ...
sql
RMAN> RESTORE ARCHIVELOG BETWEEN SEQUENCE 37501 AND 37798;
Purpose: This command restores all archive logs between the specified sequence numbers (37501 to 37798) from all threads unless a specific thread is specified elsewhere.
Parameters:
BETWEEN SEQUENCE 37501 AND 37798: Specifies the range of archive log sequences you want to restore.
Use Case: This command is useful when you want to restore a continuous range of archive logs across all threads without specifying individual thread numbers.
Key Points:
- Ensure that the archive logs you are restoring are available in your RMAN backup.
- These commands do not apply the restored archive logs; they only restore them to the specified location (usually the archive log destination).
- Check the current location and status of the logs using RMAN commands such as
LIST BACKUP OF ARCHIVELOGbefore performing the restore operation. - It's critical to be cautious with thread specification, especially in RAC environments, to avoid restoring unnecessary logs or missing required logs.
These commands are powerful tools for managing archive log restoration and can help ensure that you have the necessary logs for database recovery or point-in-time recovery operations.
Monday, October 16, 2017
set up the OPatch environment variable for Oracle Patching
To set up the OPatch environment variable, you need to add the OPatch directory (located within your Oracle Home) to your system’s PATH variable. This allows you to run OPatch commands directly from any shell prompt without specifying the full path. Below are the steps for setting up the PATH environment variable for both Korn/Bourne shells (like sh, bash, ksh) and C Shell (csh, tcsh).
Setting Up OPatch Environment Variable
For Korn Shell (ksh), Bourne Shell (sh), and Bash Shell:
Use the
exportcommand to modify thePATHvariable.sh:# Add OPatch to the PATH export PATH=$PATH:$ORACLE_HOME/OPatch- Explanation:
export PATH=$PATH:$ORACLE_HOME/OPatch: This command appends the OPatch directory to the currentPATHvariable, making the OPatch utility accessible from the command line.$ORACLE_HOME/OPatch: Refers to the OPatch directory within the Oracle Home path.
- Explanation:
For C Shell (
csh,tcsh):Use the
setenvcommand to update thePATHvariable.csh:# Add OPatch to the PATH setenv PATH $PATH:$ORACLE_HOME/OPatch- Explanation:
setenv PATH $PATH:$ORACLE_HOME/OPatch: This command updates thePATHvariable by appending the OPatch directory, allowing OPatch commands to be run without specifying the full path.
- Explanation:
Important Notes:
- Ensure Oracle Home is Set: Before running these commands, make sure the
ORACLE_HOMEenvironment variable is correctly set to your Oracle installation path. You can verify it usingecho $ORACLE_HOME. - Persistent Changes: To make these changes persistent across sessions, add the corresponding command to your shell’s startup file (
~/.bash_profile,~/.profilefor Bash/Korn shell or~/.cshrcfor C shell). - Verify OPatch: After setting the variable, verify the setup by running
opatch versionto ensure that the command is accessible and the correct OPatch version is in use.
This setup is crucial for applying patches and managing updates in your Oracle environment effectively using OPatch
Tuesday, September 12, 2017
Simple Oracle Plsql Package for password encryption and decryption
Simple Oracle Plsql Package for password encryption and decryption
Introduction:
The script provided demonstrates how to create a simple password encryption and decryption package in Oracle using the DBMS_OBFUSCATION_TOOLKIT. Below is a step-by-step breakdown of each part of the code:
1. Setting Up the Environment:
Before running the package, it is recommended to connect to the database as SYSDBA and run the script ?/rdbms/admin/catobtk.sql. This script installs the DBMS_OBFUSCATION_TOOLKIT package necessary for encryption and decryption functionalities.
2. Creating the Table USERS_INFO:
The table USERS_INFO is created to store usernames and encrypted passwords.
3. Creating the Package Specification PASSWORD:
The package specification defines two functions: encrypt and decrypt. These functions will handle the encryption and decryption of passwords.
CREATE OR REPLACE PACKAGE PASSWORD AS
function encrypt(i_password varchar2) return varchar2;
function decrypt(i_password varchar2) return varchar2;
END PASSWORD;
/
show errors
4. Creating the Package Body PASSWORD:
The package body implements the actual logic for the encrypt and decrypt functions using Oracle's DBMS_OBFUSCATION_TOOLKIT.
Key Points:
- The encryption key (
c_encrypt_key) must be exactly 8 bytes long. - Input data for encryption must have a length divisible by eight, achieved using
RPADto pad the input string.
5. Testing the Encryption and Decryption:
The following SQL statements test the encryption and decryption functions:
select password.decrypt(app_password.encrypt('PASSWORD1')) from dual;
select password.encrypt('PSW2') from dual;
select password.decrypt(app_password.encrypt('PSW2')) from dual;
6. Inserting and Retrieving Encrypted Data:
The script demonstrates inserting an encrypted password into the USERS_INFO table and then retrieving and decrypting it.
insert into USERS_INFO values ('redddy',( select password.encrypt('REDDY1') from dual) );
select password.decrypt((pass)) from USERS_INFO where USERNAME='redddy';
Important Notes:
- Security Considerations: The
DBMS_OBFUSCATION_TOOLKITuses DES encryption, which is considered outdated and insecure by modern standards. It’s recommended to useDBMS_CRYPTOfor more robust encryption methods, such as AES. - Error Handling: The script should include error handling to manage issues that may arise during encryption or decryption processes.
- Testing and Validation: Always test encryption and decryption thoroughly, especially when dealing with sensitive data like passwords, to ensure the correct implementation.
This setup demonstrates basic encryption and decryption using Oracle's built-in toolkit, providing a foundation for enhancing database security.
Friday, July 14, 2017
update rows from multiple tables (correlated update)
Cross table update (also known as correlated update, or multiple table update) in Oracle uses non-standard SQL syntax format (non ANSI standard) to update rows in another table. The differences in syntax are quite dramatic compared to other database systems like MS SQL Server or MySQL.
In this article, we are going to look at four scenarios for Oracle cross table update.
Suppose we have two tables Categories and Categories_Test. See screenshots below.
lets take two tables TABA & TABB:
Records in TABA:
Records in TABB:
1. Update data in a column LNAME in table A to be upadted with values from common column LNAME in table B.
The update query below shows that the PICTURE column LNAME is updated by looking up the same ID value in ID column in table TABA and TABB.
update TABA A
set (a.LNAME) = (select B.LNAME FROM TABB B where A.ID=B.ID);
2. Update data in two columns in table A based on a common column in table B.
If you need to update multiple columns simultaneously, use comma to separate each column after the SET keyword.
update TABA A
set (a.LNAME, a.SAL) = (select B.LNAME, B.SAL FROM TABB B where A.ID=B.ID);
Friday, June 2, 2017
How Secure Can We Make Our Oracle Databases?
How Secure Can We Make Our Oracle Databases?
- Grant Access on a Need-to-Know Basis
Always follow the principle of least privilege by granting access only to users who genuinely need it. This minimizes exposure and reduces the risk of unauthorized actions within the database.2. Remove Unnecessary Grants and Privileges
Regularly review and clean up unnecessary permissions from users and roles. Privileges that are no longer needed should be revoked to prevent misuse or accidental data exposure.3. Audit Failed Logins Regularly
4. Evaluate Requests for Elevated Privileges
When a user requests elevated privileges, always engage in a conversation to understand their requirements. Assess if the elevated access is genuinely necessary and grant it only if justified.5. Grant the Minimum Required Access
Ensure that users are granted no more access than what is absolutely necessary for their tasks. Avoid giving broad permissions, as this increases the risk of accidental or malicious actions.6. Manage Temporary Access Carefully
Sometimes, users need access temporarily for specific tasks. Make sure to track and revoke these temporary permissions immediately after the task is completed to maintain security.7. Define Clear Boundaries for Data Access
Clearly define which users can access specific data. Implement fine-grained access control to restrict access to sensitive data based on roles and responsibilities.8. Use User Profiles and Audit Features
9. Enforce Complex Password Policies
Implement strong password policies that require complexity and regular changes. Complex passwords significantly enhance security by making unauthorized access more difficult. Here is the Link on how to do it10. Use Triggers to Track User Activity
11. Encrypt Passwords in Applications
Ensure that passwords used in applications are encrypted. Storing plain-text passwords poses a significant security threat, especially if application code is compromised.12. Secure the Oracle Listener with a Password
Protect your Oracle Listener with a password to prevent unauthorized access and control over database connections. This adds an additional layer of security to your database environment.13. Restrict Access to Known Servers and Clients
Use Oracle’sVALID_NODE_CHECKING feature to restrict database access to specific, known servers or clients. This helps protect your database from unauthorized network access. Use this Valid_node_checking Link on how to restrict access to servers/clients.Conclusion
Thursday, December 15, 2016
java.lang.SecurityException: The jurisdiction policy files are not signed by a trusted signer
I was trying to Install OID (Oracle Identity Manager) and I got this error :
Problem:
at oracle.as.install.engine.modules.configuration.standard.StandardConfigActionManager.start(StandardConfigActionManager.java:186)
at oracle.as.install.engine.modules.configuration.boot.ConfigurationExtension.kickstart(ConfigurationExtension.java:81)
at oracle.as.install.engine.modules.configuration.ConfigurationModule.run(ConfigurationModule.java:86)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.SecurityException: Can not initialize cryptographic mechanism
at javax.crypto.JceSecurity.<clinit>(JceSecurity.java:88)
... 31 more
Caused by: java.lang.SecurityException: The jurisdiction policy files are not signed by a trusted signer!
at javax.crypto.JarVerifier.verifyPolicySigned(JarVerifier.java:328)
at javax.crypto.JceSecurity.loadPolicies(JceSecurity.java:317)
at javax.crypto.JceSecurity.setupJurisdictionPolicies(JceSecurity.java:262)
at javax.crypto.JceSecurity.access$000(JceSecurity.java:48)
at javax.crypto.JceSecurity$1.run(JceSecurity.java:80)
at java.security.AccessController.doPrivileged(Native Method)
at javax.crypto.JceSecurity.<clinit>(JceSecurity.java:77)
Cause:
My current version of java was 1.8.* which is not fully supported.
In this case JDK 1.8.0.1 is installed on all nodes in the cluster and JCE local policy version 6 was used for AES 256 kerberos encryption. JCE must be in sync with the JDK version.
[oracle@linux06 jdk1.8.0_111]$ cd ..
[oracle@linux06 java]$ ls
default jdk1.8.0_111 latest
[oracle@linux06 java]$ cd default/
[oracle@linux06 default]$ ls
bin javafx-src.zip man THIRDPARTYLICENSEREADME-JAVAFX.txt
COPYRIGHT jre README.html THIRDPARTYLICENSEREADME.txt
db lib release
include LICENSE src.zip
Solution:
Download :
For Java 6 use :
http://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.html
For Java 7 use :
http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html
For java 8 use :
http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html
******************** ******************** ********************
Update java with with new java unlimted jusrisdiction :
******************** ******************** ********************
After download and unzip :
[oracle@linux06 JCE]$ unzip jce_policy-8.zip
Archive: jce_policy-8.zip
creating: UnlimitedJCEPolicyJDK8/
inflating: UnlimitedJCEPolicyJDK8/local_policy.jar
inflating: UnlimitedJCEPolicyJDK8/README.txt
inflating: UnlimitedJCEPolicyJDK8/US_export_policy.jar
[oracle@linux06 JCE]$ ls -ll
total 16
-rw-rw-r--. 1 oracle oracle 8409 Dec 14 10:39 jce_policy-8.zip
drwxrwxr-x. 2 oracle oracle 4096 Dec 20 2013 UnlimitedJCEPolicyJDK8
[oracle@linux06 JCE]$ pwd
/u01/app/SFTW/JCE
[oracle@linux06 JCE]$ ls
jce_policy-8.zip UnlimitedJCEPolicyJDK8
[oracle@linux06 JCE]$ cd UnlimitedJCEPolicyJDK8/
[oracle@linux06 UnlimitedJCEPolicyJDK8]$ ls
local_policy.jar README.txt US_export_policy.jar
******************** ******************** ********************
as root user backup and replace files (US_export_policy & local_policy.jar)
******************** ******************** ********************
[oracle@linux06 security]$ su root
Password:
[root@linux06 security]# ls
blacklist java.policy local_policy.jar
blacklisted.certs java.security trusted.libraries
cacerts javaws.policy US_export_policy.jar
[root@linux06 security]# cd /usr/java/default/jre/lib/security
[root@linux06 security]# mv US_export_policy.jar US_export_policy.jar_bak
[root@linux06 security]# mv local_policy.jar local_policy.jar_bak
[root@linux06 security]# ls -ll
total 164
-rw-r--r--. 1 root root 4054 Sep 22 18:23 blacklist
-rw-r--r--. 1 root root 1273 Sep 22 18:23 blacklisted.certs
-rw-r--r--. 1 root root 112860 Sep 22 18:23 cacerts
-rw-r--r--. 1 root root 2466 Sep 22 18:23 java.policy
-rw-r--r--. 1 root root 27358 Sep 22 18:23 java.security
-rw-r--r--. 1 root root 98 Sep 22 18:23 javaws.policy
-rw-r--r--. 1 root root 3405 Sep 22 18:35 local_policy.jar_bak
-rw-r--r--. 1 root root 0 Sep 22 18:23 trusted.libraries
-rw-r--r--. 1 root root 2920 Sep 22 18:35 US_export_policy.jar_bak
[root@linux06 security]# pwd
/usr/java/default/jre/lib/security
[root@linux06 security]# cp /u01/app/SFTW/JCE/UnlimitedJCEPolicyJDK8/US_export_policy.jar /usr/java/default/jre/lib/security
[root@linux06 security]# cp /u01/app/SFTW/JCE/UnlimitedJCEPolicyJDK8/local_policy.jar /usr/java/default/jre/lib/security
[root@linux06 security]# ls -ll
total 172
-rw-r--r--. 1 root root 4054 Sep 22 18:23 blacklist
-rw-r--r--. 1 root root 1273 Sep 22 18:23 blacklisted.certs
-rw-r--r--. 1 root root 112860 Sep 22 18:23 cacerts
-rw-r--r--. 1 root root 2466 Sep 22 18:23 java.policy
-rw-r--r--. 1 root root 27358 Sep 22 18:23 java.security
-rw-r--r--. 1 root root 98 Sep 22 18:23 javaws.policy
-rw-r--r--. 1 root root 3035 Dec 14 10:47 local_policy.jar
-rw-r--r--. 1 root root 3405 Sep 22 18:35 local_policy.jar_bak
-rw-r--r--. 1 root root 0 Sep 22 18:23 trusted.libraries
-rw-r--r--. 1 root root 3023 Dec 14 10:46 US_export_policy.jar
-rw-r--r--. 1 root root 2920 Sep 22 18:35 US_export_policy.jar_bak
