Useful shortcuts for vi editor

Monday, 13 October 2014

How to know system date in Oracle?

Please run that SQL in your editor's SQL window.

select sysdate from dual;

How to connect linux machine with XStart -interface?

If you have XManager tool, you can easily connect to linux machine like Windows machines.

Firstly, change runlevel in /etc/inittab as follow;
Id:3:initdefault;
Then, reboot the machine.

After that please follow the steps:

Open XStart-> Click New and input a session name 
-> Input IP into Host, select SSH protocol and username/password 
-> Then select execution command like "/usr/bin/gnome-session --display $DISPLAY"
-> Click Run button -> Lastly, you should see the linux window

or

Open XShell-> Connect and login to machine with ssh 
-> Input IP into Host, select SSH protocol and username/password 
-> Then run this command "/usr/bin/gnome-session --display $DISPLAY"
-> Lastly, you should see the linux window

How to check ports in Linux machines?

Please run the command as linux system user.

For example, you want to check .80 port
# netstat -anp | grep :80
or
# netstat -tulpn | grep :80

How to see last updated (DDL) table object in Oracle?

Please run below sql script as desired database user;

SQL> select * from all_objects order by last_ddl_time desc;

How to use Java binary for all linux system users?

To execute java binary (bin) for all users, please run these commands below;

sudo ln -s -v /opt/jdk1.7/bin/java /usr/bin/java
sudo ln -s -v /opt/jdk/bin/javac /usr/bin/javac
              <target_name>      <sembolic-file_name>

<target_name> ; java installation directory
<sembolic-file_name> ; binary directory of all users

How to see PGA size per oracle session?

Please execute following SQL lines as "sys";

select
    1048576+a.value+b.value   pga_size
from
   v$parameter a,
   v$parameter b
where
   a.name = 'sort_area_size'
and
   b.name = 'hash_area_size';

How to set SHMMAX value and what is that?

Setting the kernel.shmmax parameter does not reserve or allocate any shared memory. SHMMAX is a safeguard parameter that sets the upper limit for a process can allocate how much shared memory when requested.

Please execute following commands as “root”;
sysctl -w kernel.shmmax=2147483648
(2147483648 -> 2 GB)

or
modify /etc/sysctl.conf file

sysctl -p
(to apply it)

How to see process that used memory or CPU at most?

Please run the command as linux system user.

# top
at manual -> shift + f and then n (mem) or k (cpu)

to highlight the column: press b

to sort by time: press shift + t

to see all CPUs: press 1

to get the different graphical output: press t

Note: Type and press enter bold ones to run

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;