0% found this document useful (0 votes)
17 views4 pages

Essential Oracle Commands Guide

The document provides a comprehensive guide on using Oracle commands for database management, including creating a new schema/user, granting rights, and exporting/importing data. It outlines the steps to create tablespaces, users, and how to manage user permissions, as well as commands for exporting and importing schemas and entire databases. Additionally, it includes useful SQL queries to check users and tables within the Oracle database.

Uploaded by

myasirm8993
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

Essential Oracle Commands Guide

The document provides a comprehensive guide on using Oracle commands for database management, including creating a new schema/user, granting rights, and exporting/importing data. It outlines the steps to create tablespaces, users, and how to manage user permissions, as well as commands for exporting and importing schemas and entire databases. Additionally, it includes useful SQL queries to check users and tables within the Oracle database.

Uploaded by

myasirm8993
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Oracle Commands:

=================

1. Go to Command Prompt
2. write: sqlplus and enter
3. enter user id & password of system as: system/system123@orcl

Note:
system is oracle main user
system123 is system password (it can be vary in different installations)
@orcl is the SID or Service Name (this can be vary in different installations,
mostly it is orcl)

===================================================================================
=================
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxx
===================================================================================
=================

Create a new schema/user:


===========================

1. create a tablespace first:


------------------------------

CREATE TABLESPACE tbs_Prism


DATAFILE 'datafile_Prism.dbf'
SIZE 10M AUTOEXTEND ON;

Note:
tbs_Prism is the tablespace name, you can put any name for each schema or keep the
same for all, default tablespace in oracle is Users
As you create a new tablespace so you have to create a new datafile with .dbf
extension
Size is initial size of db, autoextend On means it will grow with data. if not
given, it keeps the db file size to 10 MB (as given here) and then stop saving data
when reached to its size.

-----------------------------------------------------------------------------------
--

2. create a user in this tablespace:


-------------------------------------
CREATE USER PrismERP IDENTIFIED BY password
DEFAULT TABLESPACE tbs_Prism
TEMPORARY TABLESPACE temp;

Note:
PrismERP is the user / schema name
Identified by - refer to password i.e password here: Password in oracle is case
sensitive
given tablespace that created above
with temporary tablespace for transaction purpose.
-----------------------------------------------------------------------------------
--

3. Give rights to user/schema:


-------------------------------

grant dba to PrismERP;

Note: this gives the full dba rights to user PrismERP;


you can give more specific rights (not mandatory, but given if required) as well,
given below:

grant resource, create session, create view to PrismERP;


grant create user, alter any triger to PrismERP;
grant resource to PrismERP with Admin Option;

-----------------------------------------------------------------------------------
--

4. Drop or Delete a User / Schema:


----------------------------------

drop user PrismERP cascade;

Note: this will delete the user from Oracle, memory and from oracle recycle bin too
drop user required when you have no need of schema or import a new backup / dump
file on the same user/schema.

===================================================================================
=================
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxx
===================================================================================
=================

Export (make a backup) file from Oracle:


====================================================

1. Create a directory at C or D - Drive with any name, like "Dump"

2. write the following commands in the above open command prompt / sqlplus:

CREATE OR REPLACE DIRECTORY dump AS 'C:\Dump';

GRANT READ, WRITE ON DIRECTORY dump TO PrismERP;

3. Open a new command prompt and enter the following command:

expdp system/system123@orcl schemas=PrismERP directory=Dump dumpfile=[Link]


logfile=[Link]

Note:
expdp = export data pump command
system/system123@orcl = system user and password with service / SID name (i.e full
qualified name)
schemas=PrismERP == the schema / user want to export
directory=Dump == the directory created above
dumfile= [Link] (mostly keep the same name as schema, with extension .dmp)
logfile= [Link] (this to check the events, logs while running export command)

Import (from a dump) file to Oracle:


====================================================

To import a dump file into a user

-- if already created and have data, drop it first


--> Follow the "Create a new schema/user"

if already created but blank, start from here:

impdp PrismERP/password@orcl schemas=PrismERP directory=Dump dumpfile=[Link]


logfile=[Link]

Note: in case if importing from a different schema, and into a different tablespace
use the following command:

impdp system/system123@orcl SCHEMAS=PrismERP remap_schema=PrismERP:PrismNew


remap_tablespace=users:tbs_Prism directory=dump dumpfile=[Link]
logfile=[Link]

===================================================================================
=================
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxx
===================================================================================
=================

Other useful commands in Oracle:


================================

To check all users in oracle:

select * from dba_users;

===================================================================================
=================

To select specific user:


========================

select username from dba_users;

Note: username replace with any user name like PrismERP

===================================================================================
=================

To select / show all tables in a user/schema:


==============================================

SELECT
table_name, owner
FROM
all_tables
WHERE
owner='PrismERP'
ORDER BY
owner, table_name

------------------------------------

SELECT TABLE_NAME
FROM ALL_TABLES
WHERE OWNER='PrismERP'

------------------------------------

