Hope you are doing fantastic being an Oracle professional.
I wrote a blog on Oracle TABLESPACE. If you have not read that yet, I highly recommend you to click here and have a look.
In that blog, we learned how to create a Tablespace in the Oracle Database and I explained that every tablespace contains at least one datafile. So, in this blog we will learn about the datafile.
What is a Datafile?
Datafile is a storage sub-unit exists in a Tablespace in the Oracle database. Whenever we import any data into the Oracle database, it creates the tables and stores the data into the datafiles.
Next we will learn how to ADD/ALTER/DROP datafiles.
How to ADD a Datafile to an existing Tablespace?
We already have an existing Tablespace (PERM_TBLSPC) with one datafile (PERM_DF.DBF) we created while learning about the Tablespace.
We will add a new Datafile to this tablespace. First, we will check this tablespace and existing datafiles using the below query.
Above output confirms that we have a Tablespace with only one datafile.
Let’s use ALTER TABLESPACE statement and add a new datafile to the tablespace.
You can check the new datafile by running the first snippet SELECT statement.
How to ALTER a Datafile?
We added above datafile with the size of 50MB. Let’s alter this datafile and add more 50MB memory to this datafile.
This time we will be using ALTER DATABASE statement with RESIZE keyword.
Let’s check the current size of the datafile(s).
Oracle database shows the datafile size in BYTES. That’s the reason I have divided it by 1024 twice to make it MEGABYTE(MB).
How to DROP a Datafile?
Until now we have learned how to add/alter a datafile. Next, we will learn how to DROP a datafile.
It is a very similar task what we did above while adding a datafile. Just replace ADD by DROP and remove SIZE keyword.
You can query to DBA_DATA_FILES table to check if datafile has been deleted or not.
That’s all about datafile. Again, I have included very specific content to this blog to keep it easy to understand.
If you have any questions please comment below or write me an email.