Useful shortcuts for vi editor

Sunday, 19 October 2014

How to define and drop temporary tablespace?

Please execute the commands as "sys";

SQL> CREATE TEMPORARY TABLESPACE ALPER_TS_TEMP TEMPFILE 
 'C:\tablespaces\data_01.dbf' 
 SIZE 8000M 
 AUTOEXTEND OFF
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;

To alter the tablespace:
SQL> ALTER TABLESPACE ALPER_TS_TEMP ADD TEMPFILE 'C:\tablespaces\data_temp_new_02.dbf' size 128m;

To drop the tablespace:
SQL> DROP TABLESPACE ALPER_TS_TEMP INCLUDING CONTENTS AND DATAFILES;

Used Oracle Version and OS: Oracle XE and Win7

Ref: http://onlineappsdba.com/index.php/2008/02/08/tablespace-and-datafiles-in-oracle-database-back-to-basics/

How to run .sql file in sqlplus?

Press Windows button + R and press cmd then click "OK".

Write down "below command" and press enter

Full path approach
echo exit | sqlplus hr/hr @C:\sql\example.sql

Oracle path approach
echo exit | sqlplus hr/hr @?/example.sql
? -> $ORACLE_HOME

Example sql: select * from employees;

Used Oracle Version and OS: Oracle XE and Win7

How to change a specified string inside all files by recursively?

Only run this command in terminal;

$ find . -type f -exec sed -i 's/'old'/'new'/g' {} \;

You can also use escape character to use '/'.

$ find . -type f -exec sed -i 's/'\\/old'/'\\/new'/g' {} \;
(\\ -> escape characters)

How to connect into RMAN tool in Windows?

Press Windows button + R and press cmd then click "OK".
Write down "rman" and press enter

Lastly run that command to connect environment.

RMAN> connect target /

connected to target database: XE (DBID=2732638794)

How to login Windows machine with RDP (mstsc) even though firewall is active?

Please follow the instructions to use mstsc tool for Windows machines.

Press Windows key -> Right-clicking on Computer and select Properties -> Click Remote settings -> Enable Remote connections options -> You can connect with mstsc now!



Wednesday, 15 October 2014

How to clear screen in sqlplus?

SQL> clear screen;

How to set DB ID in RMAN?

RMAN> set dbid=111111;
-- 111111 -> desired dbid

How to see database open-mode information?

Please execute the commands as "sys";

SQL> SELECT open_mode FROM v$database;

How to see database tablespaces?

Please execute the commands as "sys";

SQL> SELECT * FROM v$tablespace;

How to see database instance information?

Please execute the commands as "sys";

SQL> SELECT * FROM v$instance;

To see db startup time:
SQL>
SELECT to_char(startup_time,'DD-MON-YYYY HH24:MI:SS') "DB Startup Time"
FROM v$instance;

How to see version of database?

Please execute the commands as "sys";

SQL> select version from v$instance;

How to see resource limits?

Please execute the commands as "sys";

SQL> SELECT * FROM v$resource_limit;

How to see all tablespace quotas?

Please execute the commands as "sys";

SQL> SELECT * FROM DBA_TS_QUOTAS;

How to see all profiles and assigned limits?

Please execute the commands as "sys";

SQL> SELECT * FROM DBA_PROFILES ORDER BY PROFILE;

How to check database link?

SQL> SELECT 1 FROM dual@mydblink

How to configure EM (Enterprose Manager) if has any problem?

On linux terminal;
set ORACLE_SID=<YOURSID>
emca -deconfig dbcontrol db -repos drop;
then;
emca -config dbcontrol db -repos create;
or
emca -config dbcontrol db -repos recreate;

Tuesday, 14 October 2014

How to delete archive log files until specific time in RMAN?

RMAN> delete archivelog until time ‘SYSDATE-10’;
i: it will delete them until 10 days ago

Also it has a no prompt option;
RMAN> delete noprompt archivelog until time ‘SYSDATE-10′;

How to check/open archive log in sqlplus?

Check in archive log open:
SQL> SELECT LOG_MODE FROM SYS.V$DATABASE;
or
SQL> archive log list;

Open achieve log mode:
SQL> startup mount;
SQL> alter database archivelog;
SQL> alter database open;

Enterprise Manager and OEM Agent commands in Oracle

Please login to database server with ssh as oracle user and run that commands.

Go to /bin path
su - grid12
cd agent/agent_inst/bin

How to start/stop Enterprise Manager
./emctl start dbconsole;
./emctl stop dbconsole;

for 12c grid EM
/home/grid12/oms/bin/emctl start oms
/home/grid12/oms/bin/emctl stop oms

How to start/stop Oem Agent
Be sure run root.sh as root user and run below commands as oracle user:
./emctl stop agent
./emctl start agent

How to check Oem Agent
./emctl status agent

How to restore Oem Agent
Run as grid12 user:
./emctl clearstate agent; and then
./emctl upload agent;

How to alter a profile in Oracle?

Please login to database server with ssh as oracle user and run that commands.

sqlplus / as sysdba

SQL> ALTER PROFILE engineer LIMIT 
SESSIONS_PER_USER 5
IDLE_TIME 60
CONNECT_TIME 1200;

SQL> exit

-- SESSIONS_PER_USER; Specify the number of concurrent sessions to which you want to limit the user.
-- IDLE_TIME; Specify the permitted periods of continuous inactive time during a session, expressed in minutes. Long-running queries and other operations are not subject to this limit.
-- CONNECT_TIME; Specify the total elapsed time limit for a session, expressed in minutes.