Some Important Oracle database Memory management queries.
SGA usage by Oracle Instance:
SGA Stat:
Total SGA:
Using V$PROCESS to see individual process memory usage
Using V$PGASTAT for overall PGA statistics
Tips and recommendations on various Oracle products. Solving day to day challenges with easy operational tasks. Providing ideas on scripting, queries and oracle Patching. Find tricks for numerous ORA-error.
Some Important Oracle database Memory management queries.
SGA usage by Oracle Instance:
SGA Stat:
Total SGA:
Using V$PROCESS to see individual process memory usage
Using V$PGASTAT for overall PGA statistics
In few cases we need to monitor the progress of an export or import job in oracle. below are the steps can be followed to get the details.
get the session details:
SQL> select * from dba_datapump_jobs where state='EXECUTING';
attach the session:
from Command line:
expdp system/********** attach=SYS_EXPORT_FULL_01
Export > status
Reference:
How To Monitor The Progress Of Datapump Jobs (Doc ID 1471766.1)
Best Wishes!!
In many times, we need to know what are the script is being called while setting up the environment variables, this is very handy when we are getting errors like some env variables are not setup.
If zsh is the login shell:
zsh -xl
Execute the below command to get from which file the environment is setup:
PS4='+$BASH_SOURCE> ' BASH_XTRACEFD=7 bash -xl 7>&2
Best Wishes!!
While Dropping a user if the drop user command is throwing error like:
ORA-01940: cannot drop a user that is currently connected
Follow the below steps:
select 'alter system kill session '''||sid||','||serial#||''' immediate;' "SQL Statement" from v$session where username=UPPER('&username');
SQL Statement
--------------------------------------------------------
alter system kill session '101,265842' immediate;
Execute the alter statement to kill the active session.
alter system kill session '101,265842' immediate;
System altered.
Now the drop user will work:
drop user <username> cascade;
Note: cascade option drops all the dependent objects under the schema.
DBMS_STATS.GATHER_TABLE_STATS is used to gather stats for a single table
EXEC DBMS_STATS.gather_table_stats('HR','EMPLOYEES');EXEC DBMS_STATS.gather_table_stats('HR','EMPLOYEES',cascade=>TRUE);
( Note: Cascade gathers Index stats associated with the table )
Oracle DB links are used to connect to different sources through procedures/views. It helps creating views or materialized views by pulling data from different db sources.
To check the db links present in the database, the below query can be used.
select * from dba_db_links;
SQL> desc dba_db_links;
Name Null? Type
----------------------------------------- -------- ----------------------------
OWNER NOT NULL VARCHAR2(128)
DB_LINK NOT NULL VARCHAR2(128)
USERNAME VARCHAR2(128)
HOST VARCHAR2(2000)
CREATED NOT NULL DATE
HIDDEN VARCHAR2(3)
SHARD_INTERNAL VARCHAR2(3)
VALID VARCHAR2(3)
INTRA_CDB VARCHAR2(3)
Create or replace database link "<DB link name>" connect as "<remote username>" identified by "<Remote user password>" using "<Remote DB TNS details>";
SELECT f.request_id,pt.user_concurrent_program_nameuser_conc_program_name,f.actual_start_datestart_on,f.actual_completion_dateend_on,p.concurrent_program_nameconcurrent_program_name,DECODE (f.phase_code,'R', 'RUNNING','C', 'COMPLETED',f.phase_code)phase,DECODE (f.status_code, 'C', 'NORMAL', 'E', 'ERROR', f.status_code)Status,f.requested_by,fu.user_id,fu.user_nameFROM apps.fnd_concurrent_programs p,apps.fnd_concurrent_programs_tl pt,apps.fnd_concurrent_requests f,apps.fnd_user fuWHERE f.concurrent_program_id = p.concurrent_program_idAND f.program_application_id = p.application_idAND f.concurrent_program_id = pt.concurrent_program_idAND f.program_application_id = pt.application_idAND pt.language = USERENV ('lang')AND f.actual_start_date IS NOT NULLAND f.actual_start_date >TO_DATE ('15-DEC-2021 00:00:00', 'DD-MON-YYYY HH24:MI:SS')AND f.actual_completion_date <TO_DATE ('17-DEC-2021 23:59:59', 'DD-MON-YYYY HH24:MI:SS')AND f.requested_by = fu.user_idAND pt.USER_CONCURRENT_PROGRAM_NAME = '&User_concurrent_program_name'--AND fu.user_name = '&user_name'ORDER BY f.actual_start_date ASC;
set lin 200;col file_name for a75;col autoextensible for a15;select file_name,tablespace_name,sum(bytes)/1024/1024 as FILE_SIZE,sum(maxbytes)/1024/1024 as MAX_SIZE,autoextensible from dba_temp_fileswhere tablespace_name ='TEMP' group by file_name,tablespace_name,autoextensible order by file_name;
set lin 200;col file_name for a75;col autoextensible for a15;select file_name,tablespace_name,sum(bytes)/1024/1024 "FILE_SIZE(MB)",sum(maxbytes)/1024/1024 as MAX_SIZE,autoextensible from dba_data_fileswhere tablespace_name ='&tablespace_name' group by file_name,tablespace_name,autoextensible order by file_name;
This is the simplest task for a Database Administrator.
Login to sqlplus session from your OS(Windows/Linux/AIX) using sysdba / a user who has create user privilege.
sqlplus / as sysdba
alter user <username> identified by <password>;
this will create a user with default tablespace and profile. Depending on the organization's policy and user's requirement you might need to mention few other options in the query. Those are advanced options you can explore more on my advance create user query.
Now user needs some privileges to connect to the database and do some transactions or query any tables.
CONNECT - this is the Oracle-defined default privilege for any user to be able to connect to the database.
grant connect to <username>;
alternatively, grant create session to <username>; will do the same.
Now, for the user to be able to query any table in the db, one basic privilege is required.
grant select any table to <username>;
This will create a db user in Oracle.
To see the user is created properly you can validate with below query.
select * from dba_users where username='<username>';
The dba_users is a data dictionary view which eventually being created from all_users. To know more about all_users and dba_users column properties stay tuned!!
Best Wishes!!
Some Important Oracle database Memory management queries. SGA usage by Oracle Instance: select round(sum(bytes)/1024/1024,2)||' MB'...