Category Archives: Database Administrator

Become a Database Administrator with DevOpsRoles.com. Access expert guides and tutorials to master database management, optimization, and security for DevOps.

Mastering Oracle query tablespace: A Comprehensive Guide for DBAs

Introduction

In this guide, you’ll learn how to efficiently query Oracle tablespaces using SQL commands. This guide covers essential techniques for monitoring tablespace size, available space, and differentiating between various types of tablespaces. This practical approach aims to enhance database management skills for Oracle administrators.

  1. What is Oracle SQL Tablespace?
    An overview of tablespaces in Oracle databases, explaining their purpose and types.
  2. How to Query Oracle Tablespace?
    Basic SQL queries to retrieve information about tablespaces, including size and contents.
  3. Check Tablespace Usage Percentage in Oracle
    Methods to calculate the usage percentage of tablespaces to monitor efficiency and plan for scaling.
  4. Oracle Query Tablespace Usage
    Advanced querying techniques to analyze tablespaces’ performance and optimize storage management.

Step-by-Step: Guide to Oracle Query Tablespace

How does a query check tablespace size, free space, and Big file vs small file SYSTEM tablespace? The following statement is below

SELECT tablespace_name,
  SUM(bytes)/1024/1024 AS mb
FROM
  ( SELECT tablespace_name, bytes FROM dba_data_files
  UNION ALL
  SELECT tablespace_name,bytes FROM dba_temp_files
  )
WHERE tablespace_name='SYSTEM'
GROUP BY tablespace_name;

Sample Output

TABLESPACE_NAME                    MB
-------------------- ----------------
SYSTEM                          2,048

To query tablespace “SIZE EXTEND, BIG_SMALL_FILE, BLOCK_SIZE” in Oracle.

SELECT dt.tablespace_name tablespace_name,
  SUBSTR(ddf.file_name,0, instr(ddf.file_name, '/', -1, 1) - 1) AS placement_directory,
  SUBSTR(ddf.file_name, instr(ddf.file_name, '/',   -1, 1) + 1) AS file_name,
  ddf.bytes                                         /1024/1024  AS mb,
  ddf.autoextensible,
  DECODE (dt.bigfile,'NO','SMALL','YES','BIG') AS BIG_SMALL_FILE,
  dt.block_size block_size
FROM
  (SELECT tablespace_name, file_name, bytes,autoextensible FROM dba_data_files
  UNION
  SELECT tablespace_name, file_name, bytes,autoextensible FROM dba_temp_files
  ) ddf,
  (SELECT tablespace_name, block_size,bigfile FROM dba_tablespaces
  ) dt
WHERE dt.tablespace_name = ddf.tablespace_name
AND dt.tablespace_name   = 'SYSTEM';

Sample Output

TABLESPACE_NAME
--------------------
PLACEMENT_DIRECTORY
------------------------------------------------------------------------------------------------------------------------------------
FILE_NAME                                                                            MB AUTOEXTEN BIG_SMALL_FILE  BLOCK_SIZE
---------------------------------------------------------------------- ---------------- --------- --------------- ----------
SYSTEM
/mnt_nfs/dbdata/mydata
system02.dbf                                                                      2,048 NO        SMALL                 9192

Conclusion

This article provides a comprehensive guide to Oracle query tablespaces for size, auto-extension, file types, and block sizes. By mastering these queries, you can effectively monitor and optimize your Oracle database storage. Continuous monitoring and analysis will ensure that your database runs efficiently and remains scalable. I hope will this your helpful. Thank you for reading the DevopsRoles page!

How to check the Oracle database character set

Introduction

Character sets are a crucial aspect of Oracle databases, influencing data storage, retrieval, and integrity. Properly setting and verifying your Oracle database’s character set ensures compatibility across different systems and prevents data corruption. This guide will walk you through various methods how to Oracle database character set, including using the NLS_CHARACTERSET and NLS_NCHAR_CHARACTERSET parameters.

Basic Methods to Check Oracle Database Character Set

Using SQL*Plus

One of the simplest ways to check your Oracle database character set is through SQL*Plus. Follow these steps:

Log in to SQL*Plus:

