Wednesday, June 13, 2012

Can I configure Amazon RDS to use UTF-8?



By default RDS uses latin1 as default character set. This can be easily modified by changing the DB Parameter Group that the RDS is assigned to. 


Try: 


rds-modify-db-parameter-group my_db_parameter_group \ --parameters="name=character_set_server, value=utf8, method=immediate" \ --parameters="name=collation_server, value=utf8_general_ci, method=immediate"


This will change RDS to use UTF-8. 


Once you do it make sure you reboot your RDS instance and verify that changes have been taken place by following below: 



rds-reboot-db-instance my_db




mysql> SHOW VARIABLES LIKE '%character_set_%';
+--------------------------+-------------------------------------------------+
| Variable_name            | VALUE                                           |
+--------------------------+-------------------------------------------------+
| character_set_client     | utf8                                            |
| character_set_connection | utf8                                            |
| character_set_database   | utf8                                            |
| character_set_filesystem | BINARY                                          |
| character_set_results    | utf8                                            |
| character_set_server     | utf8                                            |
| character_set_system     | utf8                                            |

Thursday, June 7, 2012

Issues while Executing ssh command from within Bash Script



I was trying to execute ssh command from bash script which will: 
1. Connect to the Host using ssh. 
2.  Execute the date command on it.
3.  Print the output of step 2 on screen. 
So basically I have several servers running on Amazon's EC2 and I want to actually see what's the date/time on all those servers for the reasons that I've seen some time drift on Amazon Instances. I have set up password less entry to remote host and also added host key to remote host.
Here is the code that I'm executing: 
inputfile="myfile.csv"
OLDIFS="$IFS"
IFS=","
while read IP; do
        echo "Instance $IP Date/Time is:" `ssh ubuntu@$IP date`
done < "$inputfile"
The problem is: When I execute this script it returns the date time for a few servers like sometimes 1, sometimes 2 or 4 and so on and then exits. 
After having spent hours on this problem finally I figured that ssh was consuming stdin. After adding a -n option to ssh all worked great. 
So here is how I should have actually used it: 
        echo "Instance $IP Date/Time is:" `ssh -n ubuntu@$IP date`
Easy.. Isn't It?


Wednesday, June 6, 2012

Amazon EC2 Instances Times differ Considerably



So, I'm running uBuntu instnaces on Amazon's EC2 for a time critical application. When these were first started they had the same time... But after few days there has been more than 5 minutes time difference between both the instances.


This happened because by default these instances have not been configured to update time from NTP Servers. So to get around this problem I have to either manually run the command: 



sudo ntpdate ntp.ubuntu.com

which will actually sync up the instance time with a network Time Server. 

To answer from where did the time difference came - Actually when rebooting the instance the time it took to reboot it each time got accumulated and hence resulted into a total 5 min difference in my case. So each time you reboot your instance time would get back by that amount. 

To permanently fix this problem we would need to sync up times on every restart.

Tuesday, June 5, 2012

How to remove last 3 character of a string in Bash

The below example will: 


1.  Remove/Trim last 3 characters of a string variable.
2.  It does it in one go... 


VAR = "ap-southeast-1a"
VAR=${VAR%%???}


echo $VAR


This will output: 
ap-southeast


Simple... Isn't It?

Find out how many concurrent connections Amazon RDS can support

So you have a running RDS (mysql) instance for which you want to find out:


1. Number of Concurrent connections this RDS can support. 


    From command line login to the RDS DB. 
    Now run the command: 


    show variables like '%conn%';


      This command will list down the max concurrent sessions that can be made to this RDS DB.
      This is quite useful when you want to see and tune your applications connection pools for DB. 


2. List down the current concurrent connections. 


    Try: 


    show processlist;


    This lists down various processes that are connected to this RDS currently. 

How to trim leading whitespaces from a variable in Bash

Suppose your variable is PDNS where 


PDNS=" test " then to remove leading whitespaces from it try:


PDNS="${PDNS#"${PDNS%%[![:space:]]*}"}"
echo $PDNS


This will trim the leading whitespaces.


To remove trailing whitespaces from this variable try: 


PDNS="${PDNS%"${PDNS##*[![:space:]]}"}"