Wednesday, March 24, 2021

Oracle Database SQL and PL/SQL Tricks and Tips

Oracle Database Tricks & Tips

People in the Oracle technologies they always dealing with Oracle Database related queries, need some time help, best practices should be implement in the daily activities. Here are some common daily using SQL queries which work on 12c to 19c and later as well. 

SQL commands runs on Oracle Database sqlplus, sqldeveloper
SQL commands run on Oracle Database using sqlplus, sqldeveloper
 


How to check user exists or not on Oracle DATABASE? 

 
select username from DBA_USERS;

Find connected to which user? 
SQL> show user 

How to search for specific user in the Oracle Database?

 SELECT username from DBA_USERS where username like '%DEMO%';
 USERNAME 
-------------------------------------------------------------------------------- 
DEMOADM 

How do you know RCU users account_status expired? 

Here we can query the username with 'PREFIX' containing word, and to know about EXPIRED account_status.
 
set pagesize 100
column username format a25

Select username, account_status from dba_users 
where username like '%DEMO%' and ACCOUNT_STATUS <> 'OPEN';

How do you reset the DB users account_status expired to OPEN? 

Here we have the solution we need to UNLOCK account and RESET the password with the following SQL qyery.
 
ALTER USER DEMO_OPSS  IDENTIFIED BY welcome1;

Note this will work for any Oracle DB user.
 
How to switch from CDB to PDB? 
Assuming you are already login to the CDB and the PDB name as MYPDB1 then following SQL command wilL help to switch to PDB.
alter session set container=MYPDB1;

How to check the number of PDBs present in CDB? 

Connect to the CDB with sys user as sysdba run the following: 

 SQL> show pdbs

 Note that if the same command executed inside the PDB it will show a single PDB to which you have connected or altered session.

How to restart a PDB?

To do this first you need to connect to your CDB and then issue the following SQL command in sqlplus prompt 
alter pluggable database PDBNAME close immediate;
alter pluggable database PDBNAME open;

How to check the number of processes running in your Oracle Database?

In SQLPLUS you can runt he following SHOW command:
show parameter processes

How to check the number of OPEN cursors Configured?

The following SQL command will help you to get the how many OPEN cursor can be used from your Database.
  show parameter open_cursors
  

How change the open cursors limit?

How to change the processes limit?

How to shutdown the Oracle  Database from Oracle SQLPLUS prompt?

We can use 'shutdown' command with options most commonly we use 'immediate' option in non-production Databases, we can also use 'shut' short command

shutdown immediate
or 
shut immediate
Note that never leave shut command without any argument which may leads you to wait indefinite period of time. 

How to clear the multiple break lines in the SQLPLUS? or How you can set page size?

set pages 200
Here 200 is random value you can change according to your need.


How create a  Oracle database as standalone with AL32UTF8 characterSet?

We can create database using dbca command utility, which we can run in CLI mode by giving arguments as follows:

 
  dbca -silent -createDatabase -templateName General_Purpose.dbc 
  -gdbname DEMODB -sid DEMODB -sysPassword manager -systemPassword manager 
  -emConfiguration none -datafileDestination /opt/oradata/ -redoLogFileSize 100 
  -asmsnmpPassword manager -diskGroupName data -characterSet AL32UTF8 -totalMemory 2048

How to resolve the QUOTA for a user on tablespace?

Issue # Exception was thrown: ORA-01950: no privilleges on tablespace 'USERS' 
Solution: Change the QUOTA in SOME diskspace say 100M for the 'USERS' tablespace to which user you encountered this issue. 
ORA-01950


Steps to follow: 
1. First connect to the Database box, and connect as SYS as SYSDBA
sqlplus / as sysdba
2. This will be in CDB we need to switch to our PDB that is ORCLPDB1
alter session set container=ORCLPDB1;
3. allocate the quota space for the USERS tablespace for your user as sample showing here as demouser
alter user demouser QUOTA 100M on USERS;
that's it resolved!

How do you know Oracle APEX instalbashled version?

Login with sys or system user as sysdba run the following SQL query to know the Oracle APEX version from SQL Prompt: 
select VERSION 
 from dba_registry 
 where COMP_NAME='Oracle Application Express';
  