sqlplus username/password@database

Execute the following query:

SELECT parameter, value 
FROM nls_database_parameters 
WHERE parameter = 'NLS_CHARACTERSET';

Using Data Dictionary Views

Oracle provides several data dictionary views that store character set information. The NLS_DATABASE_PARAMETERS view is one such view.

  1. Log in to SQL*Plus or any other SQL interface.
  2. Run the following query:
    • SELECT * FROM v$nls_parameters WHERE parameter = 'NLS_CHARACTERSET';

Intermediate Methods to Check Oracle Database Character Set

Using DBMS_SESSION Package

The DBMS_SESSION package allows you to access various session-level settings, including character set information.

Run the following PL/SQL block:

DECLARE
l_nls_characterset VARCHAR2(30);
BEGIN
DBMS_SESSION.GET_NLS('NLS_CHARACTERSET', l_nls_characterset);
DBMS_OUTPUT.PUT_LINE('Database Character Set: ' || l_nls_characterset);
END;
/

Checking Character Set in a Multitenant Environment

In a multi-tenant environment, it’s essential to check the character set of each pluggable database (PDB).

  1. Connect to the container database (CDB).
    • sqlplus username/password@CDB
  2. Query the character set for each PDB:
    • SELECT name, value FROM v$pdbs, v$nls_parameters WHERE parameter = 'NLS_CHARACTERSET' AND con_id = pdb.con_id;

Advanced Methods to Check Oracle Database Character Set

Using Oracle Enterprise Manager

Oracle Enterprise Manager provides a graphical interface to check and manage database settings, including character sets.

  1. Log in to Oracle Enterprise Manager.
  2. Navigate to the database you want to check.
  3. Go to the “Administration” tab and select “NLS Database Parameters.”
  4. Check the “NLS_CHARACTERSET” parameter.

Using SQL Developer

Oracle SQL Developer is a powerful tool that allows you to manage database settings graphically.

  1. Open Oracle SQL Developer and connect to your database.
  2. Navigate to “View” > “DBA.”
  3. Expand the “Database” node and select “NLS.”
  4. Find the “NLS_CHARACTERSET” parameter.

Checking Both NLS_CHARACTERSET and NLS_NCHAR_CHARACTERSET

To get a complete picture of your Oracle database character settings, you should check both the NLS_CHARACTERSET and NLS_NCHAR_CHARACTERSET parameters. Here’s how you can do it:

Log in to SQL*Plus:

sqlplus username/password@database

Execute the following query to check the NLS_CHARACTERSET:

SELECT PROPERTY_NAME, PROPERTY_VALUE
FROM database_properties
WHERE PROPERTY_NAME = 'NLS_CHARACTERSET';

Screen output:

PROPERTY_NAME                  PROPERTY_VALUE
------------------------------ --------------
NLS_CHARACTERSET               AL32UTF8

Execute the following query to check the NLS_NCHAR_CHARACTERSET:

SELECT PROPERTY_NAME, PROPERTY_VALUE 
FROM database_properties 
WHERE PROPERTY_NAME = 'NLS_NCHAR_CHARACTERSET'; 

Screen output:

PROPERTY_NAME PROPERTY_VALUE


NLS_NCHAR_CHARACTERSET AL16UTF16

Frequently Asked Questions (FAQs)

What is a character set in Oracle?

A character set in Oracle defines the set of characters that can be used in the database, determining how data is stored and retrieved. It includes encoding rules for characters.

Why is it important to check the Oracle database character set?

Checking the Oracle database character set ensures data integrity and compatibility, especially when dealing with multiple languages and diverse systems. It prevents data corruption and ensures seamless data exchange.

How can I change the character set of my Oracle database?

Changing the character set of an Oracle database is a complex process that involves exporting the database, creating a new database with the desired character set, and importing the data. It is recommended to consult Oracle documentation and perform thorough testing.

Can I check the character set using PL/SQL Developer?

Yes, you can use PL/SQL Developer to check the character set. Connect to your database, navigate to “View” > “NLS Parameters,” and find the “NLS_CHARACTERSET” parameter.

What are the common character sets used in Oracle databases?

