grant select on schema.table to &user;
revoke select on schema.table from &user;
delete schema.table where column='&column_name';
truncate table schema.table;
update schema.table set &column_name=&value where &column_name=&value;
grant select on schema.table to &user;
revoke select on schema.table from &user;
delete schema.table where column='&column_name';
truncate table schema.table;
update schema.table set &column_name=&value where &column_name=&value;
select * from v$pdbs;
alter pluggable database all open;
alter pluggable database pdb_name save state;
alter pluggable database all save state ;
Hint:- first shutdown database and listener
1. copy patch zip and latest opatch utility to desired directory
2. unzip patch zip file
3. cp opatch_zip file to $ORACLE_HOME/
4. cd $ORACLE_HOME/
5. mv OPatch OPatch_old
6. unzip opatch_zip
7. you will see new OPatch directory in $ORACLE_HOME/
8. cd OPatch/
9. run ./opatch version
10. cd to patch_zip directory
11. cd 32435354/
12. 32435354~]$ $ORACLE_HOME/OPatch/opatch apply
13. if unwanted happens then rollback changes using below
32435354~]$ $ORACLE_HOME/OPatch/opatch rollback -id 32435354
14. In the Final step run datapatch utility after starting database and listener
$ORACLE_HOME/OPatch/datapatch -verbose
if possible open all pdbs (pluggable databases)
select * from v$pdbs;
alter pluggable database all open;
alter pluggable database pdb_name save state;
alter pluggable database all save state ;
GRID PATCHING :-
cd patch_directory then execute below:-
make sure you've exported all oracle environment variables ORACLE_HOME,ORACLE_SID,PATH,
LD_LIBRARY_PATH,etc.
$ORACLE_HOME/OPatch/opatchauto apply -oh $ORACLE_HOME
$ORACLE_HOME/OPatch/opatchauto apply /path/to/patch_directory -oh $ORACLE_HOME
Unlock tables stats
BEGIN
DBMS_STATS.UNLOCK_TABLE_STATS(ownname => 'schema_name', tabname => 'table_name');
END;
/
Unlock Index Stats
BEGIN
DBMS_STATS.UNLOCK_INDEX_STATS(ownname => 'schema_name', indname => 'index_name');
END;
/
Unlock Partition Stats
BEGIN
DBMS_STATS.UNLOCK_PARTITION_STATS(ownname => 'schema_name', tabname => 'table_name', partname => 'partition_name');
END;
/
Unlock Materialized View Stats
BEGIN
DBMS_STATS.UNLOCK_MVIEW_STATS(ownname => 'schema_name', mvname => 'materialized_view_name');
END;
/
Unlock Schema Stats
BEGIN
DBMS_STATS.UNLOCK_SCHEMA_STATS(ownname => 'schema_name');
END;
/
Best Practice Examples For EXPDP and IMPDP Jobs:-
By default everything in database is exported and imported you can choose for your needs parameters.
select * from all_directories where directory_name='&directory';
-----------------------------------------------------------------------------
How to use export import utility from linux terminal :-
$ expdp user_who_started_job/password attach=job_name
How to export / import using "sysdba"
$ expdp \"/ as sysdba\"
$ impdp \"/ as sysdba\"
$ impdp user_who_started_job/password attach=job_name
export > status
import > status
export > exit
import > exit
import / export > help
Note:-
Default behaviour of impdp:-
1. by default imports all objects
2. impdp customize using 'include' and 'exclude' if you don't specify include/exclude then
impdp will imports all objects from the dmp files.
** all objects :- tables, indexes, views, triggers, procedures, functions, packages, constraints, types, etc.**
3.'impdp also imports others related data, such as constraints, grants and synonyms.
4. target db already contains objects with the same name as the imported objects, default behaviour is
to overwrite the existing objects with the imported objects. you can change behaviour using remap_table,
remap_schema, remap_
when to use remap_* :-
schema consolidation, renaming objects, data migration, filtering data
remap_data
remap_datafile
remap_schema
remap_table
remap_tablespace
On SOURCE DB:-
sudo -iu oracle
$ nohup expdp user/pwd directory=DATAPUMP dumpfile=file.dmp schemas=schema_name exclude=statistics logfile=file_expdp.log &
or
$ nohup expdp parfile=filename.par &
ON TARGET DB:-
sudo -iu oracle
$ nohup impdp user/pwd directory=DATAPUMP dumpfile=file.dmp logfile=file_impdp.log &
or
$ nohup impdp parfile=filename.par &
schema_objects:-
**** If you want to empty schema then drop below objects for that schemas *********
tables, views, indexes, constraints, procedures, functions, packages, triggers and synonyms
Hints: --->
In toad, go to "schema browser"
In SQLDEVELOPER, go to left pane, (+) button on each connection then search for object and drop
---------------------------------------------------------------------------------------------- ********************************* SCHEMA EXPORT ********************************* [user@hostname]$ cat schema_export_prod_<date-time>.par DIRECTORY=DATA_PUMP SCHEMAS=<schema_name> DUMPFILE=exp_prod_01132023_%U.dmp LOGFILE=exp_prod_schema_01132023.log PARALLEL=6 FILESIZE=10G EXCLUDE=STATISTICS COMPRESSION=ALL CLUSTER=N STATUS=30 JOB_NAME=exp_prod_schema_01132023 ************************************ TABLE EXPORT ********************************** [user@hostname]$ cat schema_prod_expdp_table_tablename.par DIRECTORY=DATA_PUMP SCHEMAS=<schema_name> DUMPFILE=exp_prod_<schema_name>_<table_name>_%U.dmp LOGFILE=exp_prod_<schema_name>_<table_name>.log PARALLEL=12 FILESIZE=15G COMPRESSION=ALL CLUSTER=N STATUS=30 #JOB_NAME=exp_prod_<schema_name>_<table_name>_01132023 INCLUDE=TABLE:"IN('<table_name>')" ************************************ SCHEMA import ********************************** [user@hostname]$ cat imp_<schema_name>.par DIRECTORY=DATA_PUMP_DIR DUMPFILE=exp_prod_<schema_name>_01282023_%U.dmp LOGFILE=IMP_<schema_name>_<table_name>_02022023.log TABLE_EXISTS_ACTION=REPLACE #JOB_NAME=<schema_name>_<table_name> EXCLUDE=VIEW,PROCEDURE,PACKAGE,FUNCTION,TRIGGER #schemas=<schema_name> EXCLUDE=SCHEMA:"IN('<schema1_name>','<schema2_name>')" Note:- Practice on home lab environment and observer take notes for different scenarios. PARALLEL=32 CLUSTER=N FULL=Y ************************************ SCHEMA import ********************************** [user@hostname]$ cat <schema_name>_<host_name>.par DIRECTORY=DATA_PUMP_DIR DUMPFILE=<schema_name>_<table_name>_%U.dmp LOGFILE=IMP_<schema_name>_<table_name>_10022018.log EXCLUDE=SCHEMA:"IN('<schema_name>','<schema_name>')" SCHEMAS=<schema_name> ##SCHEMAS=<schema_name> parallel=25 TABLE_EXISTS_ACTION=REPLACE CLUSTER=N ************************************ SCHEMA import ********************************** [user@hostname]$ cat <schema_name>.par DIRECTORY=DATA_PUMP_DIR DUMPFILE=<schema_name>_<table_name>_%U.dmp LOGFILE=IMP_<schema_name>_<table_name>.log EXCLUDE=SCHEMA:"IN('<schema_name>','<schema_name>')" SCHEMAS=<schema_name> ##SCHEMAS=<schema_name> parallel=25 TABLE_EXISTS_ACTION=REPLACE CLUSTER=N *********************** FULL DATABASE EXPORT ******************************** [user@hostname]$ cat <database>_FULL_EXP.par DIRECTORY=DATA_PUMP_DIR DUMPFILE=Full_database_%U.dmp LOGFILE=Full_<schema_name>_<table_name>.log ##JOB_NAME=03282016_IMP_EXPORT_ST1_NEW FILESIZE=10G CLUSTER=N PARALLEL=4 full=y EXCLUDE=SCHEMA:"IN('<schema_name>',...,'<schema_name>)" ********************************** FULL DATABASE EXPORT ******************] [user@hostname]$ cat <database>_FULL_EXP.par DIRECTORY=DATA_PUMP_DIR DUMPFILE=Full_DATABASE_exp_%U.dmp LOGFILE=Full_database_exp.log ##JOB_NAME=<full_database_exp> FILESIZE=10G CLUSTER=N PARALLEL=4 full=y EXCLUDE=SCHEMA:"IN('<schema_name>',...,'<schema_name>')" *********************************** table index create script ************************** [user@hostname]$ cat DATABASE_TABLE_INDEX_CREATE_SCRIPT.par DIRECTORY=DATA_PUMP_DIR DUMPFILE=NAME_%U.dmp LOGFILE=database_INDEX.log JOB_NAME=database_INDEX CLUSTER=N PARALLEL=24 INCLUDE=INDEX sqlfile=DATABASE_INDEXES_CREATE.sql *****************************************Schema exports ******************************** [user@hostname]$ cat <schema_name>_export_prod.par DIRECTORY=DATA_PUMP_DIR SCHEMAS=<schema_name> DUMPFILE=exp_prod_<schema_name>_%U.dmp LOGFILE=exp_prod_<schema_name>.log PARALLEL=12 FILESIZE=15G EXCLUDE=STATISTICS COMPRESSION=ALL CLUSTER=N STATUS=30 EXCLUDE=TABLE:"IN ('<table_name>',...,'<table_name>')" JOB_NAME=exp_prod_<schema_name>_<table_name> **************************************************************************************To Add Column
Indexes
create index &index_name on &table_name (&column_name);
ALTER INDEX ¤t_index_name RENAME TO &new_index_name;
CREATE INDEX &functional_index_name ON &table_name (LOWER(&column_name));
alter index &index_name unusable;
alter index &index_name rebuild;
alter index &index_name rebuild online;
drop index &index_name ;
views for indexes:
dba_indexes, user_indexes, all_indexes
select * from dba_segments where sement_name='&table_name';
Constraints
create, add, drop, enable and disable table constraints
create table &table_name (&column_name &datatype, &column_name &datatype, constraint &con_name unique (&column_name));
example:
ADD CONSTRAINTS TO TABLE
DROP CONSTRAINTS FROM TABLE
DISABLE CONSTRAINTS ON A TABLE
ENABLE CONSTRAINTS ON A TABLE
TO GET DETAILS/STATUS OF A CONSTRAINT :
if you've logged as desired user then :
Statistics Types:-
1) System statistics :-
exec dbms_stats.gather_system_stats('Start');
2) Optimizer statistics
Below are the Optimizer Statistics ( tables, indexes and Schema):-
-- Connect to your Oracle database using a SQL client or SQL*Plus
-- Execute the following command to gather statistics for a specific table
sqlplus / as sysdba ---------------------> from the host server
sqlplus user/passwd@service_or_sid ---------------------> from remote server
sqlplus user/passwd@host:1521/service_or_sid ---------------------> remote server
to check database status:-
sudo -iu oracle----> tnsping servicename ----> thats it as per tnsnames.ora entries
to check server status :-
ping server as per /etc/hosts entries
from shell script
export OH
export OS
export PATH
export LD_LIBRARY_PATH
sqlplus \/nolog <<< !! > output.txt
conn $constring;
$query;
exit;
!!
cat /etc/oratab | grep -e "^[\a-Az-Z0-9\]\{0,8\}\:*/[[:graph:]]*" | awk -F: '{print $1,$2}' | read a b
$ echo $a
target
$ echo $b
/usr/local/opt/oracle/app/oracle/product/11.2.0.4
export ORACLE_HOME=$b
export ORACLE_SID=$a
export PATH=$ORACLE_HOME/bin:$PATH
Step 1: Install OpenSSH Server You can do this via PowerShell (run as Administrator ): Check if it's already available: Get-WindowsCapab...