connect PrismERP/password;
select table_name from user_tables;

Note: this command use when connected to a schema, like PrismERP

===================================================================================
=================
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxx
===================================================================================
=================

To Database Exports/Imports instead of a user/schema:


=====================================================
Note: A database can contain many users/schema like PrismERP, PrismNew, abc,
xyz ....

To Export:
----------
expdp system/system123@orcl full=Y directory=Dump_DB dumpfile=[Link]
logfile=[Link]

To Import:
----------
impdp system/password@db10g full=Y directory=Dump_DB dumpfile=[Link]
logfile=[Link]

===================================================================================
=================
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxx
===================================================================================
=================

Common questions

Powered by AI

Remapping schemas and tablespaces during the import process is necessary when the target environment has different schema names or tablespace configurations. The command `impdp system/system123@orcl SCHEMAS=PrismERP remap_schema=PrismERP:PrismNew remap_tablespace=users:tbs_Prism directory=dump dumpfile=PrismERP.dmp logfile=impdpPrismNew.log` enables this by mapping the source schema and tablespace to new ones in the target environment, ensuring compatibility and avoiding conflicts with existing setups. It's vital in maintaining data integrity and accommodating differences in database environments .

Selective user-specific export operations are crucial for scenarios where only particular user/schema data needs to be backed up or moved without affecting the entire database system. The command `expdp system/system123@orcl schemas=PrismERP directory=Dump dumpfile=PrismERP.dmp logfile=expdpPrismERP.log` is executed for such purposes, targeting the specific user's data only. This minimizes resource utilization and processing time, making it efficient for user-centric data management tasks .

The 'full=Y' parameter in Data Pump utility commands specifies a full database export/import operation, meaning all objects within the database are exported or imported. In contrast, the 'schemas=' parameter, such as in `expdp system/system123@orcl schemas=PrismERP...`, targets specific schemas only. This distinction allows for tailored export/import operations depending on whether the intention is to manage specific user data or handle the complete state of a database system .

When creating a new user in Oracle, specifying a temporary tablespace, such as in `CREATE USER PrismERP... TEMPORARY TABLESPACE temp;`, is critical for managing temporary data generated during sort operations and SQL execution processes. This helps in optimizing database performance by providing a separate space for intermediate calculations, thus reducing contention among users for space resources .

Exporting schema data in Oracle involves creating a directory for data storage, granting write permissions, and running the Data Pump Export command, such as `expdp system/system123@orcl schemas=PrismERP directory=Dump dumpfile=PrismERP.dmp logfile=expdpPrismERP.log`. This process is crucial for backups or transferring data between environments. Importing is achieved with the Data Pump Import command `impdp PrismERP/password@orcl schemas=PrismERP directory=Dump dumpfile=PrismERP.dmp logfile=impdpPrismERP.log`. Rationale includes data preservation, migration, or auditing purposes .

Using 'AUTOEXTEND ON' while creating a tablespace, as in `CREATE TABLESPACE tbs_Prism DATAFILE 'datafile_Prism.dbf' SIZE 10M AUTOEXTEND ON;`, allows the tablespace to automatically increase in size as data is added. This feature prevents possible disruptions due to insufficient storage space, aiding in smoother database operations. However, it can lead to unexpected disk space consumption growth and could result in performance issues if not monitored .

To create a new user with custom tablespace in Oracle, first create a tablespace using the command `CREATE TABLESPACE tbs_Prism DATAFILE 'datafile_Prism.dbf' SIZE 10M AUTOEXTEND ON;`. This command specifies the tablespace name (tbs_Prism), its datafile name ('datafile_Prism.dbf'), initial size (10MB), and enables autoextension. Next, create the user with `CREATE USER PrismERP IDENTIFIED BY password DEFAULT TABLESPACE tbs_Prism TEMPORARY TABLESPACE temp;` which assigns the user to the created tablespace and specifies a temporary tablespace for transaction handling .

A drop user operation, executed with `drop user PrismERP cascade;`, should be considered when a user's schema is no longer required, or a fresh setup from a backup is intended. Precautions include ensuring no critical data is lost by preferring to back up any valuable information before proceeding and confirming there are no active dependencies or sessions that might be negatively impacted by the user's removal .

Granting the DBA role in Oracle provides comprehensive privileges across the database, including user management, resource allocation, and schema operations. This can be done with `grant dba to PrismERP;`. However, it's often safer to grant more specific permissions, such as `grant resource, create session, create view to PrismERP;`, to minimize security risks and limit user actions to necessary operations. The implication of assigning the DBA role is that the user gains control over the whole database system, requiring careful consideration of trust and security management .

To monitor all users and their privileges periodically in Oracle, commands such as `select * from dba_users;` can be used to list all users. Additionally, querying the `dba_tab_privs` and `dba_sys_privs` provides insights into object and system privileges granted to users. Automating these queries with scheduled jobs and scripts can provide regular snapshots of user privileges, aiding in security audits and compliance checks .

You might also like