Tuesday 6 December 2016

How to schedule postgresql auto vacuum in linux



Step 1: Create a .pgpass file under your home directory.


                   [root@centos6 ~]# vim .pgpass

                                localhost:5432:DB-Name:Username:Password


Step 2: Install Crond packages.  http://www.admincool.in/2016/09/how-to-scheduling-crontab-for-     backup.html

Step 3: Edit crontab


                  [root@centos6 ~]# crontab -e

                  30      10      *      *      *      /opt/PostgreSQL/9.4/bin/psql dbname=bayaTRADETest --username=dbuser -c 'VACUUM FULL VERBOSE'


Step 4: Restart crontab


                 # service crond restart


Step 5: Add crontab on startup


                # chkconfig crond on





Description


Vacuum reclaims storage occupied by dead tuples. In normal PostgreSQL operation, tuples that are deleted or obsoleted by an update are not physically removed from their table; they remain present until a Vacuum is done. Therefore it's necessary to do Vacuum periodically, especially on frequently-updated tables.


With no parameter, Vacuum processes every table in the current database that the current user has permission to vacuum. With a parameter, Vacuum processes only that table.

Plain Vacuum (without FULL) simply reclaims space and makes it available for re-use. This form of the command can operate in parallel with normal reading and writing of the table, as an exclusive lock is not obtained. However, extra space is not returned to the operating system (in most cases); it's just kept available for re-use within the same table. Vacuum FULL rewrites the entire contents of the table into a new disk file with no extra space, allowing unused space to be returned to the operating system. This form is much slower and requires an exclusive lock on each table while it is being processed.

Parameters 


FULL

Selects "full" vacuum, which can reclaim more space, but takes much longer and exclusively locks the table. This method also requires extra disk space, since it writes a new copy of the table and doesn't release the old copy until the operation is complete. Usually this should only be used when a significant amount of space needs to be reclaimed from within the table.

FREEZE

Selects aggressive "freezing" of tuples. Specifying FREEZE is equivalent to performing Vacuum with the vacuum_freeze_min_age parameter set to zero.

VERBOSE

Prints a detailed vacuum activity report for each table.

ANALYZE

Updates statistics used by the planner to determine the most efficient way to execute a query.

table

The name (optionally schema-qualified) of a specific table to vacuum. Defaults to all tables in the current database.

column

The name of a specific column to analyze. Defaults to all columns. If a column list is specified, ANALYZE is implied.


PostgreSQL Vacuum graphically 

Step 1: Right click on database and select maintenance. It will open a pop up window.

Step 2: Select maintenance operation as VACUUM.

Step 3: Select VACUUM option as FULL

Step 4: Click OK










How to schedule postgresql auto backup in linux


Step 1: Create a .pgpass file under your home directory.

                   [root@centos6 ~]# vim .pgpass

                                localhost:5432:DB-Name:Username:Password


Step 2: Install Crond packages.  http://www.admincool.in/2016/09/how-to-scheduling-crontab-for-     backup.html


Step3: Edit crontab


                  [root@centos6 ~]# crontab -e

                  30      10      *      *      *      /opt/PostgreSQL/9.4/bin/pg_dump -U username --format=c --file=/postgres-backup/dbname.backup dbname


The backup of database will scheduled every day at 10.30 AM under 'postgres-backup' directory.


Step 4: Restart crontab


                 # service crond restart


Step 5: Add crontab on startup


                # chkconfig crond on



Synopsis

pg_dump [connection-option...] [option...] [dbname]

Description


pg_dump is a utility for backing up a PostgreSQL database. It makes consistent backups even if the database is being used concurrently. pg_dump does not block other users accessing the database (readers or writers).

Dumps can be output in script or archive file formats. Script dumps are plain-text files containing the SQL commands required to reconstruct the database to the state it was in at the time it was saved. To restore from such a script, feed it to psql. Script files can be used to reconstruct the database even on other machines and other architectures; with some modifications, even on other SQL database products.

The alternative archive file formats must be used with pg_restore to rebuild the database. They allow pg_restore to be selective about what is restored, or even to reorder the items prior to being restored. The archive file formats are designed to be portable across architectures.

When used with one of the archive file formats and combined with pg_restore, pg_dump provides a flexible archival and transfer mechanism. pg_dump can be used to backup an entire database, then pg_restore can be used to examine the archive and/or select which parts of the database are to be restored. The most flexible output file format is the "custom" format (-Fc). It allows for selection and reordering of all archived items, and is compressed by default.


Options

-U username
--username=username
User name to connect as.

-F format
--format=format
Selects the format of the output. format can be one of the following:

p
plain
Output a plain-text SQL script file (the default).

c
custom
Output a custom-format archive suitable for input into pg_restore. Together with the directory output format, this is the most flexible output format in that it allows manual selection and reordering of archived items during restore. This format is also compressed by default.

