Thursday, July 26, 2012

Memcache vs APC cache in PHP

I often see this question asked; which is a better caching mechanism for PHP: Memcache or APC cache. I wanted to write about how different both of them are inherently in their very concept.

Memcache for PHP is a distributed caching mechanism. If you have several webservers running under a load balancer serving the same content and you want a caching mechanism to avoid frequent database hits , Memcache is the way to go. When using Memcache you will make the update to one webserver and it would be auto-replicated across all the severs through distributed caching mechanism. Since it requires dealing with network protocols in order to support the distributed part of caching, it is slower compared to APC cache. If data is stored in APC cache, updates need to be done individually on all APC caches on all web servers. They wont be automatically replicated.

However, Memcached is NOT an Opcode cacher like APC. APC when employed will cache all the opcode the first time it is converted and serve the cached version for subsequent HTTP requests. APC can also be used to store data like Memcache but in a non-distributed manner. Most of the times memcache is used to store results of time consuming data queries, so the need to hit database on every query is eliminated and this gives a huge performance benefit.

The good part of both these technologies, is that they are compatible with each other. A good design for scalable websites should be employing APC for opcode caching and data-caching through Memcache to exploit the distributed capabilities across several webservers. If there is just a single webserver, using just APC cache for both opcode and data caching is a good idea.



http://www.4elements.com/blog/2011/07/

Tuesday, July 24, 2012

Convert MyISAM to InnoDB

This shows how to convert MyISAM to InnoDB engine from command line:


#mysql -p -e "show tables in <database_name>;" | tail --lines=+2 | xargs -i echo "ALTER TABLE {} ENGINE=INNODB;" > alter_table.sql


#mysql --database=<database_name> -p < alter_table.sql

Enable InnoDB in MySQL

For time to time searching in the internet, I finally found a solution for enabling InnoDB in MySQL.
First of all, check your MySQL database if it supports InnoDB or not:


#mysqladmin -u root -p variables |grep have_innodb
Enter password:
| have_innodb                             | NO


Try one more time:


#mysql -u root -p
mysql>show engines\g;


+------------+---------+------------------------------------------------------------+--------------+------+------------+
| Engine     | Support | Comment                                                    | Transactions | XA   | Savepoints |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| MRG_MYISAM | YES     | Collection of identical MyISAM tables                      | NO           | NO   | NO         |
| CSV        | YES     | CSV storage engine                                         | NO           | NO   | NO         |
| MyISAM     | DEFAULT | Default engine as of MySQL 3.23 with great performance     | NO           | NO   | NO         |
| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables  | NO           | NO   | NO         |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
4 rows in set (0.00 sec)



Friday, July 13, 2012

Install RADIUS plugin for PHP on CentOS 6.3

To install RADIUS plugin for PHP on CentOS 6.3, do the following:

#pear install radius Auth_RADIUS

If you get this:
"No releases available for package "pear.php.net/radius"
"No releases available for package "pear.php.net/Auth_RADIUS"

Please update pear channel:

#pear channel-update pear.php.net
Updating channel "pear.php.net"
Update of Channel "pear.php.net" succeeded


Run the command again
# pear install radius Auth_RADIUS



Tuesday, July 10, 2012

Export Import Oracle database

http://www.orafaq.com/wiki/Import_Export_FAQ



Oracle Export and Import Utilities FAQ:
NOTE: Users on Oracle 10g and later releases should use the Data Pump expdp and impdp utilities instead of the older imp and exp utilities described in this document.
Contents [hide] 
1 What is import/export and why does one need it?
2 How does one use the import/export utilities?
3 Can one export a subset of a table?
4 Can one monitor how fast a table is imported?
5 Can one import tables to a different tablespace?
6 Does one need to drop/ truncate objects before importing?
7 Can one import/export between different versions of Oracle?
8 Can one export to multiple files?/ Can one beat the Unix 2 Gig limit?
9 How can one improve Import/ Export performance?
10 What are the common Import/ Export problems?
[edit]What is import/export and why does one need it?

Friday, July 6, 2012

ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode

-bash-3.00$ rman
RMAN> connect target /
connected to target database: ORCL(DBID=2560365586)
RMAN> backup database;
Starting backup at 27-DEC-10
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=59 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 12/27/2010 09:21:13
ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode
continuing other job steps, job failed will not be re-run
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 27-DEC-10
channel ORA_DISK_1: finished piece 1 at 27-DEC-10
piece handle=/u01/app/oracle/flash_recovery_area/ORCL/
backupset/2011_12_27/o1_mf_ncsnf_TAG20111227T092110_7hlwhbss_.bkp tag=TAG20111227T092110 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 12/27/2010 09:21:13
ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode

To be able to take a hotbackup with RMAN, you have to enable ARCHIVELOG MODE.
 
To see how to enable ARCHIVELOG MODE, How to enable ARCHIVELOG MODE

To enable archivelog mode, user must have sysdba privileges.

SQL> connect sys/solarishowto as sysdba
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter database archivelog;
SQL> alter database open;
Lets check that archivelog mode is enabled
SQL> select log_mode from v$database;
LOG_MODE
——————–
ARCHIVELOG