Sunday, December 9, 2012

common create table command in different database

Lets see how a customer table is created in different database

In Oracle:

         create table customer
         (
         cust_id number,
         cust_name varchar2(200),
         cust_gender char(1),
         registration_date date,
         );

In MySQL:
         create table customer
         (
         cust_id int,
         cust_name varchar(200),
         cust_gender char(1),
         registration_date datetime,
         );

In MSSQL:

         create table customer
         (
         cust_id int,
         cust_name varchar(200),
         cust_gender char(1),
         registration_date datetime,
         );

In PostgreSQL:

         create table customer
         (
         cust_id int8, [or cust_id integer]
         cust_name varchar(200),
         cust_gender char(1),
         registration_date date,
         );

postgresql database performance

Most of our work will be related to postgresql.conf file during our tour of performance tuning.
So first of all you have to backup the postgresql.conf file. There are hundreds of parameters in
postgresql.conf file. Most of the website regarding performance tuning focus on the following.

Summary:
1. shared_buffers [related to buffer cache]
           i.Should be set to 25% of the system memory on Unix and Linux system
          ii.Larger settings for shared_buffers usually require a corresponding
              increase in checkpoint_segment
         iii.We may need to configure the linux kernel
2. work_mem [related to sort]
         i. Should be set  between 4MB to 64MB
        ii. For 100 concurrent connections, it can be 10MB         
3. maintenance_work_mem [related to regular maintenance index, vacuuming]
        i. should be set to 5% of the system memory
       ii. but not more then 500MB.
4. effective_cache_size [related to query planner/optimizer]
        i. should be set 50%-75% of physical memory
5. wal_buffers [related to transaction commit]
        i. should be set to 1MB to 16MB
       ii. but larger values can result in extra fsync calls or to request more System V shared memory
6. Tuning Checkpoint Parameters [if needed]
        i. checkpoint_segments [related to bulk data load]
       ii. can be set to 30
        -> checkpoint_completion_target: Once you've increased this parameter,
            it also makes sense to
            increase checkpoint_completion_target to 0.9
        -> checkpoint_timeout: 5 min to 15 min
7. synchronous_commit [related to commit]
             i.  set to off for best performance
