ALTER TABLESPACE
ALTER TABLESPACE#
Syntax#
alter_tablespace ::=#
datafile_tempfile_clause ::=, modify_checkpoint_path_clause ::=, status_clause ::=, backup_clause ::=
datafile_tempfile_clause ::=#
modify_datafile_clause ::=, modify_autoextend_clause ::=
datafile_spec ::=#
autoextend_clause ::=#
maxsize_clause ::=#
modify_datafile_clause ::=#
modify_autoextend_clause ::=#
modify_checkpoint_path_clause ::=#
status_clause ::=#
backup_clause ::=#
Prerequisites#
The SYS user and users to whom the ALTER TABLESPACE system privilege has been granted can use all of the functionality of the ALTER TABLESPACE statement.
Description#
The ALTER TABLESPACE statement is used to change the definition of a disk, temporary, memory or volatile tablespace. This statement is also used to change other tablespace attributes, including the data and temporary files associated with the tablespace, the checkpoint paths, settings related to automatic extension, and the status of the tablespace.
tablespace_name#
This is used to specify the name of the tablespace to change.
datafile_tempfile_clause#
This is used to add, delete or change a data file or temporary file.
For more detailed information on the datafile_spec, maxsize_clause and autoextend_clause clauses, please refer to the description of the CREATE TABLESPACE statement.
ADD DATAFILE | TEMPFILE#
This is used to add data or temporary files to the corresponding tablespace.
RENAME DATAFILE | TEMPFILE#
This is used to change the name of the data or temporary files in a tablespace. More than one file can be renamed at one time. A file having the same name as TO file_name must have already been created.
modify_datafile_clause#
This is used to change the size or the autoextend attribute of a data or temporary file in a disk tablespace.
modify_autoextend_clause#
This is used to change the autoextension-related attributes for a memory or volatile tablespace, including whether it is automatically extended in size, the unit (increment) by which it is extended, and its maximum size.
DROP DATAFILE | TEMPFILE#
This is used to remove data or temporary files from a tablespace. More than one file can be removed at one time. Because this statement does not actually delete the physical files from the file system, they will need to be deleted (or otherwise managed) manually by the user.
modify_checkpoint_path_clause#
This is used to add, change or delete a checkpoint image path. Operations related to checkpoint image paths can only be performed during the CONTROL phase
ADD CHECKPOINT PATH Clause#
This is used to add a new checkpoint path to a memory tablespace. The DBA can move any checkpoint image files from the existing checkpoint paths to the new checkpoint path as desired. Because Altibase looks for checkpoint image files in all checkpoint paths when a memory tablespace is loaded, checkpoint image files can be stored in any of the checkpoint paths for the tablespace
When checkpointing takes place after a new checkpoint path has been added, the new checkpoint image files are distributed evenly among all of the checkpoint paths, including the new checkpoint path.
If the specified checkpoint path does not exist, or if the user who started up the Altibase server does not have write permissions for the checkpoint path, an error will be raised. Therefore, the DBA must manually create the checkpoint path to be added in the file system and add write permissions to the path for the user.
RENAME CHECKPOINT PATH clause#
This is used to change an existing checkpoint path for a memory tablespace to the path specified in the clause following "TO". The DBA must manually create or rename the actual checkpoint path in the file system. If the specified checkpoint path does not exist, or if the user who started up the Altibase server does not have suitable permissions for the checkpoint path, an error will be raised.
DROP CHECKPOINT PATH clause#
This is used to delete an existing checkpoint path from a memory tablespace. It is the DBA's responsibility to physically move the checkpoint image files in the directory corresponding to the deleted checkpoint path to the remaining checkpoint paths in the tablespace. Because Altibase looks for checkpoint image files in all checkpoint paths when a memory tablespace is loaded, checkpoint image files can be stored in any of the valid checkpoint paths for the tablespace.
Deleting the actual checkpoint path on the file system must be done by the DBA.
The physical path corresponding to the dropped checkpoint path must be manually deleted from the file system. A memory tablespace must have at least one checkpoint path. If an attempt is made to delete the only checkpoint path remaining for a memory space, an error will be raised.
status_clause#
This is used to change the status of a disk or memory tablespace to ONLINE, OFFLINE or DISCARD.
OFFLINE#
When a disk tablespace is taken offline, the contents of all data pages in the buffer corresponding the tablespace are written to data files, and the pages in the buffer pool are invalidated.
In the case of a memory tablespace, the contents of the data pages are written to checkpoint image files, and the page memory is released.
All memory that has been allocated to indexes in the tablespace is released, and the indexes for the tables in the tablespace become unavailable. In addition, the tables in the tablespace become unavailable until the tablespace is brought back online.
ONLINE#
When a disk tablespace is brought online, all of its data files become accessible, and the tables in the tablespace become available again.
When a memory tablespace is brought online, memory is assigned to all data pages again, and the contents of checkpoint image files are loaded back into the memory pages.
If a referenced tablespace is OFFLINE, an attempt to bring the tablespace ONLINE will succeed, but it may be impossible to access the tables that are stored in the tablespace.
A so-called "referenced tablespace" is, in the case of a disk tablespace, a tablespace containing a table that is associated with indexes, BLOB/CLOB columns, etc. that are stored in one or more other tablespaces, or containing a partitioned table having some of its partitions stored in one or more other tablespaces.
DISCARD#
This is used during the CONTROL phase to switch the status of a disk or memory tablespace to DISCARD.
The tables, indexes and BLOB/CLOB columns in a discarded tablespace are unusable. Furthermore, discarded tablespaces are ignored when RESTART RECOVERY is executed and when unused data are removed from the database while the database is being started up.
Once a tablespace has been discarded, the only command that can be executed on it is DROP TABLESPACE. It cannot be brought back ONLINE.
backup clause#
This statement is used to indicate that online backup ("hot backup"), in which the data files for a disk or memory tablespace are copied, is to be performed, or is complete.
BEGIN BACKUP#
This is used to indicate that online backup is to be performed on all of the data files that constitute a tablespace. During the tablespace backup operation, which takes place between this statement and the END BACKUP statement, transactions are not prevented from accessing the tablespace.
Users must execute BEGIN BACKUP before performing online backup. In addition, it is possible to indicate that online backup is to be performed for multiple tablespaces at the same time. However, disk temporary tablespaces cannot be backed up online.
END BACKUP#
This is used to indicate that online backup of a disk or memory tablespace is complete. The user must execute the END BACKUP statement immediately after online backup is completed.
Consideration#
- The ALTER TABLESPACE statement can be used to add data files and change tablespace attributes only when in online mode, and can be used to rename data files only during the CONTROL phase (STARTUP CONTROL).
- status_clause cannot be used with temporary or volatile tablespaces.
Examples#
<Query> Add the data file tbs2.user, which is 64 MB in size, to the user_disk_tbs tablespace. When more space is needed, automatically increase the size of the file in 512 kB increments.
iSQL> ALTER TABLESPACE user_disk_tbs
ADD DATAFILE '/tmp/tbs2.user' SIZE 64M
AUTOEXTEND ON NEXT 512K;
Alter success.
<Query 2> To distribute disk I/O when checkpointing, add the '/home/path' checkpoint path to the user_memory_tbs tablespace. Additionally, change the tablespace attributes such that it increases in size in 256 MB increments and cannot grow larger than 1 GB. (Note that although table attributes can be changed during the SERVICE phase, checkpoint paths can be added only during the CONTROL phase.)
iSQL(sysdba) startup control;
iSQL(sysdba) ALTER TABLESPACE user_memory_tbs ADD CHECKPOINT PATH '/home/path';
Alter success.
iSQL> ALTER TABLESPACE user_memory_tbs ALTER AUTOEXTEND ON NEXT 256M MAXSIZE 1G;
Alter success.
<Query 3> Change the attributes of the user_volatile_tbs tablespace such that it increases in size in 256 MB increments and cannot grow larger than 1 GB.
iSQL> ALTER TABLESPACE user_volatile_tbs ALTER AUTOEXTEND ON NEXT 256M MAXSIZE
1G;
Alter success.