Flashback a dropped table from recycle bin in Oracle

Restore table from Flashback in Oracle

You can flashback a dropped table from recyclebin using flashback table commands

Check the recyclebin is enabled

SQL> show parameter recyclebin
NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------
recyclebin			     string	 on

Commands to flashback the table after drop commands:

-- Flashback a dropped table from recyclebin using flashback commands:
SQL> SHOW RECYCLEBIN;

SQL> FLASHBACK TABLE "BIN$Fh1VKrueZFngYw8CAAq+WA==$0" TO BEFORE DROP;
OR
SQL> FLASHBACK TABLE SCOTT.TEST TO BEFORE DROP;

--Rename table while flashing it back from recyclebin
SQL> FLASHBACK TABLE SCOTT.TEST TO BEFORE DROP RENAME TO NEW_TEST;

Example to show the use of flashback commands to recover a dropped table:

SQL> create table test (id number);
Table created.

SQL> insert into test values (1);
1 row created.

SQL> insert into test values (2);
1 row created.

SQL> commit;
Commit complete.

SQL> drop table test;
Table dropped.

SQL> show recyclebin;
ORIGINAL NAME RECYCLEBIN NAME		     OBJECT TYPE DROP TIME
------------- ------------------------------ ----------- -------------------
TEST	      BIN$Fh1VKrueZFngYw8CAAq+WA==$0 TABLE	 2024-04-15:11:30:03
 
SQL> FLASHBACK TABLE TEST TO BEFORE DROP;
Flashback complete.

SQL> select * from test;
	ID
----------
	 1
	 2
-- As you see recyclebin having one entry for TEST that go away
SQL> show recyclebin;
SQL> 

You can check from this views recycle objects:

Select * from user_recyclebin;

Show recycle is not showing anything in Oracle

Enabled Recycle bin is not showing anything in Oracle

Reason for showing the recyclebin empty is you are able to login with SYS user and using the SYSTEM tablespace. So that it show recycle bin empty.

Check Recycle Bin is enabled

SQL> show parameter recyclebin
NAME		     TYPE	 VALUE
-------------------- ----------- ------------
recyclebin	     string	 on

I am login with the sys user that why its not capturing the result as we are using system tables with SYS user. We can see the example below by connecting with SYS user:

Note: Please connect with Normal user to avoid this error.

SQL> show user 
USER is "SYS"
SQL> create table test (id number);

Table created.

SQL> insert into test values ( 1);

1 row created.

SQL> insert into test values (2);

1 row created.

SQL> commit;

Commit complete.

SQL> drop table test;

Table dropped.

SQL> show recyclebin
SQL> 
SQL> 

Now connect with Normal user SCOTT and show the example again for Recyclebin usage:

SQL> show pdbs;
    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  MOUNTED
	 3 PDB1 			  READ WRITE NO
SQL> conn scott@pdb1
Enter password: 
Connected.

SQL> create table test (id number);
Table created.

SQL> insert into test values (1);
1 row created.

SQL> insert into test values (2);
1 row created.

SQL> commit;
Commit complete.

SQL> drop table test;
Table dropped.

SQL> show recyclebin;
ORIGINAL NAME RECYCLEBIN NAME		     OBJECT TYPE DROP TIME
------------- ------------------------------ ----------- ----------------
TEST	      BIN$Fh1VKrueZFngYw8CAAq+WA==$0 TABLE	 2024-04-15:11:30:03

Check the user creation date in MySQL / MariaDB

Find the user creation date in MySQL / MariaDB

In MySQL, there is no way to track the user creation date. The table of users does not have an entry for saving the user’s created date.

Check the table mysql.user:

desc mysql.user


