Showing posts with label Oracle. Show all posts
Showing posts with label Oracle. Show all posts

Thursday, November 18, 2021

Import Data Pump To Different Schema

 

impdp system/pwd schemas=ENILAI remap_schema=ENILAI:enilaidc remap_tablespace=ENILAI:enilaidc directory=dmpdir dumpfile=ENILAI11G.DMP logfile=enilaidc_20211118.log

Source schema: ENILAI
Target schema: enilaidc
Source tablespace: ENILAI
Target tablespace: enilaidc


Sunday, August 4, 2019

Export using Oracle Data Pump from 12c to 11g in windows




1) Create logical directory using SQL Plus



2) Export schema using version parameter

*You also can try without full parameter for ENILAI 12c DB.

 3) How to import using oracle data pump (impdp) – (from 12c to 11g)



Friday, March 22, 2019

Monitor Session and SQL



select * from v$session a, v$sql b where a.sql_Address = b.address and a.sql_hash_Value = b.hash_Value;

Wednesday, March 20, 2019

Monitor SGA Free Memory


select a.*, (a.BYTES/1000) as kb, (a.BYTES/1000)/1000 as mb, (a.BYTES/1000)/1000/1000 as gb
from v$SGASTAT a
where name like '%free memory%';

Wednesday, May 23, 2018

Change Oracle SYS and SYSTEM password

Lost Oracle SYS and SYSTEM password?

If your administration is as good as anybodies, you are bound to loose the not-so-frequently used password for the SYS and SYSTEM users of oracle. Here are a few ways I found to re-set those passwords:
Method 1: SQLPLUS (Tested on AIX Oracle 9.2.0.1.0)
Log into the database server as a user belonging to ‘dba’ [unix ] or ‘ora_dba’ [windows ] group , typically ‘oracle’, or an administrator on your windos machine. You are able to log into Oracle as SYS user, and change the SYSTEM password by doing the following:
$ sqlplus "/ as sysdba"
SQL*Plus: Release 9.2.0.1.0 - Production on Mon Apr 5 15:32:09 2004

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production

SQL> show user

USER is "SYS"

SQL> passw system
Changing password for system
New password:
Retype new password:
Password changed
SQL> quit

Next, we need to change the password of SYS:
$ sqlplus "/ as system"
SQL*Plus: Release 9.2.0.1.0 - Production on Mon Apr 5 15:36:45 2004

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

SP2-0306: Invalid option.
Usage: CONN[ECT] [logon] [AS {SYSDBA|SYSOPER}]
where <logon>  ::= <username>[/<password>][@<connect_string>] | /
Enter user-name: system
Enter password:

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production

SQL> passw sys
Changing password for sys
New password:
Retype new password:
Password changed
SQL> quit
You should now be able to log on the SYS and SYSTEM users, with the passwords you just typed in.
Method 2: Creating pwd file (Tested on Windows Oracle 8.1.7)
  1. Stop the Oracle service of the instance you want to change the passwords of.
  2. Find the PWD###.ora file for this instance, this is usuallly located atC:\oracle\ora81\database\, where ### is the SID of your database.
  3. rename the PWD###.ora file to PWD###.ora.bak for obvious safety reasons.
  4. Create a new pwd file by issuing the command: 
    orapwd 
    file=C:\oracle\ora81\database\PWD###.ora password=XXXXX
    where ### is the SID and XXXXX is the password you would like to use for the SYS and INTERNAL accounts.
  5. Start the Oracle service for the instance you just fixed. You should be able to get in with the SYS user and change other passwords from there.
Credit to: https://rolfje.wordpress.com/2007/01/16/lost-oracle-sys-and-system-password/

Thursday, May 3, 2018

How to Create a User and Grant Permissions



As always, begin by connecting to your server where Oracle is hosted, then connect to Oracle itself as the SYSTEM account.
The SYSTEM account is one of a handful of predefined administrative accounts generated automatically when Oracle is installed. SYSTEM is capable of most administrative tasks, but the task we’re particularly interested in is account management.

Creating a User

Once connected as SYSTEM, simply issue the CREATE USER command to generate a new account.
CREATE USER books_admin IDENTIFIED BY MyPassword;
Here we’re simply creating a books_admin account that is IDENTIFIED or authenticated by the specified password.

The Grant Statement

With our new books_admin account created, we can now begin adding privileges to the account using the GRANT statement. GRANT is a very powerful statement with many possible options, but the core functionality is to manage the privileges of both users and roles throughout the database.

Providing Roles

Typically, you’ll first want to assign privileges to the user through attaching the account to various roles, starting with the CONNECT role:
GRANT CONNECT TO books_admin;
In some cases to create a more powerful user, you may also consider adding the RESOURCE role (allowing the user to create named types for custom schemas) or even the DBA role, which allows the user to not only create custom named types but alter and destroy them as well.
GRANT CONNECT, RESOURCE, DBA TO books_admin;

Assigning Privileges

Next you’ll want to ensure the user has privileges to actually connect to the database and create a session using GRANT CREATE SESSION. We’ll also combine that with all privileges using GRANT ANY PRIVILEGES.
GRANT CREATE SESSION GRANT ANY PRIVILEGE TO books_admin;
We also need to ensure our new user has disk space allocated in the system to actually create or modify tables and data, so we’ll GRANT TABLESPACE like so:
GRANT UNLIMITED TABLESPACE TO books_admin;

Table Privileges