d
directory
Output a directory-format archive suitable for input into pg_restore. This will create a directory with one file for each table and blob being dumped, plus a so-called Table of Contents file describing the dumped objects in a machine-readable format that pg_restore can read. A directory format archive can be manipulated with standard Unix tools; for example, files in an uncompressed archive can be compressed with the gzip tool. This format is compressed by default.

t
tar
Output a tar-format archive suitable for input into pg_restore. The tar format is compatible with the directory format: extracting a tar-format archive produces a valid directory-format archive. However, the tar format does not support compression. Also, when using tar format the relative order of table data items cannot be changed during restore.

-i
--ignore-version
A deprecated option that is now ignored.









How to configure ftp server on centos


FTP is a file transferring protocol used to transfer form one host to another over TCP.
Package used for ftp server is vsftpd (Very Secure FTP Daemon). It is able to handle number of connections efficiently and securely. It uses port 21.

FTP server is used in wide area network. No mounting is needed. File uplod and download can be possible. FTP server offers two types of login, which are anonymous login and local user login.


Configuration


Step 1: Install vsftpd package

       [root@centos6 ~]# yum install vsftpd




Step 2: After install vsftpd package open configuration file and edit the file as following.


       [root@centos6 ~]# vim /etc/vsftpd/vsftpd.conf 

anonymous_enable=NO

local_enable=YES

write_enable=YES

chroot_local_user=YES

      Note: If 'anonymous_enable=YES', anyone can access ftp server without username and password.


Step 3: Create a folder where to store ftp data. In my case I am going to install folder under '/' directory.

       [root@centos6 /]# mkdir FTP-Share


Step 4: Create a ftp user with home directory as above created folder

       [root@centos6 /]# useradd -d /FTP-Share/alleria alleria
       [root@centos6 /]# passwd alleria





Step 5: Start the vsftpd service and add on startup

       [root@centos6 /]# service vsftpd start
       [root@centos6 /]# chkconfig vsftpd on

Step 6: Now test ftp. I created a file under user alleria's home directory.

       [root@centos6 /]# cd FTP-Share/alleria/
       [root@centos6 alleria]# touch alleria.txt






Tuesday 27 September 2016

How to find size of a directory in Linux


du is a linux command, is to display the file space allocated to each file and directory contained in the current directory. It Summarize disk usage of each FILE, recursively for directories.



                        # du    - List of directories that exist in the current directory along with their sizes.


                       # du -c   -Gives grand toal as last line of output.

                   
                       # du -s    -Displays summary of directory size.


                         # du -h   -Displays size in human readable format.









Sort Directory size in ascending order.




                         # sudo du -sh * | sort -hr








Thursday 22 September 2016

How to scheduling Crontab for backup files and directories in linux


1. Install crontab

In centos,redhat:

            # yum install cron*

2. Open crontab.

                  # crontab -e


                                field                    allowed values
                                ------------            -------------------
                                   minute                   0-59
                                   hour                       0-23
                                   day of month         1-31
                                   month                    1-12 (or names, see below)
                                   day of week           0-7 (0 or 7 is Sun, or use names)




 15      16      *       *       1       /bin/tar -czvf /Backup-Folder/Project-Folder-MON.tar.gz       /Project-Folder




The 'Project-Folder' will backup every Monday - every month - every day at 04:15 PM to 'Backup-Folder' under '/' with the name 'Project-Folder-MON.tar.gz'.


-c : Create
-z : Gzip
-v : Verbose
-f : File

3. Save the file


4. List crontab


            # crontab -l


5. Remove crontab


            # crontab -r


6. Restart crontab


            # service crond restart


7. Add crontab on startup


            # chkconfig crond on


How to schedule crontab for other users



Open crontab with username and add the scheduler and restart the service.


            # crontab -e -u username


How to deny a user from crontab



Open crontab.deny file and add the user you want to deny. save the file and restart the service.


            # vim /etc/crond.deny



Wednesday 21 September 2016

CIFS Mounting in Linux


1. Open fstab file





                #vim /etc/fstab/






2. Add the following line.


               /192.168.10.101/Projects /Project-Folder cifs username=name,password=pwd 0 0


3. Save the file.

     

How to Change JVM Heap settings of apache tomcat in Linux


1. Go to apache installation folder

                    # cd /home/apache-tomcat-8.5.4/bin/

2. Edit setenv.sh as follows

                    # vim setenv.sh

export CATALINA_OPTS="$CATALINA_OPTS -Xms1024m"
export CATALINA_OPTS="$CATALINA_OPTS -Xmx1024m"
export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=512m"

3. Save the file

4. Execute the command

                       # ./catalina.sh

How to Change JVM Heap settings of apache tomcat in Wndows

1. Open Monitor Tomcat.