Common character sets include AL32UTF8, UTF8, WE8ISO8859P1, and WE8MSWIN1252. The choice depends on the languages and data types you need to support.

Conclusion

Through this article, you have learned how to check the Oracle database character set using various methods, including NLS_CHARACTERSET and NLS_NCHAR_CHARACTERSET. Properly identifying and managing your Oracle database character set is essential for maintaining data integrity and compatibility.

By following these steps, you can confidently manage your database settings, ensuring smooth operations and data handling across different systems and languages. I hope this guide is helpful. Thank you for reading the DevopsRoles page!

How to Oracle query Database name: A Step-by-Step Guide

Introduction

In this tutorial, How do I use the Oracle query Database name? Using “v$parameter” for the database name. This tutorial guides you on how to query the “v$system_parameter” to determine the database name in Oracle. By connecting as SYSDBA and executing a specific SQL query, users can retrieve the database name from the system parameters, a crucial skill for database administrators managing multiple Oracle environments.

To query the database name in Oracle, start by connecting to the database using the SYSDBA role. This role grants you the necessary privileges to perform administrative tasks, including querying system parameters to find out detailed configuration information such as the database name. This process involves executing specific SQL commands that access Oracle’s system views, which contain data about the database instance.

[huupv@localhost ~]$ sudo su - oracle
[oracle@localhost ~]$ sqlplus "/as sysdba"

Oracle query Database name

SQL> SELECT name, value from v$parameter WHERE name = 'db_name' order by name;

The screen output terminal

NAME                         VALUE
--------------------------- -----------
db_name                  DRDB1

Conclusion

Successfully querying the “v$system_parameter” for the database name provides valuable insights into your Oracle database configuration. This method, though straightforward, requires careful execution of the SQL command provided to ensure accurate data retrieval and system management I hope will this your helpful. Thank you for reading the DevopsRoles page!

Ultimate MySQL Cheat Sheet: Essential Commands You Need to Know

Introduction

Welcome to the MySQL Cheat Sheet, a valuable resource for anyone looking to enhance their command line skills with MySQL. This comprehensive guide covers a range of commands, from basic operations like database creation and deletion to more complex tasks such as backing up and restoring databases.

In this tutorial, I will write a MySQL Cheat sheet by command line. How to Reset Root Password in MySQL? How to backup and restore databases, and so forth in MySQL databases.

  • MySQL Database Commands Cheat Sheet:
    • A comprehensive list of commands for database creation, modification, and management.
  • MySQL Command Line Client Cheat Sheet:
    • Essential commands for initiating and interacting with MySQL through the command line.
  • Create Table MySQL Cheat Sheet:
    • Syntax and options for creating tables, defining columns, setting data types, and applying constraints.
  • MySQL Connect Cheat Sheet:
    • Commands for connecting to a MySQL database using various authentication methods.

MySQL cheat sheet

At the command line, log in to MySQL as the root user:

mysql -u root -p

How to create and delete MySQL DATABASE

CREATE DATABASE DBName
CREATE DATABASE DBName CHARACTER SET utf8
DROP DATABASE DBName

Backup DATABASE to SQL File in MySQL

mysqldump -u Username -p DBName > sampledatabasename_backup.sql

Restore from backup SQL File in MySQL

mysql - u Username -p DBName < sampledatabasename_backup.sql

MySQL select query

SELECT * FROM table
SELECT * FROM table1, table2, ...
SELECT field1, field2, ... FROM table1, table2, ...
SELECT ... FROM ... WHERE condition
SELECT ... FROM ... WHERE condition GROUPBY field
SELECT ... FROM ... WHERE condition GROUPBY field HAVING condition2
SELECT ... FROM ... WHERE condition ORDER BY field1, field2
SELECT ... FROM ... WHERE condition ORDER BY field1, field2 DESC
SELECT ... FROM ... WHERE condition LIMIT 10
SELECT DISTINCT field1 FROM ...
SELECT DISTINCT field1, field2 FROM ...

Users and Privileges in MySQL