8. random_page_cost and seq_page_cost[related to control the planner's estimate]                    
              i. if your database is significantly larger than physical memory,
                 you might want to try setting these parameters to 2 and 1
             ii. Never set random_page_cost less than seq_page_cost,
                 but consider setting them equal (or very close to equal)

Othes :
     1. Use a current version
     2. ANALYZE database so that postgres keeps statistics about database to execute queries correctly
     3. Run VACUUM on database tables frequently
     4. EXPLAIN ANALYZE your slow statements

To Configure the linux kernel

    1. http://www.postgresql.org/docs/8.4/static/kernel-resources.html

    2. http://spinroot.com/spin/multicore/setup.html

    3. http://www.depesz.com/2012/07/12/waiting-for-9-3-dramatically-reduce-system-v-shared-memory-consumption/

Remarks: sample query to test :

      select count(emailaddress) from (
      select length(emailaddress),emailaddress from companies
      where emailaddress in (select emailaddress from emailcustomers)
      and   heading in (select heading from adminheadings)
      group by emailaddress
      having length(emailaddress)>5
      )a;

      In a PC with 2GB RAM this query takes 33603.661ms without changing the parameters.
      But after changing the parameters that takes only 5751.443 ms.
      So the performance is increased by five times.
   
   
source :  http://www.postgresql.org/docs/8.4/static/runtime-config-resource.html
      http://www.linux.com/learn/tutorials/394523-configuring-postgresql-for-pretty-good-performance
      http://www.westnet.com/~gsmith/content/postgresql/pg-5minute.htm
      http://www.revsys.com/writings/postgresql-performance.html
      http://linuxfinances.info/info/quickstart.html
      http://www.varlena.com/GeneralBits/Tidbits/perf.html

git tutorial

start of  tested the test tutorial of the site
A. Install and configure git in your PC

1. Install gitk and git-core from Synaptic Package Manager.
2. Create a free account in https://github.com.
          Set your username cention-[Your First Name]-[Your Last Name]. For example my username is cention-madhuri-debnath.
          Set your emailaddress as your cention webmail account email address
          Set your password as cention webmail account password
3. Run the following command:
         $ git config --global user.email "your email address"
         $ git config --global user.name "your user name"
4. Generate SSH key for github by following the instructions from the link
         http://help.github.com/linux-set-up-git/
      $ cd ~/.ssh
      $ ls
      $ ssh-keygen -t rsa -C "abul_bashar@cention.se"
      $ only Enter
      $ only Enter
      $ ls -l
      $ ctrl+h -> open in editor 'id_rsa.pub' -> copy all -> paste to
  'https://github.com/settings/ssh' SSH keys + title=cention mail
      $ ssh -T git@github.com

B. GIT commands

1. to initialized empty Git repository in /.git/ 
   $ git init

2. To see git status
   $ git statu­s

3. to add a new file
   $ git add octoc­at.txt
   3.1. to add file of similar type
    $ git add '*.tx­t'

4. to commit the change
   $ git commi­t -m "Add cute octoc­at story­"

5. to download or synchronize pc with the server copy
   $ git pull
   5.1  to download the repository
    $git pull git@github.com:cention-assad-zaman/gittestingrepo.git

6. to up the file in the server
   $ git push
   $ git push --all
   $ git push orgin master

7. Push an existing repository from the command line
   $ git remote add origin git@github.com:cention-assad-zaman/gittestingrepo.git
   $ git push -u origin master

8. steps to add new branch in the server
   8.1     create branch as of origin
    $ git checkout -tb feature-add-email-tracking origin/master
   8.2     to add the new files
    $ git add modules/cention_workflow/outbound.osm
   8.2  to commit the new files
        $ git commit -m "feature outbound.osm link tracking for email campaign"
   8.3  to update the server with the change
        $ git push origin feature-add-outboundosm-link-tracking-email-campaign

9. to see git the branches
   $ git branch
   9.1 to see all git branches
       $ git branch -a :: to see all branches

10. to remove a file from being commited or to change the branch
    $ git checkout filename or brachname

11. to clone a repository
    $git clone -o origin git@github.com:cention-assad-zaman/gittestingrepo.git   
       
       

Linux / ubuntu commands

1. To navigate to the root directory  $ cd /

2. To navigate to the home directory  $ cd or $ cd ~

3. To see the file or folder listing  $ ls 

4. To delete files $ rm file_name  
   To delete directory $ rm ­R
5. To make directory $ mkdir new_dir

6. To display file system disk space $ df -­h

7. To display amount of free and used space in RAM $ free ­m

8. System network interface $ ifconfig

9. To add group $ addgroup newgroup 

10. Add user $ adduser new_user

11. To assign password $ passwd

12. Add user assad to new group $ adduser assad newgroup

13. To get Information $ info 

14. To escape editor Press 'q' / Press Esc, :+wq = write quie write quie / :q = quit Exit, if no change

15. Change directory or file mode $ chmod xxx file_name
    X=4: for read only.
    X=2: for write only.
    X=1: for execute only.
16. To change group attribute of a file or directory $ chgrp group_name file_name 

17. Install software in ubuntusudo $ apt­get install software_name
   
18. Clear the terminal $ clear

19. To display the name of your current directory $ pwd

20. To view process currently running $ ps aux

21. Commant to start the service $ start 

22. stop Commant to stop the service

23. To lock user account $ sudo passwd ­l user_name
    To unlock user account $ sudo passwd ­u user_name

24. To enable root directory $ sodo passwd root

25. To create a file named filename1 $ touch filename1

26. Display date $ date 
    Display date in s $ date +"%H:%M:%S"
    Display calender $ cal

27. Display current user $ whoami 

28. Display system information $ uname

29. Logged on information $ who 

30. For how long the system has been running $ uptime 

41. To display text $ echo 'text display'
42. To see the path $ whereis bash
                    $locate
43. To display standard path $ which wesnoth

44. Used to concentrate more than one files $ cat /etc/mtab

45. Text editor mode $less /etc/mtab 

46. Super user $ sudo su ­

47. Find out processes $ ps ­elf | less

48. Show system configuration $ lshw

49. Find out open ports $ netstat

40. Stop mysql $ /etc/init.d/mysql stop or service mysql stop

51. Start mysql $ /etc/init.d/mysql start or service mysql start

52. To update ubuntu $ apt­get update
    To upgrade $ apt­get upgrade

53. To rename file $ cp filename1 filename2

54. To rename folders $ mv filename1 filename2

55. Networking stop / internet stop $ sudo /etc/init.d/networking stop 

56.  Networking stop / internet start $ sudo /etc/init.d/networking start

57. To copy file or folders $ cp source destination

58. Folder copy $ cp -r /data/cmail /data/assad  [cmail folder will be copied to assad folder ]

59. Folder/file move $ mv source destination

60. Secure copy [from remote pc] $ scp source destination 
    if the test folder does not exists then the file is saved as 'test' in root(/)
    scp cention@192.168.0.105:/home/cention/Documents/myth.odt /home/subarna/Desktop/assad/
    scp cention@192.168.0.105:/home/cention/Documents/myth.doc_0.odt .
    (if the destination is the default location so, . (dot) is enough as destination)

61. Remove file $ rm filename 

62 To make a shortcut $ ln -­s source destination
   e.g.$ ln -­s /home/cention/Documents/kommuninfo/portal /var/www/
  
  

Monday, August 27, 2012

Questions for Interview

Eplislon Questions for Interview:

1. Introduce yourself.

2. Tell me about your PL/SQL experience. What have you used to do the coding so far?

3. What was your responsibility there?

4. What are the projects you have worked with so far?

5. What is the longest Package you have written so far? How many lines did it consist of? What was the logic
of the Package?

6. What are the procedures and functions you wrote there? Give me some of their names. Can you
remember the syntax/coding of some of the procedures and functions you constructed there? What was
the purpose/logic of those/that procedure and the function?

7. Suppose, I will insert 1,000,000 rows in a table. I want my PL/SQL block to commit after inserting 1000
rows. How can I use this logic in PL/SQL?
Answer:
declare
  vcounter number:=0;
begin
   for i in 1..1000000 loop
           insert into test1 values(i);
      vcounter:= vcounter+sql%rowcount;
           if vcounter >=10000 then
                   commit;
                   vcounter:=0;
           end if;
   end loop;
end;


8. What is integrity constraint?
   Answer: integrity constraint ensures that the data in the table in database meet/confirm a defined
   set of correctness and quality.        
   What are the names of the Oracle Integrity Constraint?
   Answer: Not Null ,Primary Key ,Foreign Key ,Check ,Unique


9. What is Check Constraint?
   Answer: A check constraint allows to state a minimum requirement for the value in a column. If more complicated requirements are desired, an insert trigger must be used.
The following table allows only numbers that are between 0 and 100 in the column a;
create table ri_check_1 (
  a number check (a between 0 and 100),
  b number
);
Check constraints can be added after a table had been created:
alter table ri_check_1
  add constraint ch_b check (b > 50);
ref:http://www.adp-gmbh.ch/ora/misc/integrity_constraints.html

10. What is rollback?

11. What is View?
    What is updateable View?
    Answer: we cant do the operatons of insert delete and update is called non updatable views or read oly views
    whereas we can insert delete and update operations can done in updatable views with some conditions
    (should be derived from base table and should not contain derived columns,
    views should not contain groupby having and distinct clauses at the outer most level,
    views should include all the not null columns of the base table)
    ref.: http://www.coolinterview.com/interview/34123/
   
    Example:  create OR REPLACE view emp_dept_v as
          select ename,empno, job, dEPT.DEPTNO, DNAME
          from emp, dept
          where emp.deptno=dept.deptno

          INSERT INTO EMP_DEPT_V VALUES('N',1111,'J',11,'D')
          -- unable to insert

          CREATE OR REPLACE TRIGGER T_EMP_DEPT_V
          INSTEAD OF INSERT ON EMP_DEPT_V
          BEGIN
          INSERT INTO EMP (ename,empno, job)
          VALUES (:NEW.ename,:NEW.empno, :NEW.job);
          END;

          INSERT INTO EMP_DEPT_V VALUES('N',1111,'J',11,'D')
          --data inserted


    What is the difference between Views and Snapshots?
A snapshot is a recent copy of a table from db or in some cases, a subset of rows/cols of a table. They are used to dynamically replicate the data between distributed databases.
A snapshot is a table that contains the
    results of a query of one or more tables or views, often located on
    a remote database.    
In Oracle 9i instead of snapshot we can use meterialized views which can act as snapshot.

Diff between view & snapshot is view is not a table its a virtual table to join one or more table or to prevent access from users on complete data on table. whenever we will access the view that brings the data from tables only not from view(it wont store any kind of data).


but the snapshot itself store the query result data. usually we will use to get remote data to replicate the changes made at remote site.
http://www.geekinterview.com/question_details/20813   
Can we use View to update a table?

12. What is group by function? What is having clause? Why do we use having clause? What is the sequence
of the key words/clauses of a SQL Statement with a Group by Function? Does Having clause come after
Group by clause or before Group by clause?

13. What are the differences between Truncate, Drop and Delete? I want to Truncate 50 rows in a table
keeping the rest of the rows, give me the syntax.

14. What is Rowid?

15. What is rownum? Why do we use Top N Analysis?

16. Suppose there are duplicate rows in a table. How can we delete the duplicate rows keeping only the
distinct rows?

17. What is trigger? How many types of triggers are there? What is the syntax of creating a Trigger? How
many different triggers can be used for a table? In which type of trigger both old value and new value can
be inserted?

18. What is Cursor? How many Cursors are there? What is Implicit Cursor? What is Explicit Cursor? What are
the Cursors attributes? How do we use Cursor attributes? Write a PL/SQL block where you will use an
Explicit Cursor?

19. What is Ref Cursor? What is the use of a Ref Cursor? Write a PL/SQL block using Ref Cursor.

20. What is loop? What is the difference between For Loop and While loop? In what section of a PL/SQL block
do we use Loop? How do we use loop in a Cursor? How does a Looping works?

21. What PL/SQL block do we have? What are the differences between a Procedure and a Function? Can a
Function return more than one value? What do we have to do to make a Function return more than one
value?

22. What is %rowtype and what is %type? Which is a good % type?

23. What is Package? What is the difference between a stored procedure and a Package? What are Public

Construct and Private Construct in a Package? What are the differences between them? Suppose a

package has no compilation error but while trying to call it from the Front end, user gets a
Message, “Object not defined”. What may be the cause of the problem? How can we handle it?

24. What is Collections? What are the Collections we have?

25. What is Varray? How do you populate a Varray?

26. What are PL/SQL tables? Can we have multiple columns in a PL/SQL tables?

27. Can we handle an error in a PL/SQL block? What is an Exception? How many types of Exceptions are
there? How can we trap/handle an Exception in a PL/SQL block? Give us syntax where you will trap
an Exception in an Exception Handling section. How can we give different message to the end users in
Exceptions? How will you raise a user defined exception and handle it? How can we store the errors in an
Error_log table? What is Get_error in Oracle?

28. How can we see the last day of a month? Or, which built in Function is used to see the last day of a
month? How can we see the current date? How can we see the current time? Provide the syntax.

29. What are the differences between Unique Index and Unique Constraint? What are the differences
between Unique Index and Primary Key Constraint?

30. What are nvl and nvl2? What are the differences? Give us syntax for each.

31. What is an Errorlog table?
    Answer:
32. What is Varchar2? What is the maximum length Varchar2?
    Answer:
33. What is DBMS_OUTPUT.PUT_LINE?
    Answer:
34. What is partition? How we can use Partition? Why do we use Partition on a table?
    Answer:
35. How I can write something into a file using Oracle?
    Answer:
36. They have given us the image of five tables with some data and asked various questions on these tables.
    Answer:
CEO Questions for Interview:

37. What is your level of PL/SQL? How much do you work on PL/SQL? How much would you give yourself out of ten at PL/SQL?
    Answer:
38. What is your current responsibility at the place you are working?
    Answer:
39. What is your career goal?
    Answer:
40. What is ‘agile’?
    Answer: Agile software development is a group of software development methods based on iterative and incremental development.
    Agile is a conceptual framework generally centered on iterative and incremental delivery of working software, driven by the customer.
    Agile methods break tasks into small increments with minimal planning and do not directly involve long-term planning.
    Iterations are short time frames (timeboxes) that typically last from one to four weeks.
    Each iteration involves a cross functional team working in all functions:
    planning, requirements analysis, design, coding, unit testing, and acceptance testing.

41. Do you know any Linux shell programming?

42. Which are the blocks in PL/SQL?
    Answer: A PL/SQL Block consists of three sections:
    The Declaration section (optional).
    The Execution section (mandatory).
    The Exception (or Error) Handling section (optional).



43. What is multiple declared block?

    A block can be (recursively) nested, that is, a block can contain other blocks, which in turn can again contain other blocks asf.

    declare
      variable declarations
    begin
      sql statements

      declare
    variable declarations
      begin
    sql statements
      exception
    exception handler
      end;

      further-sql-statements

    exception
      exception handler
    end;


44. What is an Exception block? What happens when an exception takes place? What are the
boundaries of an Exception Section? Can we have multiple Exception section in a PL/SQL block?

45. What are the types of error handling? What are the differences between explicit and implicit error
handling?

46. What data type would you use for Pie?

47. What are the data types related to numbers? What is the difference between number and
integer?

48. What is float? What is the difference between float and number?

49. What is rowid? Can different tables have similar rowid?

50. What is an index? Suppose there are 15 columns in a table. Can we use index on every column
of a table? What will happen if we use index for every column of the table?

51. What is Error Processing/Trapping or Exception Handling?

52. How many types of loops do we have? How would you use Exception in a Loop?

53. How do you handle an exception a while loop and continue process?

54. Give an example of while loop.

55. What is Cursor? Why do we use a Cursor? How do we use a cursor in a PL/SQL block?

56. What is implicit Cursor? What is explicit cursor? What are the cursor attributes we have?

57. What are the differences between a For and While loop?

58. What is commit?

59. What is Substr?

60. What is the difference between function and procedure? How does a procedure return a value?
    Answer:
61. How does a function return a value? How does a function return multiple values? How does
procedure return multiple values? How can we return multiple values from a function? Like if I
want to get three different values (first_name, last_name, and age)from a function, what should I
do? Can we use out parameter in a function?
    Answer: we can but it is not a good programming practice.
62. What is varray? Can we hold multiple data in that varray?
    Answer:
63. What is trigger? Why is a trigger executed? Can we use triggers anywhere except at DML level?
    Answer:
64. How can we use triggers in insert in various ways?
    Answer:
65. What is a package?
    Answer:A package is a collection of PL/SQL elements like Cursors, Variables (scalars, records, tables, etc.) and constants,
    Exception names and pragmas for associating an error number with an exception,
    PL/SQL table and record TYPE statements,  Procedures and functions
   
    Why should we use package? What are the advantages of a package?
    Advantages of package:
      -----------------------
      A. Modularity
    - Encapsulate related constructs.

      B. Easier Application Design
    - Code and compile specification and body separately.

      C. Hiding Information
    - Only the declarations in the pacakge specification
      are visible and accessible to application.
    - Private constructs in the package body ar

Wednesday, June 6, 2012

mysql database access

web-based tool for accessing mysql database :

sudo apt-get install phpmyadmin
sudo apt-get install mysql-admin mysql-query-browser

MySQL Query Browser : sudo apt-get install mysql-query-browser

MySQL Admin UI : sudo apt-get install mysql-admin

For MySQL phpmyadmin : sudo apt-get install phpmyadmin

on browser test it :

http://localhost/phpmyadmin/

In terminal execute the command :

mysql -u root -h localhost -p

Then enter your root password and you will get the mysql prompt.

mysql>

Just for testing purpose, lets create a database. Execute the following commands -

create database test;
show databases;

Have a nice journey.

Office Activation