Useful shortcuts for vi editor

Monday, 13 October 2014

What should you do if electricty down or reboot exists in lvm system?

For this case,
You should mount the logic volume (lv) to related path. 

For example, you are using ftp server;
Run this command after system is up:

mount /dev/my_vg_ora/vol01 /srv/ftp/myhome/​
(mount - logic volume path - mounted path)

How to see FRA (Flash Recovery Area) configuration?

Please execute the commands as "sys";

Check archive log configuration
SQL> archive log list;

Check archive log destination
SQL> show parameter db_recovery_file_dest;

Check archive log limit and left space
SQL> SELECT * FROM V$RECOVERY_FILE_DEST;

Check archive log files 
RMAN> list archivelog all;

How to add datafile as logic volume (LV) on the tablespace in Linux?

On linux terminal;
chown -R oracle:dba /dev/my_vg_ora/example01
chown -R oracle:dba /dev/mapper/my_vg_ora-example01
chmod 777 /dev/my_vg_ora
chmod 660 /dev/my_vg_ora/*

$ sqlplus
Enter user-name: sys as sysdba
@sys
to add database file please execute under query as system database role

SQL> ALTER TABLESPACE MYTABLESPACE ADD DATAFILE '/dev/my_vg_ora/example01' size 8000m reuse

To execute the command, make sure the instance is open and the tablespace is online and also check database datafiles;

SELECT * FROM dba_data_files;

How to kill session when system could not drop database user?

Please execute following commands as "sys user":

select inst_id, sid, serial# from gv$session where username = 'TEST_ALPER';
(inst_id -> instance id, sid -> service id, serial# -> serial number)

then use;

alter system kill session '44,61808,@1';
(44 -> inst_id, 61808 -> service id, @1 -> serial number)

finally drop user;

drop user TEST_ALPER cascade;

Saturday, 11 October 2014

How to select top 10 records in Oracle 11g and 12c?

In 11g:

As you now that TOP keyword does not exist in 11g, but you can use rownum keyword to query top records.

For example, you want to see top 10 salary records based on employees:

Run that SQL in your editor's SQL window.

Wrong one;
SELECT *
FROM (
 SELECT employee_id, first_name, last_name, salary
 FROM employees
 )
WHERE rownum < 11
ORDER BY salary DESC;

* ORDER BY runs at last so that it should be in sub query.

Correct one;
SELECT *
FROM (
 SELECT employee_id, first_name, last_name, salary
 FROM employees
 ORDER BY salary DESC
 )
WHERE rownum < 11;


In 12c:
With 12c, you may use special syntax to see top records that is "FETCH" syntax.

SELECT employee_id, first_name, last_name, salary
FROM employees
ORDER BY salary DESC
FETCH FIRST 10 ROWS ONLY;

Also, you may disregard first 5 records inside 10 records.

SELECT employee_id, first_name, last_name, salary

FROM employees
ORDER BY salary DESC
OFFSET 5 ROWS 
FETCH NEXT 5 ROWS ONLY;

That's all. Bye :)

Windows makineye, Fedora 20 kurulum adımları

  1. Fedora 20 DVD(.iso) dosyasını sitesinden indir.
  2. Fedora 20 DVD(.iso) hazırlamak için Infra Recorder programını indir.
  3. Programı kurup, açtıktan sonra; Write Image seçeneğinden DVD burn edilir.
  4. Hard diski formatlamak için, Run'dan mmc yazıp, çalıştırılır.
  5. Add Snap-In -> Disk Management -> OK ile disk formatlanır.
  6. BIOS ayarlarından, bilgisayarın DVD'den boot olacak şekilde ayarla.
  7. Kurulum sırasında takılma(donma) hatasını almamak için Floopy drive -> disable yapılır.
Alternatif kurulum
  1. Universal USB installer programını kullanarak .iso dosyasından Linux kurulumu yapılabilir.
  2. Program gerekli dosyaları USB belleğe attıktan sonra, \boot\bootinst.bat çalıştırılır ve bilgisayar USB'den boot edilip, işletim sistemi kurulur.
  3. Hızlı bir linux deneyimi için SLAX dağıtımını tavsiye ederim.

Kurulum sırasında çıkan sorunlar ve çözümleri

Gigabyte anakartlarında USB Boot olmama problemi ve çözümü;
  • Öncellikle, BIOS ayarındaki Legacy USB storage detect seçeneğinin enable olduğuna emin olun. (BIOS Setup Menu -DEL tuşuyla -> Integrated Peripherals -> Legacy USB storage detect -> enable)
  • Daha sonra; USB sürücünüzü HP USB Disk Storage Format Tool ile formatlayın. (Linux için FAT32 seçilmeli)
  • Alternatif kurulum bittikten sonra; PC startup zamanında F12 ile Boot Menu'ye gidin. Açılan menuden + Hard Disk seçeneğine tıklayın.
  • Son olarak; açılan listeden USB Storage yani USB cihazınızı seçin. (Örn. USB-HDD0)

Linux işletim sistemi düzgün uninstall edilmediğinde boot sırasında ortaya çıkan grub rescue sorunu ve bu sorunun kalıcı çözümü;
  • Windows live CD veya Windows kurulum DVD ile Command Prompt penceresinden bootrec /fixmbr komutu çalıştırılır. Daha sonra bilgisayar restart edilir.
Daha fazla ayrıntı için tıklayınız.

Geçici çözüm olarak BIOS'dan boot sırası değiştirilir.
  • USB flash bellek format sorunu ortaya çıkarsa şu komutlarla flash belleğe format atılır.
    - CMD > diskpart > list disk > select disk 1 (genelde bu olur) > clean > create partition primary > select partition 1 > active > assign > formatla
Daha fazla ayrıntı için tıklayınız.

How can I do watermark my pictures?

You can easily watermark your photographs or pictures with this link. It is a free and online tool.

Bye. :)

What is the SID (Service Identifier) in Oracle?

Oracle uses service (oracle service) for connecting instance database by looking to sid. You can find which service names (sid) are using in database services with this command easily.

Connection format: IP:LSTN_PORT/SID
e.g.
C:\Users\Alper> lsnrctl status


LSNRCTL for 32-bit Windows: Version 11.2.0.2.0 - Production on 11-EKI-2014 12:01:25

Copyright (c) 1991, 2010, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for 32-bit Windows: Version 11.2.0.2.0 - Production
Start Date                11-EKI-2014 11:49:12
Uptime                    0 days 0 hr. 12 min. 16 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Default Service           XE
Listener Parameter File   C:\oraclexe\app\oracle\product\11.2.0\server\network\admin\listener.ora
Listener Log File         C:\oraclexe\app\oracle\diag\tnslsnr\Alper-PC\listener\alert\log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1ipc)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=Alper-PC)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=Alper-PC)(PORT=8080))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "CLRExtProc" has 1 instance(s).
  Instance "CLRExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "PLSExtProc" has 1 instance(s).
  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "XEXDB" has 1 instance(s).
  Instance "xe", status READY, has 1 handler(s) for this service...
Service "xe" has 1 instance(s).
  Instance "xe", status READY, has 1 handler(s) for this service...
The command completed successfully

Friday, 10 October 2014

How to define a new Linux user?

# useradd -d /home/alper -g gpalper -s /bin/csh -m alper -u 1008
# passwd alper

To check it:
$ egrep -i "^alper" /etc/passwd
$ egrep -i "^gpalper " /etc/group
or
$ grep alper /etc/passwd
$ grep gpalper /etc/group

How to see that a package and a program exists in SUSE Linux ?

for package;
$ rpm –ql test_package 
or 
rpm –qa test_package

for program;
$ whereis test_program

How to resolve "Enterprise Manager Agent status is Unavailable" issue in Linux?

Please run below commands as oracle system user.
  • emctl clearstate agent 
  • emctl upload agent

[SOLUTION] ORA-28003 problem

Please execute the command as "sys";

SQL> ALTER PROFILE DEFAULT LIMIT PASSWORD_VERIFY_FUNCTION NULL;

How to see related user process in Linux?

In command window;

$ ps –u alper

(“alper”, linux system user)

[SOLUTION] ORA-00845 problem


By default /dev/shm is created to use half size of your server physical memory

If you see that MEMORY_TARGET not supported on this system​ while starting Oracle Database Instance in sqlplus window, please follow the instructions as below;

For this case, you should increase memory that using by Oracle as root user (e.g. size=10240m means 10 GB RAM)
-> umount tmpfs
-> mount -t tmpfs shmfs -o size=10240m /dev/shm

If you encounter any error like that "the system is using already", (e.g. process id of /dev/shm is "5265")
-> fuser -m /dev/shm
or
-> lsof /dev/shm
-> kill 5265

Ref: http://blog.yannickjaquier.com/linux/linux-memory-usage.html

How to change oracle max connection limits for "maximum connection exceed problem"?

$ sqlplus
Enter user-name: sys as sysdba @sys
to see parameter process for altering system sessions (processes (integer) = sessions)

SQL> show parameter session 
SQL> ALTER system SET sessions= 300 scope=spfile;
SQL> show parameter process
SQL> ALTER system SET processes= 300 scope=spfile;

Finally, restart the database to activate all changes

How to drop a user from database in Oracle?

Please login to database server with ssh as oracle user and run that commands.
  • sqlplus / as sysdba
  • SQL> DROP USER testuser CASCADE; --If testuser's schema contains objects such as tables, then you must use the CASCADE clause to drop testuser.
  • SQL> exit

How to see the size of users on specific tablespace in Oracle?

Please execute following command as "sys";

SELECT tablespace_name, owner, segment_type "Object Type",
       COUNT(owner) "Number of Objects",
       ROUND(SUM(bytes) / 1024 / 1024, 2) "Total Size in MB"
FROM   sys.dba_segments
WHERE  tablespace_name IN ('ALPERTABLESPACE')
GROUP BY tablespace_name, owner, segment_type
ORDER BY tablespace_name, owner, segment_type;

How to login sqlplus on linux command window in Linux?

$ sqlplus scott/tiger@orcl

@orc1 -> tnsnames.ora – connection node name
scott -> db username
tiger -> db username password 

$ sqlplus / as sysdba@orcl

Login as sysdba with this.

How to see tablespace usage for Oracle Database?

Please execute following commands as "sys";

select b.tablespace_name, tbs_size SizeMb, a.free_space FreeMb
 from  (select tablespace_name, round(sum(bytes)/1024/1024 ,2) as  free_space from dba_free_space
 group by tablespace_name) a,
 (select tablespace_name, sum(bytes)/1024/1024 as tbs_size
from dba_data_files
 group by tablespace_name) b
where a.tablespace_name(+)=b.tablespace_name

How to add a alias for using by all users in Linux?

Please edit /etc/bash.bashrc, for example;
  • alias c='cd' 
  • alias a='dir'
  • alias l='ls -l'
  • alias p='cd -'
  • alias '..'='cd ..'