GRANT ALL PRIVILEGES ON sampledatabase.* TO 'user'@'localhost' IDENTIFIED BY 'password';
GRANT SELECT, INSERT, DELETE ON sampledatabase.* TO 'user'@'localhost' IDENTIFIED BY 'password';
REVOKE ALL PRIVILEGES ON sampledatabase.* FROM 'user'@'hostname'; -- one permission only
REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'user'@'hostname'; -- To revoke all privileges, which drops all global, database, table, column, and routine privileges for the named user or users

SET PASSWORD = PASSWORD('new_pass')
SET PASSWORD FOR 'user'@'hostname' = PASSWORD('new_pass')
SET PASSWORD = OLD_PASSWORD('new_pass')

DROP USER 'user'@'hostname' -- DROP to delete a user

Reset Root Password in MySQL

$ /etc/init.d/mysql stop
$ mysqld_safe --skip-grant-tables

Open another terminal

$ mysql 
mysql> UPDATE mysql.user SET password=PASSWORD('new_pass') WHERE user='root';

Switch back to the mysqld_safe terminal and kill the process using Control

$ /etc/init.d/mysql start

Conclusion

This MySQL Cheat Sheet is designed to serve as a quick reference for frequently used MySQL commands. Whether you’re a beginner or an experienced developer, these commands are essential tools to efficiently manage your databases. Keep this guide handy to streamline your database operations. I hope will this your helpful. Thank you for reading the DevopsRoles page!

How to find latest Oracle database patchset

In this tutorial, How to find the latest Oracle database patchset: Patch Set Release (PSR). Sometimes you check the latest patch name.

find latest Oracle database patchset

Which oracle patch has installed your system?

The easiest check Patch Set Release (PSR)as command below

$ sudo su - oracle
$ opatch lsinventory | grep "^Oracle Client"

More verbose list on the installed Oracle patches:

$ sudo su - oracle
$ opatch lsinventory -details

Conclusion

Thought the article, You can “How to find latest Oracle database patchset” as above. I hope will this your helpful. Thank you for reading the DevopsRoles page!

How to check dump file size in oracle

In this tutorial, we will show you How to check dump file size in Oracle. Sometimes, you need to export the entire database and may not know the exact space required for the dump file. Oracle provides the expdp command to perform this export.

Check dump file size in Oracle

The query calculates how much dump file table data each schema on your databases.

SELECT owner, segment_type, SUM(bytes)/1024/1024/1024 GB
FROM dba_segments
WHERE owner IN ('huupv') AND segment_type NOT LIKE '%INDEX'
GROUP BY owner, segment_type
ORDER BY 1, 2;

Note:

  • Replace [USER_NAME] with the specific username for which you want to get the dump size.
  • For example, if [USER_NAME] is huupv, the query becomes:
SELECT owner, segment_type, SUM(bytes)/1024/1024/1024 GB
FROM dba_segments
WHERE owner IN ('huupv') AND segment_type NOT LIKE '%INDEX'
GROUP BY owner, segment_type
ORDER BY 1, 2;

Conclusion

Throughout the article, you can learn how to “check dump file size in Oracle” as described above. I hope you find this information helpful. Thank you for reading the DevopsRoles page!

Solving “Oracle 12c unable to access port 5500” Issue

Introduction

In this tutorial, we will address how to solve the issue of “Oracle 12c unable to access port 5500”. This is an essential skill for DevOps roles involved in Oracle database management. By following these steps, you will be able to resolve the port access issue and ensure smooth connectivity to your Oracle database.

Accessing the Oracle Database with Required Privileges

First, access the Oracle database with the necessary permissions:

sqlplus / as sysdba

Checking Port 5500 from SYSDBA Oracle

Execute the following SQL command to check the current HTTPS port configuration:

SQL> select dbms_xdb_config.gethttpsport from dual;

Terminal Output

markdownCopy codeGETHTTPSPORT
------------
5500

If the port is not set to 5500, you can set it using the following command:

Setting HTTPS Port to 5500

Execute the following PL/SQL command to set the HTTPS port to 5500:

SQL> exec DBMS_XDB_CONFIG.SETHTTPSPORT(5500);

Terminal Output

PL/SQL procedure successfully completed.

Starting the Listener Service

To ensure that the listener service is running, use the lsnrctl command from the command line:

[oracle@DBOracle ~]$ lsnrctl start LISTENER

Checking Port 5500 Listening in Linux

Verify that port 5500 is listening by using the netstat command:

$ netstat -nplt | grep 5500

Accessing the Oracle Database Web Interface

Now, you should be able to access the Oracle database web interface. Open your web browser and navigate to:

https://192.168.1.114:5500/em/

Conclusion

In this article, we covered how to solve the “Oracle 12c unable to access port 5500” issue. By following these steps, you should now be able to configure and access port 5500 for your Oracle database. This ensures efficient management and connectivity for your database applications. Thank you for reading the DevopsRoles page!

How to Drop User Cascade Oracle: A Comprehensive Guide

Introduction

Managing users and their associated objects in an Oracle database is a crucial aspect of database administration. Occasionally, a user account may become obsolete, requiring removal from the system. Oracle provides the DROP USER CASCADE command, allowing administrators to drop a user and all objects owned by that user in one step.

However, executing this command demands careful consideration due to its irreversible nature. This guide will walk you through the entire process, ensuring you understand each aspect, from prerequisites to practical examples.

Understanding the Drop User Cascade Command in Oracle

What Is the Drop User Cascade Command?

The DROP USER CASCADE command is an Oracle SQL statement that allows the removal of a user account from the database. Unlike a simple user deletion, the cascade option extends its functionality by deleting all objects owned by that user, such as tables, indexes, views, and more.

Why Use the DROP USER CASCADE Command?

There are several scenarios where using the DROP USER CASCADE command is necessary:

  1. Cleaning Up Unused Accounts: When a user account is no longer needed, and you want to remove it along with all its objects to free up resources.
  2. Managing Security: Eliminating obsolete user accounts reduces security risks by ensuring that no abandoned user objects remain in the database.
  3. Database Maintenance: Regular maintenance may involve dropping outdated or redundant users to maintain an organized and efficient database environment.

Prerequisites for Using DROP USER CASCADE

Before executing the DROP USER CASCADE command, certain conditions must be met:

  1. System Privileges: You must have the DROP USER system privilege to perform this operation. Without this privilege, the command cannot be executed.
  2. Understanding the Impact: Since the command is irreversible, thoroughly assess the impact of dropping a user and its objects. Ensure you have appropriate backups if needed.

Basic Syntax of DROP USER CASCADE

The basic syntax for the DROP USER CASCADE the command is straightforward:

DROP USER username CASCADE;

Here, username represents the name of the user you wish to drop. The CASCADE option ensures that all objects owned by the user are also removed.

How to Drop a User with the CASCADE Option

Step-by-Step Guide to Dropping a User

Step 1: Verify User Existence

Before dropping a user, ensure that the user exists in the database. You can check this using the following query:

SELECT username FROM dba_users WHERE username = 'HUUPV';

If the user exists, the query will return the username.

Step 2: Review Owned Objects

It’s crucial to review the objects owned by the user before dropping them. Use the following query to list all objects:

SELECT object_name, object_type FROM dba_objects WHERE owner = 'HUUPV';

This step helps you understand what will be deleted.

Step 3: Execute the DROP USER CASCADE Command

Once you’ve verified the user and reviewed the objects, you can execute the command:

DROP USER HUUPV CASCADE;

This command will remove the user HUUPV and all associated objects.

Handling Common Issues and Errors

What Happens if the User Owns No Objects?

If the user owns no objects, the CASCADE option will still work, but it won’t have any additional effect. The user will simply be dropped.

Can the Command Be Rolled Back?

No, the DROP USER CASCADE the command is irreversible. Once executed, the user and all owned objects are permanently deleted.

Error: ORA-01940: Cannot Drop a User That Is Currently Connected

This error occurs if the user is currently connected to the database. To resolve it, you must disconnect the user before executing the command.

ALTER SYSTEM DISCONNECT SESSION 'SID,SERIAL#' IMMEDIATE;

Replace SID,SERIAL# with the specific values from the user’s session.

FAQs on Dropping Users in Oracle

What does the CASCADE keyword do?

