Saturday, September 12, 2015

To create and add Swap file in Ubuntu Linux after installation

What is a swap file on Ubuntu server or desktop system?

As a sysadmin it is necessary to add more swap space after installation on the server. Swap file allows Ubuntu Linux to use hard disk to increase virtual memory.
Virtual Memory = RAM + Swap space/file
Virtual Memory (1GB) = Actual RAM (512MB) + Swap space/file (512MB)
When the Ubuntu server runs low on memory, it swaps a section of RAM (say an idle program like foo) onto the hard disk (swap space) to free up memory for other programs. Then when you need that program (say foo again), kernel swapped out foo program, it changes places with another program in RAM.

Procedure to add a swap file on a Ubuntu Linux

Open the Terminal app or use the ssh client to get into the remote server. Login as a root user using sudo command:
 
sudo -s
 

Create a swap file command

Type the following command to create a 2GB swap file on Ubuntu:# dd if=/dev/zero of=/swapfile bs=1G count=2
Sample outputs:
2+0 records in
2+0 records out
2147483648 bytes (2.1 GB) copied, 20.2256 s, 106 MB/s
Verify that file has been created on the server:# ls -lh /swapfile
Sample outputs:
-rw-r--r-- 1 root root 2.0G Oct 29 14:07 /swapfile

Creating swap space using fallocate command instead of dd command

Instead of the dd command, you can use the the faster fallocate command to create swap file as follows:# fallocate -l 1G /swapfile-1
# ls -lh /swapfile-1

Sample outputs:
-rw-r--r-- 1 root root 1.0G Oct 29 14:11 /swapfile-1

Secure the swap file

Type the following chmod command and chown command to secure and set correct file permission for security reasons:# chown root:root /swapfile
# chmod 0600 /swapfile
# ls -lh /swapfile

Sample outputs:
-rw------- 1 root root 2.0G Oct 29 14:07 /swapfile
A world-readable swap file is a huge local vulnerability. The above commands make sure only root user can read and write to the file.

Turn on the swap file

First, use the mkswap command as follows to enable the swap space on Ubuntu:# mkswap /swapfile
Sample outputs:
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=10231c61-6e55-4dd3-8324-9e2a892e7137
Finally, activate the swap file, enter:# swapon /swapfile

Verify new swap file and settings on Ubuntu

Type the following command# swapon -s
Sample outputs:
Filename    Type  Size Used Priority
/dev/sda5                               partition 3998716 704 -1
/swapfile                               file  2097148 0 -2
You can also run the following commands to verify swap file and its usage:# grep -i --color swap /proc/meminfo
# top
# htop
# atop

How can I disable swapfile on Ubuntu?

You need to use the swapoff command as follows:# swapoff /swapfile
# swapon -s

Update /etc/fstab file

You need to make sure the swap file enabled when server comes on line after the reboot. Edit /etc/fstab file, enter:# vi /etc/fstab
Append the following line:
/swapfile none            swap    sw              0       0
Save and close the file.

Tuning the swap file i.e. tuning virtual memory

You can tune the following two settings:
  1. swappiness
  2. min_free_kbytes
  3. vfs_cache_pressure

How do I set swappiness on a Ubuntu server?

The syntax is:# sysctl vm.swappiness=VALUE
# sysctl vm.swappiness=20

OR
# echo VALUE > /proc/sys/vm/swappiness
# echo 30 > /proc/sys/vm/swappiness

The value in /proc/sys/vm/swappiness file controls how aggressively the kernel will swap memory pages. Higher values increase agressiveness, lower values descrease aggressiveness. The default value is 60. To make changes permanent add the following line to/etc/sysctl.conf:
 
echo 'vm.swappiness=30' >> /etc/sysctl.conf
 
For database server such as Oracle or MySQL I suggest you set a swappiness value of 10. 

Sunday, August 23, 2015

To install subversion client in ubuntu

To install subversion client in ubuntu

  1. Install the subversion commandline tool using sudo apt-get install subversion.
  2. Use the client by typing the command svn command [options] [args].
  3. Do not do anything else. The server will not start and you can happily use the client without the server. You will also not have GUI access.
The subversion package
includes the Subversion client (svn), repository administration tools (svnadmin, svnlook) and a network server (svnserve).
Installing the whole packages (including both server and client) might seem like a lot of overhead, but it is the most easily maintainable solution. You easily get future updates, security releases and more. Also if ever one of your users desperately needs a subversion server, it is only a few commands away.
Use svn --version for the modules included:
* ra_neon : Module for accessing a repository via WebDAV protocol using Neon.
  - handles 'http' scheme
  - handles 'https' scheme
* ra_svn : Module for accessing a repository using the svn network protocol.
  - with Cyrus SASL authentication
  - handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
  - handles 'file' scheme
* ra_serf : Module for accessing a repository via WebDAV protocol using serf.
  - handles 'http' scheme
  - handles 'https' scheme
and use svn --help for more information. The available commands illustrate that the subversion package is the way to go.
   add
   blame (praise, annotate, ann)
   cat
   changelist (cl)
   checkout (co)
   cleanup
   ...

