oracletablespacedata-files

Oracle Tablespace multiple datafile with autoextend and maxsize


I'm completely new to Oracle Database and I'm trying to learn it. My goal today is to create a simple tablespace with one datafile and then add a new datafile to that tablespace. With this I understand that my tablespace will start at 1M and will automatically extend(50M each time) until it reaches 1000M.

CREATE TABLESPACE simple_tablespace DATAFILE '/oracle/app/oracle/oradata/ORACLE/datafile/simple_tablespace_01.dbf' SIZE 1M AUTOEXTEND ON NEXT 50M MAXSIZE 1000M;

Lets assume that my tablespace is already at 1000M and instead of having one single big datafile, i want to have multiple datafile. What is the best way to handle this situation? The relation between Tablespace MAXSIZE, datafile SIZE and the number of datafile in a tablespace is not 100% clear for me.


Solution

    1. SIZE is how big the new file should be when created, at the start.
    2. NEXT enables autoextend functionality to add that much more space every time the existing file is full.
    3. MAXSIZE is an autoextend parameter that tells the autoextend functionality when to stop extending the file, so sets a limit to how large the file can get.

    None of the above have anything to do with the tablespace. They control the individual datafile. When you create a tablespace it needs at least one starting datafile, and that's the one you've specified in your CREATE TABLESPACE command, so those size settings are all related to that first file, not the tablespace itself. There is no (within reason) maximum size for a tablespace, at least not one we define ourselves.

    As long as you don't define your tablespace as BIGFILE, you can add as many datafiles to it as you'd like whenever you'd like:

    ALTER TABLESPACE simple_tablespace ADD DATAFILE '....' SIZE ....

    With multiple files in a tablespace, Oracle will interleave extents across the files, causing any autoextending that you've enabled on any of them to continue increasing the file sizes up to their max, but more slowly. You don't want lots of files - fewer is better. However, a traditional datafile is limited to 32G, so once you get to that point you're forced to grow by adding more files.

    Alternatively, you can create one huge tablespace with BIGFILE and then you are no longer limited to a 32G file size. But then you only get one file. Autoextend is necessary to keep it growing.

    In most cases, BIGFILE (one file per tablespace) is preferrable in modern times. Adding datafiles when more space is needed becomes a management headache and requires custom scripting. And we rarely run on boxes with local storage where we have to manually manage I/O across different disks, which is the old reason for multiple files. Most of us are using storage arrays that handle all that for us, so a single file works just as performantly and is a lot easier to manage.