The CASCADE keyword in the DROP USER command ensures that all objects owned by the user are also dropped. This is useful for thoroughly cleaning up the database when removing a user.

Can I drop multiple users simultaneously with DROP USER CASCADE?

No, the DROP USER CASCADE command is designed to drop one user at a time. If you need to drop multiple users, you must issue separate commands for each user.

Is it possible to recover a user dropped with CASCADE?

Once a user is dropped with the CASCADE option, it is not possible to recover them or their associated objects. Ensure that dropping the user is the correct action before proceeding.

Do I need to back up the database before dropping a user?

While not mandatory, it is highly recommended to back up the database before dropping a user, especially if the user owns important objects. This provides a safety net in case of accidental data loss.

What system privilege is required to drop a user in Oracle?

The DROP USER system privilege is required to execute the DROP USER CASCADE command. Without this privilege, you will not be able to perform the operation.

Best Practices for Using DROP USER CASCADE

Always Review the Impact

Before dropping a user with the CASCADE option, carefully review the potential impact. Understand what objects will be deleted and consider whether they are still needed.

Implement Database Auditing

Consider implementing database auditing to track user activities and understand what a user has done before you drop them. This can help in assessing whether it’s safe to remove the user.

Schedule User Drops During Low-Traffic Periods

Dropping a user, especially one with many associated objects, can be resource-intensive. Schedule the operation during low-traffic periods to minimize the impact on database performance.

Document the Process

Maintain thorough documentation of the process, including why the user was dropped and what objects were affected. This is useful for future reference and accountability.

Conclusion

Dropping a user and their associated objects in Oracle is a significant operation that requires careful consideration and appropriate privileges. The DROP USER CASCADE command is a powerful tool for database administrators to manage users efficiently and maintain a clean database environment. By following the steps and best practices outlined in this guide, you can confidently perform this operation while minimizing the risk of unintended consequences.

Thank you for reading this comprehensive guide. We hope it provides the clarity and guidance you need to manage your Oracle database effectively. If you have any further questions, feel free to explore our other resources or reach out to a professional Oracle expert. Thank you for reading the DevopsRoles page!

How to Oracle import dmp file: A Comprehensive Guide

Introduction

In this tutorial, you will learn how to Oracle import dmp file. This process involves creating a new schema and then importing the data from the DMP file into the new schema. This guide will provide step-by-step instructions to help you accomplish this task efficiently.

Step 1: Create a New Schema

Before importing the DMP file, you need to create a new schema where the data will be imported.

Connect to SQL*Plus

Navigate to the directory where your schema creation script is located and connect to SQL*Plus with DBA privileges:

cd /tmp
sqlplus / as sysdba

Run Schema Creation Script

Run the script to create the new schema. In this example, the script is named CRT_SCHEMA_newhuupv:

SQL> @/home/oracle11g/HuuPV2/CRT_SCHEMA_newhuupv

Exit SQL*Plus

After running the script, exit SQL*Plus:

SQL> exit;

Example of Schema Creation Script

Here’s an example of what your schema creation script (CRT_SCHEMA_newhuupv.sql) might look like:

CREATE USER newhuupv IDENTIFIED BY password;
GRANT CONNECT, RESOURCE TO newhuupv;
ALTER USER newhuupv DEFAULT TABLESPACE users;
ALTER USER newhuupv TEMPORARY TABLESPACE temp;

Step 2: Import the DMP File

With the new schema created, you can now import the data from the DMP file.

Set NLS_LANG Environment Variable

Set the NLS_LANG environment variable to ensure proper character set handling:

export NLS_LANG=American_America.UTF8

Run the Import Command

Use the imp utility to import the data from the DMP file. Replace oldhuupv with the source schema name and newhuupv with the target schema name:

imp userid=oldhuupv/oldhuupv@DevopsRoles fromuser=oldhuupv touser=newhuupv BUFFER=100000 file=./exp_ora.dmp log=./exp_ora.log

Explanation of Parameters

  • userid: Specifies the user credentials for the import process.
  • fromuser: Specifies the source schema from which data is exported.
  • touser: Specifies the target schema to which data will be imported.
  • BUFFER: Sets the buffer size for the import.
  • file: Specifies the path to the DMP file.
  • log: Specifies the path to the log file where the import process will be logged.

