Data migration from Oracle 10g to Postgres db - oracle

I want to migrate the data from Oracle 10g database to Postgres db.
Oracle SQL developer has data migration option but it seems its only for migrating non oracle db to oracle.
Please let me know other options.

There's a dedicated tool for that written in Perl: Ora2Pg.
Most databases provide tools for importing from other databases but not exporting to other databases.

I have tried using ORA2PG before but it was too complicated so I found my own way to migrate from sql developer to postgres.
Here's a step by step, let me know if you have any questions.
HOW TO MIGRATE DATA FROM THE ORACLE DATABASE TO THE POSTGRES DATABASE!
Tools to download before migration: SQL Developer, WINSCP
SQL Developer
Step 1: Login into the Oracle server using SQL Developer
Step 2: Right click on the schema name > Export > Change for the format to CSV and the encoding to UTF-8. (Make sure Export DDL is unchecked) (Make sure the filename is finished with .csv )
Step 3: Click next > next > Finish (Wait till the exporting is done)
ONCE THE FILE FROM SQL DEVELOPER IS EXPORTED
Right click on the csv file, click on open with and open it with Notepad.
Click File > Save as > Change encoding to UTF-8 and save it.
Open WINSCP
STEP 1: Before logging in into your server, click on edit > Advanced > Turn ON ‘UTF-8 encoding for filenames’.
STEP 2: Login into your server
STEP 3: Click on Settings > Internal Editors > Change the Default encoding to UTF-8 > Click Ok
STEP 4: Create a new directory anywhere on your server and drag your file to that directory into WINSCP
Now the file should be on your server with the UTF-8 encoding.
Open putty
Before logging in into your server with Putty, click on Translation and change the Received data assumed to be in which character set to UTF-8 then click on DATA and change the Terminal-type string to Putty then login into your server.
Once you logged in into your server with Putty, Run the command:
Locale charmap
This command will show you the default encoding of the server.
Run that command after:
grep -Rw '/home/pgadmin/data1/1234.csv' -e 'fre'
data1 = Directory created on the server
1234.csv = Csv file inside the data1 Directory
This command will show you if the French word in your document are still lost or not.
The '/home/pgadmin/data1/1234.csv' in that command is where your file is located on your server and ‘1234.csv’ is the name of the CSV file.
If everything is good after running that command, now we’re able to put it on the Postgres database.
After entering the postgres database with the command “psql”
Step 1: Make sure you have created your own database, schema and table (if you don’t know how, Scroll down to the end of the document).
Step 2: After creating your own database, schema and table, we can run the copy command.
\Copy joe.data01 FROM ‘home/pgadmin/data1/1234.csv’ DELIMITER ‘,’ CSV HEADER encoding ‘UTF-8’ ;
If the file already has column names on the csv file, add “HEADER” in the command.
joe.data01= Name of table created
home/pgadmin/data1/1234.csv = Location of the file on the server
To view if the schema was copied, simply run the command select * from joe.data01;
To view if French words are not lost, run the command select * from joe.data01 where isa = ‘fre’ ;
How to create a Database on Postgres: CREATE DATABASE name_of_database ;
How to create a Schema on Postgres: CREATE SCHEMA name_of_schema;
How to create a Table on Postgres: create table joe.data01 (ccca CHAR(50) NOT NULL, isa CHAR(70) NOT NULL, co CHAR(150) NOT NULL) ;

