Thursday 7 September 2017

How to add datafiles to Tablespace in realtime scenario

Hey DBA-mates,
Welcome Again in Oracle Hub.
Adding a data file in Tablespace is a one of the daily task for any dba in any environments or corporations.

And for this also, I have seen almost DBA will search in Google for command and check for the command and process. But during interviews same people will the question about please tell the command for adding datafiles in tablespace.

One thing I don’t understand if a DBA have to search in Google during adding datafiles then why we need to remember and why we should give answer in interviews hehehhehhh.
But boss that is like a process which we can’t change. :D

I have very simple steps to add datafiles in tablespace which will be very important for DBA especially fresher. If they have joined any company and they are not sure about the stuff, they can refer it.

Do you know one reality, even a senior or junior joined any New corp./company, even they know the dba stuff but still they will cross check in Google or with some other colleague and there is nothing wrong in that.
Asking is better than doing mistake and also takes it as positive if you are doing mistake means you are working or learning hehehe yessssss. 
Even I am known for asking the stuff but if never ask twice same things.

Now let’s move to point:
Please follow the below points to add datafiles:

Check for Pre-Check Tablespace details from below command:

select a.tablespace_name, b.total,
       c.available, d.large_extent,
       (b.total - c.available) used,
       round((((b.total - c.available)*100)/b.total),2) pctused
  from (select tablespace_name, (sum(bytes)/1024)/1024 total
          from dba_data_files group by tablespace_name)  b,
       (select tablespace_name,  nvl(round(((sum(bytes)/1024)/1024),2),0) available
          from dba_free_space group by tablespace_name)  c,
       (select tablespace_name, (max(bytes)/1024)/1024 large_extent
          from dba_free_space group by tablespace_name)  d,
       dba_tablespaces  a
 where a.tablespace_name = b.tablespace_name(+)
   and a.tablespace_name = c.tablespace_name(+)
   and a.tablespace_name = d.tablespace_name(+)
   and a.tablespace_name = upper ('&tablespace')
/


Output Sample:

Enter value for tablespace: SKU
old  15:    and a.tablespace_name = upper ('&tablespace')
new  15:    and a.tablespace_name = upper ('SKU')

ORA-DATA - Tablespace Usage Report                              September 04, 2017

                                              Largest
                          Total  Available  Available       Used Percent
Tablespace                   MB         MB     Extent         MB    Used
-------------------- ---------- ---------- ---------- ---------- -------
SKU                    306,742     43,845        412    262,897   85.71
                     ----------                       ----------
sum                     306,742                          262,897
SQL>

Now check for all the datafiles for a given tablespace.
SQL>set verify off

col file_id   heading ' File ID'   format 999999
col file_name heading ' File Name' format a50
col MB        heading 'Megabytes'  format 999999

select file_id, file_name, sum(bytes)/1024/1024 MB
  from dba_data_files
 where tablespace_name = upper('&tblspace')
 group by file_id, file_name
/

set verify on

Output Sample:
Enter value for tblspace: SKU

 File ID  File Name                                         Megabytes
-------- -------------------------------------------------- ---------
     600 /ora-data/SKU/data19/sku101.dbf                    1024
     289 /ora-data/SKU/data21/sku102.dbf                     1024


VERY IMPORTANT POINT:
Check for space available in directory where you are adding datafile.
Check for last name of datafile and add datafile name which is not in list.

Example: In my list, last datafile is 102. So, I will add 103 datafile as shown below:
SQL> show user
USER is "SYS"

SQL> alter tablespace SKU  add datafile '/ora-data/SKU/data21/sku103.dbf ' size 1024 M;
SQL>

Again Check for Tablespace details and space available from above command. 

Hope this may useful and helpful. Please let us know for any concerns either in comment box or contact @ora-data.blogspot.com

Some more important Points:
Regards,
ora-data Team.

15 comments:

  1. After checking out a few of the blog posts on your
    blog, I honestly appreciate your way of writing a blog.
    I bookmarked it to my bookmark site list and will be
    checking back in the near future. Please visit my website as well and let me
    know your opinion.
    Website: http://herb24.space

    ReplyDelete
    Replies

    1. Dear user,

      Please use https:// for safe website.
      My Antivirus is blocking your website.

      Regards,
      ora-data Team.

      Delete
  2. What's up, yup this piece of writing iis genuinely pleasant and I
    have learned lot of things from iit regardding blogging.
    thanks.

    ReplyDelete
    Replies

    1. Dear user,

      Thank you a lots.

      Regards,
      ora-data Team.

      Delete
  3. Wow, marvelous blog layout! How long have you been blogging for?
    you make blogging look easy. The overall look of your web site is fantastic,
    let alone the content!

    ReplyDelete
    Replies

    1. Dear User,

      Thank you.
      Started 1 Year back.

      Regards,
      ora-data Team.

      Delete
  4. Мay Ι simply just sɑy what а comfort tо discover an individual who tгuly
    knows what they are discussing online. You definitеly knoᴡ how tο ƅring
    a pгoblem tօ light ɑnd maҝe it impoгtant. More and moгe people
    need tⲟ read this and understand thіs side of the story.
    I ѡas surprised you are not mⲟre popular given that you most cеrtainly possess the gift.

    ReplyDelete
  5. Hey There. I found your blog using msn. This is a really well written article.
    I'll make sure to bookmark it and return to read more of your useful information. Thanks
    for the post. I'll certainly comeback.

    ReplyDelete
    Replies

    1. Dear User,

      Thank you for your feedback.

      Regards,
      ora-data Team

      Delete
  6. This paragraph will assist the internet people for building up new website or even a blog from start to end.

    ReplyDelete
  7. My brother recommended I might like this web site.
    He used to be totally right. This submit truly made my day.
    You can not believe just how so much time I had spent for this info!

    Thanks!

    ReplyDelete
    Replies

    1. Dear User,

      Thank you very much for your comment and appreciations.

      Regards,
      ora-data Team

      Delete
  8. It is appropriate time to make some plans for the future and it’s time to be happy.

    I have read this post and if I could I wish to suggest you some interesting things or advice.
    Maybe you can write next articles referring to this article.
    I wish to read even more things about it! Woah! I'm really enjoying the template/theme of this blog.
    It's simple, yet effective. A lot of times it's
    hard to get that "perfect balance" between superb usability and appearance.
    I must say you have done a great job with this. In addition, the blog loads extremely fast for me on Internet explorer.
    Outstanding Blog! There is definately a great deal to find
    out about this issue. I love all the points you have made.
    http://foxnews.org

    ReplyDelete
  9. Very well explained. Thanks for sharing proper steps. I was looking to extend tablespace size which really helps.

    ReplyDelete
  10. Very clear steps to <a href='https://orahow.com/add-datafile-in-oracle/" rel="follow">add datafile in Oracle</a>.

    ReplyDelete

Thank you for your comments and suggestions. It's good to talk you.