Sunday, August 16, 2015

Installing Oracle client libraries on Ubuntu

The latest RPM files can be downloaded from Oracle instant client download section.
The three minimal RPMs required are “Basic”, “SQLPlus” and the “SDK”.
In case of Ubuntu 14.04 LTS, Intel on 64-bit we will need to download the files mentioned below:
  • oracle-instantclient12.1-basic-*.x86_64.rpm
  • oracle-instantclient12.1-sqlplus-*.x86_64.rpm
  • oracle-instantclient12.1-devel-*.x86_64.rpm
Note: The asterisk (*) would be the latest version available for download.
Convert and Install
The RPM filess need to be converted from .rpm to .deb, you’ll need to use the commandline tool alien. I the tool is not already installed it needs to be installed as shown bellow:
Now convert and install the packages in this order:
Now test the client libs using the sqlplus commandline tool. Use either sqlplus or sqlplus64 depending on your platform:
Replace the connection string with the appropriate parameters.
If you get an error message “missing libaio.so.1 file”, run:
If you get an error message “sqlplus64: error while loading shared libraries: libsqlplus.so: cannot open shared object file: No such file or directory”, then you need to add it to the system library list. To do so you need to locate the Oracle liberaries path, which would be something like:
/usr/lib/oracle/12.1/client64/lib/
Now, add this path to the system library list. CREATE and ADD the line to a NEW file:
Add inside the path:
/usr/lib/oracle/12.1/client64/lib/
Run now the dynamic linker run-time bindings utility:
For any further errors or issues while trying to run sqlplus, please refer the Ubuntu help page.

Wednesday, August 5, 2015

Parameters File in Oracle

A Parameter is a key Value Pair
i.e db_block_size, db_name each contain a value in a files.

Types of parameter:

tns.ora parameter files: There are some parameters related to network. This file maps the net services to connect with network.

Listener.ora Parameter: is a file tells on which port to be connected for accessing DB.

Database parameters: its known as init.ora. It consists the parameters that required to start the database. Normally init.ora file reside with the name concating with the Site Identifier Name(SID). If the database SID is XE. then the init file name is initXE.ora. If we check this file we will get some parameters which suggest how the database will be configured.[Its like the blueprint of a home]. It contains some default parameters. But there parameters are the basic parameters must be in this file is Control File, DB_BLOCK_SIZE, DB_NAME. As this file is needed for the start of the database, we can use it as:

startup pfile=initXE.ora


We can change the name of the init.ora file for different types of requirements. Sometimes it makes confusion for multiple existence of the same file. Another problem is as this file is editable using text editor, for any unwanted mistake file may not be  updated with the correct value. Then for the corrupted file, DB wont start up properly. To get rid from such type of problem, starting from the Oracle 9i, Oracle introduces another file called SP file[System Parameter]. It may reside only one copy and another things its a binary file. And you are not able to change it manually. Only oracle can modify it. and for modifying it we next execute command for it. All the parameters are saved in a dynamic performance table named v$parameter. To get the value of a parameter, after connecting to DB through sqlplus, we can execute


desc v$parameter;

in this file we will get more than 250 parameters.

Select value from v$parameter where name='sql_trace'; || or || show parameter sql_trace


We can modify the value of parameter. And for the effecting it we can follow two steps:

alter system set sql_trace=true scope=memory;

using the above query, we are changing the parameter value until the running the database.

scope memory: until the instance will be shutdown
scope sp file: it will preserve the value in the SP file. It will be effected after restartigng the database
scope both: it will effect the change immediately in all places


In two ways we can get back after corruption of SP file. By using the unix command strings, we can get all those key value pairs those can be stored init.ora file. We can start database through it. And after that we can create SP file from it.

Whenever a database start all the non default parameter are put into a file named alert.log From that file we can check those. From that file we can create a (anyname.)ora file, and after starting using this file we can create SP fiel from the init file.

Tuesday, August 4, 2015

File system in Oracle Database

Different types of database files.

1.Parameter Files:  It tells how the instance is configured that how big the SGA. at the start up data base, it uses the parameter file for  configurations. It also tells how my Database process in the DB writer.

2. Data files: This stores all of the data of user. Such as tables, table data are being consisted by Data files. Its a operating system file. Each database must contain at least one datafile.

3. Redo log files:  Its the transaction log of database. When any operation is being performed at database, then a transaction is being created at Redo log files. Using Redo log files we can recover the Database for instance or media failure. It contains all the information for revert back of database.

4. Control Files: It tells the instance where the datafiles and redo log files exist. Instance read the control files information to locate where those files. For the importance of its role, 4 copy of control files are saved. Its called Multiplexing of control files.

5.Temp Files:  For
 the temporary requirement of some operation, instance need some temporary storage. Temp files arrange that space. i.e for order by query processing purpose, it might be needed.


6. Password Files: its used to authenticate users performing administrative [Start up/ Shut down Database]task over network.

7. Trace Files/Alert Log: There are many background process running behind the database. For various purpose to get the status of those process, we can take help of trace files. As for unexpected error or failure, trace file contain the status of those services.