While not typically necessary in newer versions of Oracle, some older installations may require that you manually specify the access rights the new user has to a specific schema and database tables.
For example, if we want our books_admin user to have the ability to perform SELECTUPDATEINSERT, and DELETE capabilities on the books table, we might execute the following GRANT statement:
GRANT
  SELECT,
  INSERT,
  UPDATE,
  DELETE
ON
  schema.books
TO
  books_admin;
This ensures that books_admin can perform the four basic statements for the books table that is part of the schema schema.
Credit to: https://chartio.com/resources/tutorials/how-to-create-a-user-and-grant-permissions-in-oracle/

Show All Tablespaces



if you want to get a list of all tablespaces used in the current database instance, you can use the DBA_TABLESPACES view as shown in the following SQL script example:
SQL> connect SYSTEM/fyicenter
Connected.

SQL> SELECT TABLESPACE_NAME, STATUS, CONTENTS
  2  FROM USER_TABLESPACES;
TABLESPACE_NAME                STATUS    CONTENTS
------------------------------ --------- ---------
SYSTEM                         ONLINE    PERMANENT
UNDO                           ONLINE    UNDO
SYSAUX                         ONLINE    PERMANENT
TEMP                           ONLINE    TEMPORARY
USERS                          ONLINE    PERMANENT
SQL> select owner, table_name, tablespace_name
  2        from dba_tables
  3       where owner in ('SCOTT', 'HR')
  4       order by owner, tablespace_name, table_name;

OWNER                          TABLE_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------ ----------------
HR                             DEPARTMENTS                    USERS
HR                             EMPLOYEES                      USERS
HR                             JOBS                           USERS
HR                             JOB_HISTORY                    USERS
HR                             LOCATIONS                      USERS
HR                             REGIONS                        USERS
HR                             COUNTRIES

7 rows selected.

Sunday, April 29, 2018

Create Tablespaces



SQL> create tablespace TABLESPACENAME datafile 'E:/oraclexe/app/oracle/oradata/XE/YOURDATAFILE.DBF' size 10M autoextend on;

Drop Table and Other Objects in Schema



-- DROP TABLE
> SELECT 'DROP TABLE "' || TABLE_NAME || '" CASCADE CONSTRAINTS;' FROM user_tables;

-- DROP OTHER OBJECTS
> select 'drop '||object_type||' '|| object_name || ';' from user_objects where object_type in ('VIEW','PACKAGE','SEQUENCE', 'PROCEDURE', 'FUNCTION', 'INDEX');

Wednesday, April 25, 2018

Show All Tables



SELECT owner, table_name
  FROM dba_tables
This is assuming that you have access to the DBA_TABLES data dictionary view. If you do not have those privileges but need them, you can request that the DBA explicitly grants you privileges on that table, or, that the DBA grants you the SELECT ANY DICTIONARY privilege or the SELECT_CATALOG_ROLErole (either of which would allow you to query any data dictionary table). Of course, you may want to exclude certain schemas like SYS and SYSTEM which have large numbers of Oracle tables that you probably don't care about.
Alternatively, if you do not have access to DBA_TABLES, you can see all the tables that your account has access to through the ALL_TABLES view:
SELECT owner, table_name
  FROM all_tables
Although, that may be a subset of the tables available in the database (ALL_TABLES shows you the information for all the tables that your user has been granted access to).
If you are only concerned with the tables that you own, not those that you have access to, you could use USER_TABLES:
SELECT table_name
  FROM user_tables
Since USER_TABLES only has information about the tables that you own, it does not have an OWNERcolumn – the owner, by definition, is you.
Oracle also has a number of legacy data dictionary views-- TABDICTTABS, and CAT for example-- that could be used. In general, I would not suggest using these legacy views unless you absolutely need to backport your scripts to Oracle 6. Oracle has not changed these views in a long time so they often have problems with newer types of objects. For example, the TAB and CATviews both show information about tables that are in the user's recycle bin while the [DBA|ALL|USER]_TABLES views all filter those out. CAT also shows information about materialized view logs with a TABLE_TYPE of "TABLE" which is unlikely to be what you really want. DICTcombines tables and synonyms and doesn't tell you who owns the object.
Credit to https://stackoverflow.com/questions/205736/get-list-of-all-tables-in-oracle

Connect To A Remote Database Using SQLPlus



Here is how to connect to a remote Oracle database using SQLPlus:
sqlplus user/pass@(DESCRIPTION=(ADDRESS=(PROTOCOL=protocol)(HOST=host)(PORT=port))(CONNECT_DATA=(SID=sid)))
Please note that the words in Italics represent variables:
user – user name for the remote database
pass – password for the remote database
protocol – protocol used to connect to remote database, usually TCP
host – IP address or hostname of the remote host
port – remote port listening for database connections
sid – remote SID to connect to
Here’s an example:
sqlplus username/password@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.110.70.199)(PORT=1521))(CONNECT_DATA=(SID=xe)))

Credit to https://hecpv.wordpress.com/2015/04/29/how-to-connect-to-a-remote-oracle-database/

Oracle Database



  1. Change Oracle SYS and SYSTEM password
  2. Connect To A Remote Database Using SQLPlus
  3. Create Tablespaces
  4. Drop Tables and Other Objects in Schema
  5. Export using Oracle Data Pump from 12c to 11g in windows
  6. How clear Oracle 11g listener log on windows
  7. How to Create a User and Grant Permissions
  8. Import Data Pump To Different Schema
  9. Monitor Session and SQL
  10. Monitor SGA Free Memory
  11. Show All Tables
  12. Show All Tablespaces