Oracle expdp and impdp command? - oracle

I want to know the Oracle expdp and impdp command for sys user and scott/tiger user for entire database or a particular table.I will be grateful if you share me the script of expdp and impdp.I also want the script of recovery of a entire database and performance tuning.

There is no such "the" script, as in one single script that does whatever you seem to wan. If you want to know how to use expdp and impdp, then check the documentation - the Utilities manual.
And to address one point, using expdp/impdp as SYS, the manual specifically warns against it, with this quote:
Note:
Do not start Export as SYSDBA, except at the request of Oracle
technical support. SYSDBA is used internally and has specialized
functions; its behavior is not the same as for general users.
And there is no single script for " recovery of a entire database". Recovery of an entire database should actually be done with rman, using backups made by rman, not expdp.
And there is certainly no script for "performance tuning." You are looking for simplistic answers to complex issues. Whole books have been written on performance tuning. Performance tuning depends on identifying the cause of poor performance, and that can come from countless unrelated sources.

Before exporting/importing a dump of the database make sure that you have created a directory and give the permissions to read & write on this for the user that will be used to export/import.
Some basic examples for expdp & impdp:
full database export: expdp scott/tiger#orcl directory=mydir dumpfile=expdp_full_db.dmp logfile=expdp_full_db.log full=YES;
table export: expdp scott/tiger directory=mydir dumpfile=table_exp.dmp logfile=table_exp.log table=test
table import: impdp scott/tiger directory=mydir dumpfile=table_exp.dmp logfile=table_exp.log tables=test
These are just some examples. Expdp and impdp provide a lot more useful options and parameters. More details here (https://oracle-base.com/articles/10g/oracle-data-pump-10g )
But keep in mind that EdStevens is right because there is not a 'script' that can be used to solve any problem, especially performance issues.

Related

How to generate DDL for all Users and privileges in Oracle

I'm trying to migrate a database instance from RDS Oracle to On-premise Oracle. I'm still pretty new to database scripting. I found this script that does the work for me for a single user that I pass via SQLDeveloper. However I have 200+ users on my RDS Oracle instance.
https://oracle-base.com/dba/script?category=script_creation&file=user_ddl.sql
I have tried removing the variable here for the user name and the rownum but this generates a lot of duplicate entries. Can someone guide me what is the best way to achieve the result set of the above script for all users.
Much appreciated!
I'd suggest another approach (if you can use it): data pump.
You'd perform export
using user SYSTEM or SYS as they own the database and can export ...
... FULL database
content would be METADATA_ONLY (so that you'd skip data; I understood you don't need that)
That would be something like
expdp system/pwd file=your_db.dmp full=y content=metadata_only
Import goes the same way, in the target database.

Oracle Clone/Copy complete Schema with all dependencies and tablespaces

Problem to solve, let's say that:
We have a new clean install of Oracle 11G R2.
We want to copy/clone a Schema from another one with all needed Tablespaces and dependencies.
We want to minimize all manual recreation of tablespaces and so on, also some Packages may or may not have dependencies out of that schema - so we need to check for that too.
What would be the best way to do that. Software options are welcomed too, please describe the procedure if you know with what application and how to be done.
Example: Oracle Sql Developer, such and such steps, at least in brief.
if you know how to make it work with 'EXPDP ... include=tablespace' can you please write the full command for exporting a selected Schema including the Tablespaces and all 'packages/function/trigers...etc' and how to IMPDP that after that.
Thank you very much community.
Remap_schema (+ remap_tablespace if you want it) is what you are looking for:
expdp schema1/pwd DIRECTORY=dump_dir DUMPFILE=schema1.dmp \
LOGFILE=schema1_exp.log SCHEMAS=schema1
impdp schema2/pwd2 DIRECTORY=dump_dir DUMPFILE=schema1.dmp \
LOGFILE=schema1_imp.log REMAP_SCHEMA=schema1:schema2 \
REMAP_TABLESPACE=(schema1_tab1:schema2_tab1,schema1_tab2:schema2_tab2)

How to Take month wise dump in oracle 10G?

I have database. I need to take back up of table month wise. so how to take backup in month wise in oracle 10G?
You don't mean "backup". Backup implies recovery, and a monthly dump is no good for recovery purposes. That's why Nature gave us RMAN.
The Oracle export and import tool is called Data Pump. We can run this as an external command or with a PL/SQL API. Find out more.
Running a monthly export requires a scheduling tool. Use an OS command such as cron to run a shell script invoking the command line expdp or the built-in DBMS_SCHEDULER to run a stored proc using DBMS_DATAPUMP.

Oracle: Recover backup in other different than original server

I'm really newbie about Oracle backup operations. I'm really new in this world and I need to know how to backup a DB schema and restore it in another machine under another schema name.
I cannot afford any mistake since I'll be doing this in our customer site, an making a small mistake could be the last one
I don't want to sound offensive, but doing this in MySQL is really easy, like this:
in server one:
$mysqldump --user=user --password=password db_to_backup > bc_name.sql
-after transfering the sql script to another server
in server two:
mysql>create database db_to_restore;
$mysql --user=user --password=password db_to_restore < bc_name.sql
I need to do the same using Oracle, I read some documentation but I'm still unsure how to do it:
First: What's the equivalent of MySQL database in Oracle? tablespace?
Second: I think these are the steps to get a backup
mkdir /opt/oracle/dumptmp/
CREATE OR REPLACE DIRECTORY dumptmp AS '/opt/oracle/dumptmp/';
expdp user/pass#tablespace directory=dumptmp dumpfile=dumptmp:full.dmp logfile=dumptmp:full.log full=y
Third: Then I move the file "full.dmp" to the other server, but I'm not sure how to restore my backup file full.dmp into a new tablespace with a different name to the one it the backup was gotten from:
SQLPLUS>create tablespace ts_something;
then I'm not sure how to proceed from here. Please advice me how to do it using command line commands since my customer does not have GUI tools intalled.
Thanks a lot!
First of all, make sure you test this procedure in test or development environments before proceeding to perform it on production. Disclaimer: I'm not responsible if you bust any of your databases by misusing the following advice. Note that I'm also ignoring how tablespace storage is set up for your schemas, which you should definitely hold in consideration when creating new schemas.
Here is the simplest possible method using command line. You will need to use exp and imp utilities which come with complete Oracle database distributions. Assuming that you have the path to Oracle executables set correctly in your environment path, you will need to do:
Export your source schema on the source database server:
[oracle#src_server ~]$ exp source_schema_username#SRC_SID owner=source_schema_username file=source_schema.dmp
Import your source schema into destination schema on the destination database server (assuming you have already created the destination schema, if not, see CREATE USER, also make sure that destination schema user has RESOURCE role):
[oracle#dst_server ~]$ imp system#DST_SID fromuser=source_schema_username touser=destination_schema_username file=source_schema.dmp
Note that you must run imp as a user that has DBA role. I'm using system here because this user typically exists on all Oracle databases and has DBA role. You will of course need to know the password for system user. You may not need to specify SIDs if ORACLE_SID is already set in your environment on both servers (echo $ORACLE_SID), however I wanted to be explicit here to make sure that you do not import into the wrong database.
For more information on usage of export and import utilities run exp help=y and imp help=y.
To answer your questions about Oracle:
First: What's the equivalent of MySQL database in Oracle? tablespace?
Oracle equivalent is database name (db_name parameter). It identifies a database on Oracle database server(s). On a single instance database, this is also typically Oracle SID. On Oracle RAC, a single database will have many SIDs.
Third: Then I move the file "full.dmp" to the other server, but I'm not sure how to restore my backup file full.dmp into a new tablespace with a different name to the one it the backup was gotten from:
You want to create a new user, which is identical to a schema in Oracle. Tablespaces are abstracted collections of disk locations where Oracle stores tables and indicies. For example, when you create a table, it has to be assigned to some tablespace.
What you're explaining is not really a backup, more like schema export & import.
but doing this in MySQL is really easy.
So is doing the same in Oracle.
exp user/password#hoststring file=bc_name.dmp log=bc_name.log full=y statistics=none
& to import it,
imp new_user/new_password#hoststring file=bc_name.dmp log=bc_name.log full=y
If new_user doesn't exist then create the users
create user new_user identified by new_password
and grant the rights
grant create session,connect,imp_full_database to new_user

clone oracle database without data

I want to clone my existing oracle database structure without data including packages, users, tablespaces etc. I read some methods but they all copied data as well. Is there anyway out in order to do this?
Thanks in advance.
Use SQL Developer > Tools > Database Export..
On "Specify Data" do not include any tables.
Omit packages etc here,
Fine tune your selection here,
My trial export has not finished yet but I expect this will work.
Use Oracle exp.exe utility for export. E.g.
EXP.EXE login/password#TNSNAME file=entire_db.dmp owner=(scott, my_user, user2) rows=n grants=y triggers=y
Only rows=n option in command above make sense for your task.
You can import to target database with imp.exe utility.
Look for detailed option list and definition by running this utilities with help=y option.
BUT tablespaces and users on target databases must be created manually before running import.
There are no standard tablespace cloning tools (including SQL Developer), but some queries exists for generating such cloning scripts.
Examples can be found here and here.
P.S. This question better fits to ServerFault than to StackOverflow ...
You can do it in toad but its not free tool. (Database Tab->Export->Export DDL)
Try Oracle Export command with ROWS=N
exp SCOTT/TIGER ROWS=N TRIGGERS=N
Use SQL Developer, Tools > Database Export.
You will need to specify at least one table in the 'data' option because you cannot choose to NOT export any data. Pick a table that has a small number of rows or create a dummy table without any rows beforehand as a workaround.

Resources