We ended up migrating a fairly large database (~100 schema, with >1000 tables) from Oracle to Postgres using the approach outlined at: https://github.com/MIT-LCP/oracle-to-postgres.
You can install the package with pip install oracle2postgres. More information is at: https://pypi.org/project/oracle2postgres/
A Jupyter Notebook demonstrating the approach is at: https://github.com/MIT-LCP/oracle2postgres/blob/master/migration.ipynb.
Our general approach was to mirror the source database; convert data types where necessary; create the target database; copy across the data in chunks. It's a slightly hacky solution, but it worked well for us.
# import the package
import oracle2postgres
# create the logfile
oracle2postgres.create_logfile()
# get source database settings
source_config = oracle2postgres.get_source_config()
# get target database settings
target_config = oracle2postgres.get_target_config()
# get settings for migration
migration_config = oracle2postgres.get_migration_config()
# check the schema exist on the source database
source_engine = oracle2postgres.connect_to_source(source_config)
oracle2postgres.check_schema_exist(source_engine,source_config['schema_list'])
# check for null characters in strings in the source database
# if found, they can be removed as explained in the documentation
oracle2postgres.check_for_nulls(source_engine,source_config['schema_list'])
# create a new database on the target database
target_engine = oracle2postgres.connect_to_target(target_config)
oracle2postgres.create_database(target_config['database'],target_engine)
# create schema on the target database
target_engine = oracle2postgres.connect_to_target(target_config,target_config['database'])
oracle2postgres.create_target_schema(source_config['schema_list'],source_engine,target_engine)
# run the migration
oracle2postgres.migrate(source_config,target_config,migration_config)
If you hit problems when reusing the code, feel free to raise an issue if so and we'll do our best to help.

expand the tables section,
then select tables you want to export
right click, select export,
then select format and export (preferably insert statements or csv)

Related

Open dbf file from oracle database

My instructor gave me a username and password and .dbf file and tell me to open it and try to retrieve with sqlplus and oracle database
I tried to open the dbf file from excel mysql and ms server but it i gave me an error
Speaking as a DBA: As Littlefoot stated, you can't just read a data file from an Oracle DB. At best they are proprietary binary file formats, assuming it isn't encrypted on top of that. Nor can you take a data file from one database instance and just plug it in to another database instance. You also can't import it to mySQL or any other database engine: as a stand-alone data file it can only be properly read by its original database installation (i.e. the specific database instance that created it).
Oracle has specific tools available to copy data and/or files from one database to another, but those would generally use the RMAN backup manager (used to make physical backups) or (more likely in your case) the Datapump "Transportable Tablespace" feature.
To restore it from an RMAN backup you would need a complete full backup of the entire source database instance: RMAN backup sets including all data files, redo logs (and perhaps archived logs), control files, parameter files, encryption keys,, and possibly more.
To restore a transportable tablespace dump you would need your own running Oracle database instance, the correct parameters to run the impdp import utility, and the assistance/cooperation of the DBA.
You need to confirm if the file you were given is such an export dump (though the .dbf file extension would suggest not), and how you are expected to access the data. You won't be able to just "open the file".
.DBF extension probably represents datafile; I don't think you can read it with any tool (at least, I don't know of any).
You should find an Oracle DBA who might try to help; in order to restore a database (which is contained in that file), they might need control file(s), redo log files and ... can't name what other files (I'm not a DBA).
Then, if everything goes OK, database might be started up so that you'd be able to connect to it using credentials you were given.

Oracle Database Backup in DBeaver