Note

  • File dump: exp_ora.dmp
  • Service Name: DevopsRoles
  • To schema: newhuupv

Conclusion

In this tutorial, we covered the steps to create a new schema and import a DMP file into Oracle. By following these instructions, you should be able to efficiently import data into a new schema. For more Oracle tutorials and tips, continue following our page!

How to Oracle create tablespace: A Comprehensive Guide

Introduction

In this tutorial, you will learn how to Oracle create tablespace, including creating permanent and temporary tablespaces, as well as creating multiple datafiles with a single tablespace creation command. Understanding how to manage tablespaces is crucial for effective database administration.

Creating a Permanent Tablespace

Permanent tablespaces store user data and schema objects. Here’s how to create a bigfile permanent tablespace:

SQL Command

CREATE BIGFILE TABLESPACE USERDATA 
LOGGING
DATAFILE '/mnt_nfs/oradata/oracle11g/DEVOPSROLES/USERDATA.dbf'
SIZE 2048MB
EXTENT MANAGEMENT LOCAL
SEGMENT SPACE MANAGEMENT AUTO;

Explanation

  • USERDATA: Name of the tablespace.
  • LOGGING: Enables logging for the tablespace.
  • DATAFILE: Specifies the location and name of the datafile.
  • SIZE 2048MB: Sets the size of the datafile.
  • EXTENT MANAGEMENT LOCAL: Manages extents locally.
  • SEGMENT SPACE MANAGEMENT AUTO: Automatically manages segment space.

Datafile Details

  • Named datafile: USERDATA
  • Size: 2048MB
  • Location: /mnt_nfs/oradata/oracle11g/DEVOPSROLES/USERDATA.dbf

Creating a Temporary Tablespace

Temporary tablespaces are used for sorting operations and temporary data storage.

SQL Command

CREATE TEMPORARY TABLESPACE TEMP_DATA 
TEMPFILE '/mnt_nfs/oradata/oracle11g/DEVOPSROLES/TEMP_DATA.dbf'
SIZE 32M
AUTOEXTEND ON
NEXT 32M
MAXSIZE 1048M
EXTENT MANAGEMENT LOCAL;

Explanation

  • TEMP_DATA: Name of the temporary tablespace.
  • TEMPFILE: Specifies the location and name of the tempfile.
  • SIZE 32M: Initial size of the tempfile.
  • AUTOEXTEND ON: Enables auto-extension of the tempfile.
  • NEXT 32M: Amount of space added on each extension.
  • MAXSIZE 1048M: Maximum size the tempfile can grow to.
  • EXTENT MANAGEMENT LOCAL: Manages extents locally.

Note

  • A temporary tablespace uses tempfiles, not datafiles.

Creating Multiple Datafiles with a Single Tablespace

You can create a tablespace with multiple datafiles in a single command.

SQL Command

CREATE TABLESPACE DATA 
DATAFILE '/mnt_nfs/oradata/oracle11g/DEVOPSROLES/DATA_01.dbf' SIZE 4M AUTOEXTEND OFF,
'/mnt_nfs/oradata/oracle11g/DEVOPSROLES/DATA_02.dbf' SIZE 4M AUTOEXTEND OFF,
'/mnt_nfs/oradata/oracle11g/DEVOPSROLES/DATA_03.dbf' SIZE 4M AUTOEXTEND OFF
LOGGING
EXTENT MANAGEMENT LOCAL;

Explanation

  • DATA: Name of the tablespace.
  • DATAFILE: Specifies multiple datafiles with their respective sizes.
  • AUTOEXTEND OFF: Disables auto-extension for these datafiles.
  • LOGGING: Enables logging for the tablespace.
  • EXTENT MANAGEMENT LOCAL: Manages extents locally.

Conclusion

In this tutorial, we covered how to create permanent and temporary tablespaces in Oracle, as well as how to create a tablespace with multiple datafiles. Understanding these processes is essential for effective database management and optimization. For further topics, such as “Install Oracle Database 12c on Centos 7,” keep following our page! Thank you for reading the DevopsRoles page!