Activities

December 2016
M T W T F S S
« Nov    
 1234
567891011
12131415161718
19202122232425
262728293031  

How to pull single table data from full database backup file.

At some time, you would ask to restore a particular table from a full backup. So you have to follow the below steps.

1. Request backup team to provide the backup
2. Decompress the backup.
3. Move the file to target server.
4. Restore entire backup which take long time based of the volume.
5. Pull particular table backup and provide it to the requestee.

The below single line of bash command will help you to get single table backup which stored into a particular file. Here I’m going to pull the table backup of help_category from a database.

#sed -n -e '/DROP TABLE.*`help_category`/,/UNLOCK TABLES/p' /tmp/fullbackup.sql  > tabledump.sql

Note : Note : You may need to remember this activity will open a single file, sometime GB file which would harm the entire server resources and not advisable to execute this script on any Production server. Also you may need more CPU/RAM for this activity.

Collecting the JVM data for identifying the bottleneck

WE all are developing jave application for various area as it is one of the secure and non-hackle platform. So it’s consider is most secured programming platform to choose. Here One of our servers went heavily loaded and we did not find any specific reasons to happen this. At the same time observed the CPU consumed heavily and RAM is barely used . So its seems like some memory leakage or code brake happening at web server end as we did not see any load conjunction on web server end.

So we need to dig the issue by collecting the Garbage collection data to a file. Based on the information which I’d given, There are 3 basic types data that we need to identify the a root cause of a Java application.

1. Collecting the Heap dump
This is basically pull what all the data are present in the system Memory. So this would help us to identify which function/code is currently loaded in memory.

How do I take thread dump : Execute the below command

 /var/jdk/bin/jmap  -histo $(pgrep java)   > ~/heapdump_$(date +"%Y-%m-%d_%H%M").log

The above command will pull the headp dump data to a dated separated file for future reference.

