Can I migrate tables without the triggers? - oracle

I'd like to migrate all tables, data, and indexes for a given Oracle schema (approx 2000 tables).
I do want to migrate the triggers. I am looking for a way to do this without visiting each table and deselecting its triggers.

The simple answer would be to migrate everything and build a script using something like;
select 'drop trigger ' || trigger_name || ';' from all_triggers where owner = 'MYSCHEMA';

If your database is 11g or above, you can use the expdp utility with include=triggers qualifier.

Related

truncate tables or replace old data with new data using imp oracle utility

I need import utility to remove old data then reinsert new data. How can I do that without using data pump?
The reason I can't use data pump is because I need to run this script on application server, I don't have the privilege to run this on database server. below is the script I'm currently trying to fix
imp < username >/< password >#//< host > fromuser=< schema > touser=< schema > file=exp_$TODAY.dmp log=exp_import_$TODAY.log ignore=y
IMP can't truncate tables prior to importing, so - you're out of luck here. If you could use the Data Pump Import, you could use the TABLE_EXISTS_ACTION parameter set to TRUNCATE (which would remove existing data) or even REPLACE (which drops table, creates it and loads data). Ask the DBA to provide access to a directory you could use for importing purposes.
Alternatively, as it seems that you're importing everything, consider dropping the target user (with the cascade option) and then import its objects.
Or, if it isn't too complicated, create a script which would truncate tables, for example
SQL> select 'truncate table ' || tname ||';' from tab;
'TRUNCATETABLE'||TNAME||';'
----------------------------------------------
truncate table BONUS;
truncate table DEPT;
truncate table EMP;
truncate table SALGRADE;
truncate table WC;
SQL>
so you'd run those TRUNCATE TABLE statements prior to importing.
Note that - if there are foreign key constraints - they won't let you do it unless you disable them; as above, you could use SQL to create SQL for you:
SQL> select 'alter table ' || table_name || ' disable constraint ' || constraint_name ||';'
2 from user_constraints
3 where constraint_type = 'R';
'ALTERTABLE'||TABLE_NAME||'DISABLECONSTRAINT'||CONSTRAINT_NAME||';'
---------------------------------------------------------------------------------------------
alter table EMP disable constraint FK_DEPTNO;
SQL>

Take backup and then drop all tables with same prefix in Oracle

In one of my Windows form application in asp .net, I am creating tables on daily basis sharp at 00:00 am with name as "data_YYYY_MM_DD" in Oracle database. A large amount of data exist in each table as after every 5 seconds I am writing some useful data into these.
Now consider all tables of month Oct 2016. All will have name like 'data_2016_10%'. How can I take backup of only these tables (not backup of entire database) and then drop these tables from the database.
You can take logical backup of these tables using data pump. It creates dump file(binary file) which can be imported as per your needs.
Export:Table Mode
A table mode export is specified using the TABLES parameter. In table mode, only a specified set of tables, partitions, and their dependent objects are unloaded.
Example:
expdp hr TABLES=hr.employees VERSION=LATEST DIRECTORY=dpump_dir1 DUMPFILE=emp.dmp NOLOGFILE=YES
Reference:
Data Pump Export
Try like below,
you can schedule it in dbms_scheduler jobs,So that every day it will run and create backup table and drop existing table.Also please add exceptions like table does not exist...if you want
create or replace procedure backup_monthly_table
as
prev_date varchar2(20) := to_char(sysdate-1, 'yyyy-mm-dd');
begin
for i in (select table_name from dba_tables where upper(table_name) like '%'||'"'||prev_date||'_%')
loop
dbms_output.put_line('working');
dbms_output.put_line(i.table_name);
execute immediate 'create table sysman.'||'"'||i.table_name||'_bkp'||'"'||' as select * from sysman.'||'"'||i.table_name||'"';
execute immediate 'drop table sysman.'||'"'||i.table_name||'"';
end loop;
end;
verification output:
select owner,table_name from dba_tables where upper (table_name) like '%2017-%'
SYSMAN 2017-02-01_test1_bkp
SYSMAN 2017-02-01_test2_bkp
SYSMAN 2017-02-01_test3_bkp
SYSMAN 2017-02-01_test4_bkp

How to export empty tables in oracle

I have a big problem When i take a dump of database the empty tables are truncated
How i can export the all tables in oracle 10g
exp SYSTEM/password FILE=expdat.dmp
This might be because of these tables may not be extent allocated. Before taking backup you need to identify all the tables that do not have data. Then alter these tables to allocate extent.
ALTER TABLE <table_name> ALLOCATE EXTENT;
Use the below script to alter all tables they do not have extent allocated.
SELECT 'ALTER TABLE '||table_name||' ALLOCATE EXTENT;' FROM user_tables WHERE segment_created = 'NO';
Copy the output and execute it.
You might consider expdp (data pump) instead. There's a parameter CONTENT=METADATA_ONLY that might get you what you want.
I found another solution here.
Oracle has an option called DEFERRED_SEGMENT_CREATION, default true.
from the docs:
If set to true, then segments for tables and their dependent objects (LOBs, indexes) will not be created until the first row is inserted into the table.
I'll sum up the solution from the above link:
SQL> alter system set DEFERRED_SEGMENT_CREATION=FALSE scope=both;
Run the output of the following statement:
SQL> select 'alter table ' || table_name || ' move;' from user_tables where num_rows=0;
This made my exp export empty tables as well.

Oracle export: table doesn't exist

I am trying to export data in oracle 11g
exp user/password file=dump.dmp tables = (table1)
via sqlplus.
And i get the following error:
About to export specified tables via Conventional Path ...
EXP-00011: USER.TABLE1 does not exist Export terminated
successfully with warnings.
But when i check who is the owner of this table:
SELECT owner, table_name from dba_tables where table_name = 'TABLE1';
I get that the owner of TABLE1 is USER
What should i do to export this table?
UPDATE
Actually, i found a solution. I hope it will help someone else.
Since version 11g Oracle has introduced new feature that is called deferred segment creation. Thus oracle doesn't create table segment if there are now rows in it. So i recreated my table with option 'segment creation immediate'
Actually, i found a solution. I hope it will help someone else. Since version 11g Oracle has introduced new feature that is called deferred segment creation. Thus oracle doesn't create table segment if there are no rows in it. And my table didn't contain any data. So i recreated my table with option 'segment creation immediate'
The solution was found here. There are more options how to fix the problem and an explanation why this thing happens to be in oracle 11g. :)
In addition to the posted answer from Olivia i would like to add some code:
SELECT 'alter table ' || table_name || ' allocate extent;'
from dba_tables where SEGMENT_CREATED = 'NO';
Execute the output and exp again. Your schema will be exported including empty tables.
EDIT:
similar question here, maybe you'll find your solution there.
Change this:
exp user/password file=dump.dmp tables = (table1);
to this:
exp user/password tables = (table1) file=dump.dmp;
You Can Use below query to take table level export from specific user.
exp user/password file=dump.dmp tables = user.table1

Alter table on a running database

I am using Postgres 8.4
I need to execute an ALTER statement on a running database with ~4M data on the relevant table. My sql is like:
ALTER TABLE some_table ALTER a_row bigint;
Now, relevant row type is int
But what i wonder is data consistency, Nearly 3-4 records are written to that table and some more are being read per second.
What i need to do for avoiding data consistency and such other problems.
When you execute and ALTER TABLE sql, table will be locked and you shouldn't have any problems except some possible performance issues in INSERT sqls in your case. But if you are going to do this once, there is no reason to hesitate.

Resources