How do you know the APEX installed on CDB with PDB?

Login to the sys as sysdba  into your CDB run the following SQL query:
  select COMP_ID, VERSION, STATUS 
   from CDB_REGISTRY 
   where COMP_ID='APEX' 
   order by CON_ID;

COMP_ID                        VERSION                        STATUS
------------------------------ ------------------------------ -----------
APEX                           20.1.0.00.13                   VALID

To know which PDB contains this APEX installed
select r.COMP_NAME, r.VERSION, c.NAME, c.CON_ID
from CDB_REGISTRY r, V$CONTAINERS c
where r.CON_ID=c.CON_ID and r.COMP_ID='APEX'
order by CON_ID;

Write your recent Database Query that saved your time a lot, Share that which you frequently use to resolve an issuee comments we appreciate your contributions!!!

Monday, February 1, 2021

Oracle APEX 20.1 Admin Account Locked - Troubleshooting

I'm working on the Upgrade project where Oracle APEX 19.1 to Oracle APEX 20.1. All the steps which are given in the documentation I've followed. Able to login the the APEX Admin as well. Here the story begans, my other team members didn't observed there is a change in the ADMIN password and tried multiple times with OLD Password, then the ADMIN user was locked. Now even though I've correct password could not able to login to the APEX admin user. 

How do we know this?

Oracle Apex Workspace Admin login had an issue, where it was configured with a passwd which was mistakenly used old and that leads to lock the ADMIN user blocked.

This APEX Login failed and say that account is blocked. There could be two reasons. First, the browser cache holding the old and wrong password so not allowing you to log in to the ADMIN account. You could try on a different browser if you are in Chrome(login issue), use Firefox or Internet Explorer try to login.

Changing browser did not work!  Then follow the below-given steps.


Navigate to the apex install director (un-compressed software location). Example (/opt/apex_20.1). First, connect to your database with the sys user.

 The better approach is to run apex_util.set_security_group_id(with appropriate arguments) and apex_util.unlock_account() procedures to unlock the admin account in Oracle Apex.

This issue we will explore more in detail now. First, get the securit_group_id
 
select * from APEX_WORKSPACE_APEX_USERS;
-- To get the APEX related users info
select * from DBA_USERS where username like 'APEX%';
-- If you found LOCKED please unlock with the following
ALTER USER APEX_INSTANCE_ADMIN_USER ACCOUNT UNLOCK;

-- switch the session to APEX ADMIN session
alter session set current_schema = APEX_200100;
-- Get all the ADMIN user details
SELECT * FROM wwv_flow_fnd_user WHERE  user_name = 'ADMIN';

-- setting secuirty group 

begin
wwv_flow_api.set_security_group_id(p_security_group_id=>nvl(wwv_flow_application_install.get_workspace_id,11workspace_id000));
end;
/

Now use that security_group_id and unlock with the following procedure from the apex folder.

 
alter session set current_schema = APEX_200100;
Session altered.
Run the above query in SQL Developer get the g_security_group_id value.
begin
    wwv_flow_security.g_security_group_id := 1467836176007596;
    wwv_flow_fnd_user_api.UNLOCK_ACCOUNT('ADMIN');
    commit;
end;
/  

PL/SQL procedure successfully completed.

SELECT * FROM wwv_flow_fnd_user WHERE  user_name = 'ADMIN';
or 
SELECT user_id,first_name,last_name, default_schema FROM wwv_flow_fnd_user WHERE  user_name = 'ADMIN';

begin 
  apex_util.edit_user(p_user_id => '11workspace_id000', 
  p_user_name => 'ADMIN', 
  p_web_password => 'Welcome1', 
  p_new_password => 'Welcome1');
end;
/

commit;
/

The above mentioned step resolved the issue!

Write your comments/Suggestions on this issue.

Tuesday, January 5, 2021

Installation of Oracle Fusion Middleware 12c GoldenGate Monitor & Veridata