Field                 |Type               |Null|Key|Default |Extra|
----------------------+-------------------+----+---+--------+-----+
Host                  |char(255)          |NO  |   |        |     |
User                  |char(128)          |NO  |   |        |     |
Password              |longtext           |YES |   |        |     |
Select_priv           |varchar(1)         |YES |   |        |     |
Insert_priv           |varchar(1)         |YES |   |        |     |
Update_priv           |varchar(1)         |YES |   |        |     |
Delete_priv           |varchar(1)         |YES |   |        |     |
Create_priv           |varchar(1)         |YES |   |        |     |
Drop_priv             |varchar(1)         |YES |   |        |     |
Reload_priv           |varchar(1)         |YES |   |        |     |
Shutdown_priv         |varchar(1)         |YES |   |        |     |
Process_priv          |varchar(1)         |YES |   |        |     |
File_priv             |varchar(1)         |YES |   |        |     |
Grant_priv            |varchar(1)         |YES |   |        |     |
References_priv       |varchar(1)         |YES |   |        |     |
Index_priv            |varchar(1)         |YES |   |        |     |
Alter_priv            |varchar(1)         |YES |   |        |     |
Show_db_priv          |varchar(1)         |YES |   |        |     |
Super_priv            |varchar(1)         |YES |   |        |     |
Create_tmp_table_priv |varchar(1)         |YES |   |        |     |
Lock_tables_priv      |varchar(1)         |YES |   |        |     |
Execute_priv          |varchar(1)         |YES |   |        |     |
Repl_slave_priv       |varchar(1)         |YES |   |        |     |
Repl_client_priv      |varchar(1)         |YES |   |        |     |
Create_view_priv      |varchar(1)         |YES |   |        |     |
Show_view_priv        |varchar(1)         |YES |   |        |     |
Create_routine_priv   |varchar(1)         |YES |   |        |     |
Alter_routine_priv    |varchar(1)         |YES |   |        |     |
Create_user_priv      |varchar(1)         |YES |   |        |     |
Event_priv            |varchar(1)         |YES |   |        |     |
Trigger_priv          |varchar(1)         |YES |   |        |     |
Create_tablespace_priv|varchar(1)         |YES |   |        |     |
Delete_history_priv   |varchar(1)         |YES |   |        |     |
ssl_type              |varchar(9)         |YES |   |        |     |
ssl_cipher            |longtext           |NO  |   |        |     |
x509_issuer           |longtext           |NO  |   |        |     |
x509_subject          |longtext           |NO  |   |        |     |
max_questions         |bigint(20) unsigned|NO  |   |0       |     |
max_updates           |bigint(20) unsigned|NO  |   |0       |     |
max_connections       |bigint(20) unsigned|NO  |   |0       |     |
max_user_connections  |bigint(21)         |NO  |   |0       |     |
plugin                |longtext           |NO  |   |        |     |
authentication_string |longtext           |NO  |   |        |     |
password_expired      |varchar(1)         |NO  |   |        |     |
is_role               |varchar(1)         |YES |   |        |     |
default_role          |longtext           |NO  |   |        |     |
max_statement_time    |decimal(12,6)      |NO  |   |0.000000|     |

To store the created date in the table, you must alter the table with the root user or create a seperate table to hold entry of it. In following i am using seperate table for holding user creation time.

If you want to save the creation time of users in MariaDB / MySQL, you can create a custom table to store this information and use triggers to automatically update this table whenever a new user is created. Here’s a basic example of how you can achieve this:

  1. Create a custom table to store user creation times:
CREATE TABLE user_creation_times (
    username VARCHAR(100),
    creation_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

2. Create a trigger to insert the creation time into the custom table whenever a new user is created:

DELIMITER //

CREATE TRIGGER after_user_creation
AFTER INSERT ON mysql.user
FOR EACH ROW
BEGIN
    INSERT INTO user_creation_times (username) VALUES (NEW.User);
END//

DELIMITER ;

With this trigger in place, every time a new user is inserted into the mysql.user table, the trigger will automatically insert the username and the current timestamp into the user_creation_times table.

Keep in mind that you may need appropriate permissions to create triggers and modify system tables. Also, modifying system tables like mysql.user directly can have security implications, so make sure you understand the implications of doing so in your environment.