I am new to Oracle databases. I have installed DBeaver (never used this before too) to connect to the database.
I have created a connection (which I believe is called database) and now I am able to see the database tables and everything. How do I take the backup of the Oracle Database in DBeaver so I can use it locally for test purposes before making any change on live database?
I can't find any option to take the backup of connection/database.
To do a proper backup of your Oracle Database, you should use the oracle provided utility, Recovery Manager. It's a command line interface that's called from your DB server shell prompt via 'RMAN'
You can also use Data Pump to export all or part of a database that can be used to import to another database...not really used for recovery of an existing database.
I'm not aware of your tool having interfaces for either of these Oracle features.
You might not need a backup at all for your needs, take a look at Oracle Flashback Technology.
DBeaver does not support oracle database export import. See details here:
https://dbeaver.com/docs/wiki/Backup-Restore/
You need to run the sqlplus tool to create a folder where oracle is going to import/export database dumps. Login should happen as sys as sysdba and enter the password you previously entered during database server installation. Example:
sqlplus sys/[your password] as sysdba
After you successfully logged into sqlplus run the following command (don't forget to set to a different folder that you prefer to use):
create or replace directory DATA_PUMP_DIR as 'D:\Database Backups';
Once this is done exit from sqlplus and enter the following command into the command line (again no sqlplus should be used here)
expdp sys/[your password]#localhost:1521/[listener name] file=your-database-dump-file.dmp owner=[your schema]
Once this is done and finished you can zip your database dump if you would like to upload it somewhere else. (I had 9 GB dump and the zipped size was 1.6 GB)

Can I Restore data from ORACLE datafiles folder?

my server had been attacked by a ransomware .rapid and all my data had been encrypted , luckily for me the oracle home folder is not encrypted - yet - and most of the files including the datafiles folder and tablespaces are still accessible
Can any One please tell me how to recover my database objects?
no backup is available , only oracle home folder -most of it-
EDIT :
The System is broken , I am trying to know witch files to collect and copy that will enable me to recover my database files from another system
when I try to log into sqlplus throw cmd I get the following error :
'sqlplus' is not recognized as an internal or external command ,
operable program or batch file.
Blockquote
EDIT :
FILES THAT I STILL HAVE ACCESS TO - NOT ENCRYPTED -
Okay. If you can find an init.ora file on your server, that's the PFILE - initialization parameter file - that's the last thing missing to easily copy your database to a new server. If you can't find it, that's ok - it'll just be a little harder. As long as you have the datafiles, you can eventually get your database back.
Basically, you'll want to follow steps 2-8 in the link I posted. You can also find some helpful info in the Oracle guide to manually creating a database in Windows. I'll walk you through them.
Shutdown your old database (if it's still running). This will make sure your datafiles are in a consistent state for copying. Probably stopping the Windows Service would be the easiest way to do that if you can't access sqlplus.
Copy the data to your new server. I'm assuming it'll be in the same location, D:\app\Administrator\oradata\VTC\
Make a copy of the control file CONTROL01.CTL and name it create_db.sql (EDIT: I was assuming that this was a backup to trace ascii version of the control file, but it sounds like this is the binary file)
Edit create_db.sql. Where it says CREATE CONTROLFILE REUSE DATABASE "MY_DB" NORESETLOGS, change it to CREATE CONTROLFILE SET DATABASE "MY_DB" RESETLOGS. Make note of whatever "MY_DB" is - this is your database name. Most people make it the same as the SID. I normally do RESETLOGS which throws out the old redo logs, but you could try keeping them with NORESETLOGS if that works for you.
Remove or comment out the lines that say RECOVER DATABASE and ALTER DATABASE OPEN;. Make sure the paths for the datafiles and logfiles look correct. Save the file.
If you couldn't find your init.ora to copy, I think this very minimal one will work for you, although you'll want to fix your memory settings later. Create it in the same folder.
DB_NAME=MY_DB
INSTANCE_NAME=MY_DB
SERVICE_NAMES=MY_DB
CONTROL_FILES = ("D:\app\Administrator\oradata\VTC\CONTROL01.CTL")
DB_FILES=100
Create an Oracle Database Windows Service. Afterwards check Services to make sure it's running.
oradim -NEW -SID MY_DB -STARTMODE manual -PFILE "D:\app\Administrator\oradata\VTC\init.ora"
Log in to your new Oracle instance as SYSDBA. There's no database yet.
cd D:\app\Administrator\oradata\VTC\
set ORACLE_SID=MY_DB
sqlplus / as sysdba
Create the database, using the control file from the old server as a script.
#create_db.sql
If everything comes back OK, run:
alter database open

How to create a dump?

I'm one of the junior DBA working in IT company.In my company there are so many schemas is there.Now my question is How to create a dump file(some times i'm working at home.That time how to use that dump file ).Please suggest me
NOTE:I am using Oracle SQL Developer.
Expdp helps in exporting the database and impdp helps in importing the database. you can directly export one schema to another (in different database also) by using network link concept.
If network link concept is used then the creation of separate expdp file is not required.
For example If you have to export a schema called schema1 with password pwd1 from source database to target database then
first you need admin privileges of your target and source schema.
You can create a network link between source and target schema
CREATE PUBLIC DATABASE LINK example_link
CONNECT TO schema1 IDENTIFIED BY pwd1
USING 'server_name:port/service_name';--(put source database server_name,port and service name)
then create a directory in your target server :-
CREATE OR REPLACE DIRECTORY exp_dir AS 'F:/location';
grant read,write on directory exp_dir to schema1;
After this login to your target server and from command line use the below command:
impdp dba_username/dba_pwd network_link=example_link directory=exp_dir remap_tablespace=source_tbs:target_tbs remap_schema=schema1:schema1 parallel=2
You should use the Oracle Data Pump tool. The tool allows you to export your data into a .dmp file and import it into any database. Here is a video showing how to use the data pump tool in SQLDeveloper. I think this is a relatively new feature in SQLDeveloper, so make sure you have the appropriate versions..
Video Tutorial HERE
From the command line, you can use data pump with the expdp and impdp commands like so..
Set your oracle environment by running the below command and providing your oracle SID
. oraenv
Then you can run your export command..
expdp directory=/bu1/dpdump/ dumpfile=myexport.dmp logfile=mylog.log schemas=users,products,sales
The parameters are as follows..
directory - the directory where to create the dumpfile and log
dumpfile - name of the dump file (should end in .dmp)
logfile - name of the log file (should end in .log)
schemas - comma seperated list of the schemas you want to export
NOTE: you need dba privileges to use datapump. It will prompt you for the credentials
Data Pump Documentation is here
Exporting of ORACLE database objects is controlled by parameters. To get familiar with EXPORT parameters type:
exp help=y
You will get a short description and the default settings will be shown.
The EXPORT utility may be used in three ways:
Interactive dialogue
Controlled through bypassed parameters
Parameterfile controlled
Example to the 2nd option:
exp scott/tiger file=empdept.expdat tables=(EMP,DEPT) log=empdept.log
Take a look at these links for further readings:
Original Export and Import
The ORACLE Import/Export Utilities

How to create a dump with Oracle PL/SQL Developer?

I need to take dump of a user (including tables, procedures ,etc.) as FILENAME.dmp.
If I create a new user and import that FILENAME.dmp, then everything should be created.
How can I create this dump file?
Don't tel me to use the Run > EXP or Run > IMP functions because, due to some problem, that feature is not working for me.
EXP (export) and IMP (import) are the two tools you need. It's is better to try to run these on the command line and on the same machine.
It can be run from remote, you just need to setup you TNSNAMES.ORA correctly and install all the developer tools with the same version as the database. Without knowing the error message you are experiencing then I can't help you to get exp/imp to work.
The command to export a single user:
exp userid=dba/dbapassword OWNER=username DIRECT=Y FILE=filename.dmp
This will create the export dump file.
To import the dump file into a different user schema, first create the newuser in SQLPLUS:
SQL> create user newuser identified by 'password' quota unlimited users;
Then import the data:
imp userid=dba/dbapassword FILE=filename.dmp FROMUSER=username TOUSER=newusername
If there is a lot of data then investigate increasing the BUFFERS or look into expdp/impdp
Most common errors for exp and imp are setup. Check your PATH includes $ORACLE_HOME/bin, check $ORACLE_HOME is set correctly and check $ORACLE_SID is set
Just to keep this up to date:
The current version of SQLDeveloper has an export tool (Tools > Database Export) that will allow you to dump a schema to a file, with filters for object types, object names, table data etc.
It's a fair amount easier to set-up and use than exp and imp if you're used to working in a GUI environment, but not as versatile if you need to use it for scripting anything.
Just as an update this can be done by using Toad 9 also.Goto Database>Export>Data Pump Export wizard.At the desitination directory window if you dont find any directory in the dropdown,then you probably have to create a directory object.
CREATE OR REPLACE DIRECTORY data_pmp_dir_test AS '/u01/app/oracle/oradata/pmp_dir_test';
See this for an example.
There are some easy steps to make Dump file of your Tables,Users and Procedures:
Goto sqlplus or any sql*plus
connect by your username or password
Now type host it looks like SQL>host.
Now type "exp" means export.
It ask u for username and password give the username and password of that user of which you want to make a dump file.
Now press Enter.
Now option blinks for Export file: EXPDAT.DMP>_ (Give a path and file name to where you want to make a dump file e.g e:\FILENAME.dmp) and the press enter
Select the option "Entire Database" or "Tables" or "Users" then press Enter
Again press Enter 2 more times table data and compress extent
Enter the name of table like i want to make dmp file of table student existing so type student and press Enter
Enter to quit now your file at your given path is dump file now import that dmp file to get all the table data.
Export (or datapump if you have 10g/11g) is the way to do it. Why not ask how to fix your problems with that rather than trying to find another way to do it?

Resources