The objective of this blog post is the Installation of Oracle Goldengate Monitoring Agent in a silent mode. Here in this experiment, we will see the silent mode installation of Oracle Fusion Middleware 12c GoldenGate Monitor & Veridata 12.2.1.2.0

Pre-requisite

  • Operating System: oracle-6,oracle-7,redhat-7,redhat-6,SuSE-11,SuSE-12 for this experiment used Oracle Linux 7.8
  • CPU speed is above 300 MHz
  • Memory ; 8GB (min)
  • Diskspace: as per your Data needs to pumped
  • Temp space: must be greater than 300 MB.
  • Swap space: must be greater than 512 MB
  • The platform requires a 64-bit JVM
  • Java version: 1.8.0_101
  • Database: Any database fine- for this choose Oracle Database 12c

Environment Setup



Create Response File


#DO NOT CHANGE THIS.
Response File Version=1.0.0.0.0
[GENERIC]
#The oracle home location. This can be an existing Oracle Home or a new Oracle Home
ORACLE_HOME=/u01/GG_MONITOR12212
INSTALL_TYPE=GoldenGate Monitor Agent Installation
There could be a few important fields that need to add the values are:

Silent mode installation of GG  Monitor

  $JAVA_HOME/bin/java  -jar fmw_12.2.1.2.0_ogg.jar \
 -silent -responseFile /tmp/oggagent_install.rsp \
 -invPtrLoc /u01/inventory/oraInst.loc 
  
  

Oracle Goldengate Monitor Agent


References:

Pleasel write your valuable feedback

Installation of Golden Gate 19.x on Oracle Linux

 The objective of this is post is for the installation of Oracle Golden gate 19.x on Oracle Linux.


Pre-requisites

  • Operating System: Oracle Linux 7.x
  • Memory ; 8GB (min)
  • Diskspace: as per your Data needs to pumped
  • Temp space: must be greater than 120 MB.
  • Swap space: must be greater than 150 MB.
  • Database: Any database fine- for this choose Oracle Database 12c

Environment setup

Before running the installer we need to setup the Database Home you can run the 'oraenv' or else export the ORACLE_HOME, ORACLE_SID, and LD_LIBRARY_PATH


Create Response File

There could be a few important fields that need to add the values are:   

  1. INSTALL_OPTION=ORA12c or ORA19c  Specify ORA19c for installing Oracle GoldenGate for Oracle Database 19.x  ORA12c for installing Oracle GoldenGate for Oracle Database 12c and ORA11g for installing Oracle GoldenGate for Oracle Database 11g
  2. SOFTWARE_LOCATION=/u01/OGG_19C you can give as per your needs
  3. START_MANAGER=TRUE if you want to start the GG mgr process
  4. MANAGER_PORT=7878 enter port value which is available on your system
  5. DATABASE_LOCATION=/u01/product/12.2/db_home enter as per your DB installed path
  6. UNIX_GROUP_NAME=dba
The remaining fields you leave empty but should present in the response file.

Sample responsefile for installing Oracle GoldenGate for Oracle Database 12c : goldengate19.rsp
oracle.install.responseFileVersion=/oracle/install/rspfmt_ogginstall_response_schema_v12_1_2
INSTALL_OPTION=ORA12c
SOFTWARE_LOCATION=/u01/OGG19C
START_MANAGER=TRUE
MANAGER_PORT=7878
DATABASE_LOCATION=/u01/product/12.2/db_home
INVENTORY_LOCATION=
UNIX_GROUP_NAME=dba

Execution of Goldengate 19.x installer

To install the Goldengate 19.x in a silent mode we have oraInst.loc and response file and then the installer file.
/tmp/fbo_ggs_Linux_x64_shiphome/Disk1/runInstaller -silent  \
-invPtrLoc /u01/inventory/oraInst.loc \
-responseFile /tmp/goldengate.rsp -waitforcompletion -showProgress

Now let's run the above in action ...

Oracle Goldengate 19 install in silent mode
Oracle Goldengate 19.1 installation in silent mode

Once the installation completes MANAGER process will be started automatically and you can see that with GG prompt 'info all' ...

Goldengate Info All

after this next task would be Oracle GoldenGate Monitor Agent installation.