Cannot drop Oracle flashback data archive - oracle

Wanted to do a clean test on Flashback Data Archive so had to remove the existing.
I disabled FDA on all enabled tables and dropped FDA.
But still i see the record in DBA_FLASHBACK_ARCHIVE And DBA_FLASHBACK_ARCHIVE_TS
If i attempt to drop the tablespace, i get "ora-55641 cannot drop tablespace used by flashback data archive". When i drop FDA its successful and no errors.
I tried alter flashback data archive purge and i still could not drop TS
alter flashback archive fla1 purge all;
Then i tried to alter FDA and see if i can delink - alter flashback archive fla1 remove tablespace tbs2; I get the error "ORA-55626: Cannot remove the Flashback Archive's primary tablespace"
Can i know if any internal tables has to be cleaned.

I had a similar situation; in my case I had been having some issues with Flashback Data Archive (Also Known as FBA, FBDA, FDA) with some queries, possibly due to materialized views. So to solve that problem, I dis-associated those tables from the FBDA, using DBMS_FLASHBACK_ARCHIVE.DISASSOCIATE_FBA(owner_name, table_name) which solved the performance problem, but of course those tables were no longer tracked.
Now, I've given up on the FBA on that instance for now, and when cleaning up, I hit the same ORA-55641 and also ORA-55626 when trying to clean up.
What I ended up doing was to re-associate the tables to the flashback data archive, and also (not sure if this was needed, but ...) I purged all records:
alter flashback archive ARCH_FLASHBACK_10_YEAR purge all;
-- Identify tables tied to the flashback archive; mine was named ARCH_FLASHBACK_10_YEAR
select owner_name, table_name, FLASHBACK_ARCHIVE_NAME,
ARCHIVE_TABLE_NAME, status from DBA_FLASHBACK_ARCHIVE_TABLES;
-- look for ones with a STATUS of "DISASSOCIATED" and do the next two
-- statements for those tables
exec DBMS_FLASHBACK_ARCHIVE.REASSOCIATE_FBA ('YOUR_OWNER', 'YOUR_TABLE')
alter table YOUR_OWNER.YOUR_TABLE no flashback archive;
-- Then query again. When clean:
alter flashback archive ARCH_FLASHBACK_10_YEAR remove tablespace ARCH_HIST;
drop flashback archive ARCH_FLASHBACK_10_YEAR;
-- And if ARCH_HIST has no other data:
drop tablespace ARCH_HIST including contents and datafiles;
And after doing those steps I was able to drop the flashback archive, and drop the tablespace associated with that flashback archive.

Related

SQL to limit the types of tables returned when connecting to Oracle Database in Power BI

I have got a connection to an Oracle Database set up in Power BI.
This is working fine, apart from the fact it brings back 9500+ tables that start with "BIN".
Is there some SQL code I can put in the SQL statement section when connecting to the Oracle Database that limits the tables that it returns to ignore any table that begins with 'BIN'?
Tables starting with BIN$ are tables that have been dropped but not purged and are in Oracle's "recycle bin".
The simplest method of not showing them is, if they are no longer required, to PURGE (delete) the tables from the recycle bin and then you will not see them as they will not exist.
You can use (documentation link):
PURGE TABLE BIN$0+xyzabcdefghi123 to get rid of an individual tables with that name (or you can use the original name of the table).
PURGE TABLESPACE tablespace_name USER username; to get rid of all recycled tables in a table space belonging to a single user.
PURGE TABLESPACE tablespace_name; to get rid of all recycled tables in a table space.
PURGE RECYCLEBIN; to get rid of all of the current user's recycled tables.
PURGE DBA_RECYCLEBIN; to get rid of everything in the recycle bin (assuming you have SYSDBA privileges).
Before purging tables you should make sure that they are really not required as you would need to restore from backups to bring them back.

oracle flashback feature for tables of a specific user in a database