2. Collecting Thread dump
This is basically used for identify the programming side libraries/functions/forms those are being used in that particular time. This will be very useful to identify the functionality fix or brakes. So we had instructed to keep this data strictly up on any application outage.

  • How to pull the Thread dump
  •  /var/jdk/bin/jstack  -l $(pgrep java)  > ~/thread_dump_$(date +"%Y-%m-%d_%H%M").log

    Note : This command will pull the backup of all the java thread currently being executed in the memory and written it as a dated file. You also need to take these logs for a period of time to understand the history of the function loaded in memory. So I used to execute this commands 3 times in one minute interval.

    3. Verifying java application is heavily used using jstat.

    There is a utility (jstat) which collect the statistics of Garbage collection data which including the gcutils (used to check the usage of heap areas, the number of GC performed, and the total accumulated time for GC operations).

    [root@web232 ~]# /var/jdk/bin/jstat -gcutil $(pgrep java) 250 700
      S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT
      0.00  76.33 100.00 100.00  38.71    133   15.991   229 1465.177 1481.168
      0.00  76.33 100.00 100.00  38.71    133   15.991   229 1465.177 1481.168
      0.00  94.96 100.00 100.00  38.71    133   15.991   229 1466.212 1482.203
      0.00 100.00 100.00 100.00  38.71    133   15.991   230 1466.212 1482.203
      0.00 100.00 100.00 100.00  38.71    133   15.991   230 1466.212 1482.203
      0.00 100.00 100.00 100.00  38.71    133   15.991   230 1466.212 1482.203
      0.00 100.00 100.00 100.00  38.71    133   15.991   230 1466.212 1482.203
      0.00 100.00 100.00 100.00  38.71    133   15.991   230 1466.212 1482.203

    The above logs showing that Old space and Eden space was fully occupied by GC cycle. So any pending GC request will be keep in queue and web server remains running in hanging states appears even though it is working correctly. The only culprit is GC collection killing the web server and keep it forzhen. So restarting webserver will help to release the GC and hence platform bring it back quickly.

    If you see Eden space (E) and Old area (O) are showing the value 100. you application was driven in poor performance and may not be working correctly. So the options are restart the web server or kill the jave process.

    How do I kill the java process.

    /bin/kill -9 $(pgrep java)​

    How to delete the PU protocol from Glassfish 3

    I have created PU protocol on Glassfish server in order to serving SSL pages forcefully. The main issue is this is the only way to redirect all the non-http requests to https. I did not find any other option for ‘SSL forcing’ in Glassfish 3 version. But here I want to get the same domain.xml file without having the PU ( port unification) protocal enabled. Becasue we enabled many other customer variables on domain.xml and wanted to move all the ssl parts under the loadbalencer (ssl offloading)

    Here is the reverse process of the activities remove PU protocol

    1. Assuming that Glassfish is installed on (/home/glassfish/bin) folder and execute the below commands.

    [root@web03 ~]# cd /var/glassfish/domains/domain1/config
    [root@web03 ~]#/home/glassfish/bin/asadmin create-protocol --securityenabled=false http-redirect
    [root@web03 ~]#/home/glassfish/bin/asadmin create-protocol-filter --protocol http-redirect --classname com.sun.grizzly.config.HttpRedirectFilter redirect-filter
    [root@web03 ~]#/home/glassfish/bin/asadmin create-protocol --securityenabled=false pu-protocol
    [root@web03 ~]#/home/glassfish/bin/asadmin create-protocol-finder --protocol pu-protocol --targetprotocol http-listener-2 --classname com.sun.grizzly.config.HttpProtocolFinder http-finder
    [root@web03 ~]#/home/glassfish/bin/asadmin create-protocol-finder --protocol pu-protocol --targetprotocol http-redirect --classname com.sun.grizzly.config.HttpProtocolFinder http-redirect
    [root@web03 ~]#/home/glassfish/bin/asadmin set configs.config.server-config.network-config.network-listeners.network-listener.http-listener-1.protocol=pu-protocol​

    MySQL : ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails

    While I’ve been working with MySQL host more frequently, I’d to drop a database due to storage space constraint. When I’m executing the drop command,it showing an error that

    "ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails"

    .

    Some strange error but not severe since MySQL database is still working.

    Solution : This is due to foreign key reference. Few of the tables in test database was linked with other table on the other database. So MySQL engine will not allow us to drop the database and throws me an exception.

    Strange !! You may need to set SET FOREIGN_KEY_CHECKS=0; and will be able to drop the database. What this command will do is, it will disable the foreign keys checks against the query we’ve been executed.

    Note : Do not keep the SET FOREIGN_KEY_CHECKS=0; in any of production server. I execute this query on off peak hours to minimize the impact and set it to enabled once after the database was removed.

    mysql> SET FOREIGN_KEY_CHECKS=0;
    Query OK, 0 rows affected (0.00 sec)
    mysql> drop database test;
    Query OK, 1 row affected (0.14 sec)

    mysql> SET FOREIGN_KEY_CHECKS=1;
    Query OK, 0 rows affected (0.00 sec)

    MySQL : How to create multiple root user (Super admin)

    I have a situation to create multiple root users for managing a large Database. I used to execute ‘ grant all *. user@localhost identified by ‘password’ ” to create super users earlier. But I realized that these users can’t alter the existing users permission set even though they can create same privilege set users.

    Knowing that this is a rare case in most of the scenario where no. of DBA are very limited. So one of my collegue found that we need to opt “with grant option” while you creating multiple super root users.

    So that you will have FULL access to MySQL user accounts. Amazon RDS service will automatically create such user when you turn out an new RDS instance. But they did not allow you to create ‘super root‘ users sadly :-(

    Solution :

    GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost' IDENTIFIED BY 'password'
    WITH GRANT OPTION;

    Mutt : Emails are not sending from user account

    Recent I had switched a script which was running from the root account to normal user account for audit purpose. But it is noticed that script is not sending email which use “mutt” commandline MUA program. I have checked email server log and nothing found useful out there. Also I noticed that email from address was changed having poor reputation ie from address showing ‘ramesh@localhost.localdomain

    The solution are,
    a. We have to create a mut profile file to set the FROM address header.

    b. We may also need to set few other variables in that file in order to send email outside. Otherwise mutt program showing in hanged state. The following values are the added to ~/.muttrc file.
    set realname=”Daily validations of invoice history”
    set use_from=yes
    set envelope_from =”yes”

    My muttrc file will looks like

    [user1@web01 ~]$ cat  ~/.muttrc
    set signature='~/.signature'
    # Customized headers
    unmy_hdr *                      # remove all extra headers first.
    set edit_headers=yes
    my_hdr From:  Exception Checker   <support@mydomain.com>
    my_hdr Reply-To: Group admins <support@mydomain.com>
    set realname="Exception Checker "
    set use_from=yes
    set envelope_from ="yes"
    [user1@web01 ~]$