2. Go to java (4th tab).

3. Change initial memory pool (-Xms) and maximum memory pool (-Xmx).

4. Click Apply and Ok.




Tuesday 20 September 2016

How to Start apache tomcat server on startup in Ubuntu,LinuxMint

1. First install the apache server.


                           http://rapidsolutions4u.blogspot.in/2016/09/install-apache-tomcat-on-linux-1.html

2. Go to init.d directory.


                                # cd /etc/init.d


3. Create and edit "tomcat.sh" file.


                                # vim tomcat.sh


    # Tomcat auto-start
    # description: Auto-starts tomcat
    # processname: tomcat
    # pidfile: /var/run/tomcat.pid

    export JAVA_HOME=jdk path


    case $1 in

    start)
            sh /home/apache-tomcat-8.5.4/bin/startup.sh
            ;;
    stop)
            sh /home/apache-tomcat-8.5.4/bin/shutdown.sh
            ;;
    restart)
            sh /home/apache-tomcat-8.5.4/bin/shutdown.sh
            sh /home/apache-tomcat-8.5.4/bin/startup.sh
            ;;
    esac
    exit 0


4. Save the file.

5. Set permission to created file.

                               # sudo chmod 755 /etc/init.d/tomcat

6. Create links


                               # sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat
                              # sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat


7. Restart tomcat service.



                             # /etc/init.d/tomcat restart



8. Similarly stop and restart tomcat service.




Monday 19 September 2016

How to Start apache tomcat server on startup in Centos,Redhat


1. First install the apache server.


                           http://rapidsolutions4u.blogspot.in/2016/09/install-apache-tomcat-on-linux-1.html

2. Go to init.d directory.


                                # cd /etc/init.d


3. Create and edit "tomcat.sh" file.


                                # vim tomcat.sh


#!/bin/bash  
# description: Tomcat Start Stop Restart  
# processname: tomcat  
# chkconfig: 234 20 80  
JAVA_HOME=jdk path 
export JAVA_HOME  
PATH=$JAVA_HOME/bin:$PATH  
export PATH  
CATALINA_HOME=apache path  
 
case $1 in  
start)  
sh $CATALINA_HOME/bin/startup.sh  
;;   
stop)     
sh $CATALINA_HOME/bin/shutdown.sh  
;;   
restart)  
sh $CATALINA_HOME/bin/shutdown.sh  
sh $CATALINA_HOME/bin/startup.sh  
;;   
esac      
exit 0


4. Save the file.

5. Set permission to created file.

                               #  chmod 755 tomcat

6. Add on startup


                               # chkconfig --add tomcat
                               # chkconfig --level 35 tomcat on


7. Start tomcat service.



                             /etc/init.d/tomcat on


8. Similarly stop and restart tomcat service.



How to install apache tomcat on Linux


Apache Tomcat is an opensource web server that is developed by Apache software foundation.
It is bascically used for deploying java web application. It is run on port 8080.


1. Download jdk-version.tar.gz from


                 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html


2. Extract the downloaded jdk.


                   # tar -xzf jdk-version.tar.gz


3. Set environmental variable.


                    Edit vim .bash_profile  --->  export PATH=(path of jdk bin):$PATH  (in centos,redhat....) 
           Edit vim .profile           --->  export PATH=(path of jdk bin):$PATH  (in ubuntu,mint....)


4. Download and Extract Tomcat Archive  http://tomcat.apache.org/


                     # tar -xzf apache-tomcat-(version).tar.gz



Tar is a linux command used to create or extract .tar.gz file formats. Tar stands for tape archive. It is an archiving file format.

Tar synopsis


                       tar <operation> [options]

Operations:


[-]A --catenate --concatenate
[-]c --create
[-]d --diff --compare
[-]r --append
[-]t --list
[-]u --update
[-]x --extract --get
--delete

Common Options:


-C, --directory DIR
-f, --file F
-j, --bzip2
-p, --preserve-permissions
-v, --verbose

-z, --gzip




5. Start Tomcat


            # cd /apache-tomcat-(version)/bin/
            # ./startup.sh


6. Access Tomcat in Browser


             http://localhost:8080/


7. Stop Tomcat


            # cd /apache-tomcat-(version)/bin/
            # ./shutdown.sh


8. Setup User Accounts


             Edit "conf/tomcat-users.xml" file and paste inside <tomcat-users> </tomcat-users> tags.


<role rolename="manager-gui" />
<user username="manager" password="YOUR_PASSWORD_" roles="manager-gui" />



11. Restart the tomcat server




How to Install apache tomcat on Windows


Apache Tomcat is a opensource web server that is developed by Apache software foundation.
It is bascically used for deploying java web application. It is run on port 8080.


1. Download apache tomcat from


                                    http://tomcat.apache.org/


2. Install apache-tomcat-(version).exe