I am trying to implement a flashback feature in oracle 11g. I have successfully implemented it but it is not restricted to a single user instead, whenever I restore a flashback it affects all the tables/views for all the users. Is there some way to restrict the restoration to a particular user and avoiding the rest.
Example: I have a database "db" and there are 4 users "a,b,c,d" now, I want to restore the flashback such that it only affects user "a"?
Use the command FLASHBACK TABLE instead of FLASHBACK DATABASE to only affect specific tables.
For example:
create table table1(a number) enable row movement;
create table table2(a number) enable row movement;
--Wait one second.
flashback table jheller.table1, jheller.table2 to timestamp systimestamp - interval '1' second;
Keep in mind that table flashback uses UNDO, while database flashback uses flashback logs. Table flashback depends on UNDO retention and is more picky about things like DDL.

Audit on dropped and recreate table

I have a table that is dropped every day and then recreated.
I executed some audit actions on that table (select, update, delete, insert, all).
Now I want to use the noaudit command to disable audit, but the table is already dropped, so I get an object does not exist exception.
When this table is recreated, will the audit work on it?
I have version oracle 11g.
Thanks.

Oracle 12c - drop table and all associated partitions

I created table t1 in Oracle 12c.
Table has data and it is partitioned on list partition and also has subpartitions.
Now I want to delete whole table and all associated partitions (and subpartitions).
Is this the right command to delete all?
DROP TABLE t1 PURGE;
The syntax is right but not preferable,
just drop without purge so that whenever you need you could have it back, if your flashback option is enabled. If your database's flashback option is in charge, you could issue this command (provided you don't use purge):
SQL> DROP TABLE T1;
SQL> FLASHBACK TABLE T1 TO BEFORE DROP RENAME TO T1_ver_2;
When you run DROP then the table is removed entirely from database, i.e. the table does not exist anymore.
If you just want to remove all data from that table run
truncate table T1 drop storage;
You can also truncate single (sub-)partition if required.

How to Recover an Entire Oracle Schema

I was using Navicat for Oracle to backup an entire Schema. I mistakenly selected the Execute SQL File instead of the Backup file option and All previous data has been changed/lost. I tried using the Oracle Undo feature but it says the table definition has changed. Please i am not skilled in oracle, i only used it for a project cause it was required so i just use it to store the data. I need all the help i can get right now to recover the entire schema to how it was 24 hours ago else i am so screwed...(forgive my language)
From your description you ran a script that dropped and recreated your tables. As you have flashback enabled and your dropped table is in the recycle bin, you can use the 'Flashback Drop' feature to get the dropped table back.
Here's an example with a single table:
create table t43 (id number);
drop table t43;
create table t43 (id2 number);
show recyclebin;
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
-------------------------------- ------------------------------ ------------------------- -------------------
T43 BIN$/ILKmnS4b+jgQwEAAH9jKA==$0 TABLE 2014-06-23:15:38:06
If you try to restore the table with the new one still there you get an error:
flashback table t43 to before drop;
SQL Error: ORA-38312: original name is used by an existing object
You can either rename the restored table:
flashback table t43 to before drop rename to t43_restored;
... which is useful if you want to keep your new table but be able to refer to the old one; or probably more usefully in your situation rename the new table before restoring:
alter table t43 rename to t43_new;
table T43 altered.
flashback table t43 to before drop;
table T43 succeeded.
desc t43
Name Null Type
---- ---- ------
ID NUMBER
You can undrop all of your tables, and as referential constraints still work with tables in the bin you don't have to worry too much about restoring parent tables before child tables, though it's probably neater to do that if you can.
Note that the bit in the documentation about retoring dependent objects - that index names won't be preserved and you'll need to rename them after the restore with alter index.
You can't undrop a sequence; those don't go into the recycle bin. If you need to reset a sequence so it doesn't repeat values you already have, you can get the highest value it should hold (from the primary keys on your restored table, say) and use temporarily change the increment value to skip over the used numbers.

Resources