<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1727938467293727772</id><updated>2024-09-26T00:43:09.376+05:00</updated><category term="Postgresql"/><category term="Linux"/><category term="CentOS"/><category term="Sql"/><category term="Oracle"/><category term="Consultancy"/><category term="Failover"/><category term="Mysql"/><category term="Pgpool"/><title type='text'>AI Rumman - with the Databases</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>22</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1727938467293727772.post-8838175449074758585</id><published>2011-02-13T18:01:00.001+06:00</published><updated>2011-02-18T20:31:18.361+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CentOS"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="Postgresql"/><title type='text'>Set Unix Shared Memory Parameters&#39; (shm)  value for Postgresql in CentOS</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;I had to setup Postgresql 9.0.1 in a virtual machine running with CentOS5 with 2 GB RAM.&lt;br /&gt;
&lt;br /&gt;
Two important Unix Shared Memory papramters are &lt;b&gt;SHMMAX&lt;/b&gt; and &lt;b&gt;SHMALL&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
Here,&lt;br /&gt;
SHMMAX is the maximum size (in bytes) for a single shared memory segment&lt;br /&gt;
and&lt;br /&gt;
SHMALL is the total amount of shared memory (in pages) that all processes on the server can use.&lt;br /&gt;
&lt;br /&gt;
I followed the following steps to calculate the above parameters for my Postgresql DB server:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;page_size=`getconf PAGE_SIZE`&lt;br /&gt;
phys_pages=`getconf _PHYS_PAGES`&lt;br /&gt;
let shmall=$phys_pages/2&lt;br /&gt;
echo $shmall&lt;br /&gt;
let shmmax=$shmall*$page_size&lt;br /&gt;
echo $shmmax&lt;/blockquote&gt;&lt;br /&gt;
Here,&lt;br /&gt;
&lt;b&gt;_PHYS_PAGES &lt;/b&gt;: Total number of RAM pages used by processes in this container.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;PAGE_SIZE:&lt;/b&gt; A page is a fixed length block of main memory, that is contiguous in both physical memory addressing and virtual memory addressing.&lt;br /&gt;
&lt;br /&gt;
I got the following values for my DB server which was running with 2 GB RAM:&lt;br /&gt;
&lt;br /&gt;
shmall=262166&lt;br /&gt;
shmmax=1073831936&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
That is maximum size for a single shared memory segment is 1 GB which is shmmax and all processes on the server can use upto 1 GB (shmall*page_size) of shared memory.&lt;br /&gt;
&lt;br /&gt;
Now, I modified the value for the above two parameters using sysctl interface -&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;$ sysctl -w kernel.shmmax=1073831936&lt;br /&gt;
$ sysctl -w kernel.shmall=262166&lt;/blockquote&gt;&lt;br /&gt;
Check that the values are set;&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;$ cat /proc/sys/kernel/shmmax&lt;br /&gt;
1073831936&lt;br /&gt;
$ cat /proc/sys/kernel/shmall&lt;br /&gt;
262166&lt;/blockquote&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
In addition, I also preserved these values between reboots in the file /etc/sysctl.conf.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/8838175449074758585/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://airumman.blogspot.com/2011/02/set-unix-shared-memory-parameters-shm.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/8838175449074758585'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/8838175449074758585'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/2011/02/set-unix-shared-memory-parameters-shm.html' title='Set Unix Shared Memory Parameters&#39; (shm)  value for Postgresql in CentOS'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1727938467293727772.post-356670483540596919</id><published>2011-02-08T17:59:00.002+06:00</published><updated>2011-02-12T00:28:13.145+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Failover"/><category scheme="http://www.blogger.com/atom/ns#" term="Pgpool"/><category scheme="http://www.blogger.com/atom/ns#" term="Postgresql"/><title type='text'>Postgresql failover with Pgpool II replication</title><content type='html'>Postgresql failover with Pgpool II replication can be configured for 24x7 database system where no downtime is allowable. The followings describe the steps that we have taken for configuration og Pgpool II replication.&lt;br /&gt;
1. Environment&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;* Two identical servers 10.0.0.36 as &#39;Node 1&#39; and 10.0.0.34 as &#39;Node 2&#39; with Centos 5&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;* Existing ssh-key-exchange between both the nodes.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;* Postgresql 8.3.8 has been installed in each server&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;* Pgpool II 2.2.5 has been installed in 10.0.0.36&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;* At Node 1, $PGDATA=/usr/local/pgsql/data&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;* At Node 2, $PGDATA=/usr/local/pgsql/data&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;1.1 Wal Archiving is on in both the nodes.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
At Node_1:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;archive_mode = on&lt;br /&gt;
archive_command = &#39;rsync %p postgres@10.0.0.34:/var/lib/pgsql/wal_archive_36/%f&amp;lt;At Node_2:&lt;br /&gt;
archive_mode = on&lt;br /&gt;
archive_command = &#39;cp %p /var/lib/pgsql/wal_archive_34/%f&amp;lt;&lt;/blockquote&gt;&amp;nbsp;&lt;b&gt;1.2 Pgpool II installation&lt;/b&gt;&lt;br /&gt;
&lt;blockquote&gt;As root user perform the followings:&lt;br /&gt;
&lt;blockquote&gt;cd /downloads/&lt;br /&gt;
tar -xzvf pgpool-II-2.2.5.tar.gz&lt;br /&gt;
cd pgpool-II-2.2.5&lt;br /&gt;
./configure --prefix=/opt/pgpoolII &amp;nbsp; --with-pgsql-libdir=/usr/local/pgsql/lib &amp;nbsp; --with-pgsql-includedir=/usrlocal/pgsql/include&lt;br /&gt;
make &amp;amp;&amp;amp; make install&lt;/blockquote&gt;&lt;/blockquote&gt;&lt;br /&gt;
&amp;nbsp;&lt;b&gt;1.2.1 Configuration&lt;/b&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;blockquote&gt;cd /opt/pgpoolII/&lt;br /&gt;
cp etc/pcp.conf.sample etc/pcp.conf&lt;br /&gt;
cp etc/pgpool.conf.sample etc/pgpool.conf&lt;br /&gt;
/opt/pgpoolII/bin/pg_md5 -p&lt;br /&gt;
password:postgres&lt;br /&gt;
e8a48653851e28c69d0506508fb27fc5&lt;br /&gt;
vi etc/pcp.conf&lt;br /&gt;
...&lt;br /&gt;
postgres:e8a48653851e28c69d0506508fb27fc5&lt;/blockquote&gt;&lt;b&gt;&lt;/b&gt;&lt;/blockquote&gt;&lt;br /&gt;
&amp;nbsp;&lt;b&gt;1.2.2 Modify parameters at pgpool.conf&lt;/b&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;br /&gt;
Here we define ports for pgpool,pgpool communication manager, listen addresses and a lot of other things.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;vi etc/pgpool.conf&lt;br /&gt;
...&lt;br /&gt;
listen_addresses =&#39;*&#39;&lt;br /&gt;
...&lt;br /&gt;
replication_mode = true&lt;br /&gt;
…&lt;br /&gt;
logdir = &#39;/opt/pgpoolII/log&#39;&lt;br /&gt;
.....&lt;br /&gt;
pid_file_name=&#39;/var/run/pgppool/pgpool.pid&#39;&lt;br /&gt;
...&lt;br /&gt;
health_check_period= 5&lt;br /&gt;
health_check_user = &#39;postgres&#39;&lt;br /&gt;
...&lt;br /&gt;
failover_command = &#39;echo host:%h new master id:%m old master id:%M&amp;gt;/opt/pgpoolII/log/failover.log&#39;&lt;br /&gt;
failback_command = &#39;echo host:%h new master id:%m old master id:%M&amp;gt;/opt/pgpoolII/log/failback.log&#39;&lt;br /&gt;
...&lt;br /&gt;
backend_hostname0 = &#39;10.0.0.36&#39;&lt;br /&gt;
backend_port0 = 5432&lt;br /&gt;
backend_weight0 = 1&lt;br /&gt;
backend_data_directory0 = &#39;/usr/local/pgsql/data&#39;&lt;br /&gt;
backend_hostname1 = &#39;10.0.0.34&#39;&lt;br /&gt;
backend_port1 = 5432&lt;br /&gt;
backend_weight1 = 1&lt;br /&gt;
backend_data_directory1 = &#39;/usr/local/pgsql/data&#39;&lt;br /&gt;
..&lt;/blockquote&gt;&lt;b&gt;&lt;/b&gt;&lt;/blockquote&gt;&amp;nbsp;&lt;b&gt;1.2.3 Make directory for pgpool pid file:&lt;/b&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;br /&gt;
Login as root and make a directory pgpool in /var/run&lt;br /&gt;
&lt;blockquote&gt;cd /var/run&lt;br /&gt;
mkdir pgpool&lt;br /&gt;
chown -R postgres:postgres pgpool&lt;/blockquote&gt;&lt;b&gt;&lt;/b&gt;&lt;/blockquote&gt;&amp;nbsp;&lt;b&gt;1.2.4 Install online recovery functions at both the nodes:&lt;/b&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;blockquote&gt;cd /downloads/pgpool-II-2.2.5/sql/pgpool-recovery/&lt;br /&gt;
make install&lt;br /&gt;
psql -f pgpool-recovery.sql template1&lt;/blockquote&gt;&lt;b&gt;&lt;/b&gt;&lt;/blockquote&gt;&amp;nbsp;&lt;b&gt;1.2.5 pg_hba.conf configuration&lt;/b&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;br /&gt;
As pgpool is running at 10.0.0.35 and the connection between pgpool and postgresql should be trusted, we configured as follows:&lt;br /&gt;
At Node_1:&lt;br /&gt;
&lt;blockquote&gt;host &amp;nbsp; &amp;nbsp;all &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; all &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10.0.0.35/32 &amp;nbsp; &amp;nbsp; &amp;nbsp; trust&lt;br /&gt;
host &amp;nbsp; &amp;nbsp;all &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; all &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.0.0.0/0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;reject&lt;/blockquote&gt;At Node_2:&lt;br /&gt;
&lt;blockquote&gt;host &amp;nbsp; &amp;nbsp;all &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; all &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10.0.0.35/32 &amp;nbsp; &amp;nbsp; &amp;nbsp; trust&lt;br /&gt;
host &amp;nbsp; &amp;nbsp;all &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; all &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.0.0.0/0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;reject&lt;/blockquote&gt;pool_hba.conf configuration of pgpool&lt;br /&gt;
In our test environment, we did not enable pgpool hba configuration. Important point is that Pgpool II does not support md5 authentication.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;&lt;/blockquote&gt;&amp;nbsp;&lt;b&gt;2. Copy database from Node_1 to Node_2&lt;/b&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;2.1 At Node_1:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Assume postgresql is running.&lt;br /&gt;
&lt;blockquote&gt;psql -U postgres&lt;br /&gt;
&amp;gt; select pg_start_backup(&#39;initial_backup&#39;);&lt;br /&gt;
&amp;gt; \q&lt;br /&gt;
cd /usr/local/pgsql&lt;br /&gt;
rsync -avz data/* postgres@node_2:/usr/local/pgsql/data&lt;br /&gt;
psql -U postgres&lt;/blockquote&gt;&lt;blockquote&gt;&amp;gt; select pg_stop_backup();&lt;br /&gt;
&amp;gt; \q&lt;/blockquote&gt;&lt;b&gt;2.2 At Node_2:&lt;/b&gt;&lt;br /&gt;
&lt;blockquote&gt;cd /usr/local/pgsql/data&lt;br /&gt;
rm postmaster.pid&lt;br /&gt;
Start postgresql at Node_2&lt;br /&gt;
pg_ctl start&lt;/blockquote&gt;Now postgresql DB is running in both the nodes. We will start PgpoolII.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;&lt;/blockquote&gt;&amp;nbsp;&lt;b&gt;3. Start Pgpool II&lt;/b&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;br /&gt;
At this stage, we start pgpool in debug mode.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;/opt/pgpoolII/bin/pgpool &amp;nbsp;-f /opt/pgpoolII/etc/pgpool.conf -F /opt/pgpoolII/etc/pcp.conf -a /opt/pgpoolII/etc/pool_hba.conf -d -n &amp;gt; /opt/pgpoolII/log/pgpool.log 2&amp;gt;&amp;amp;1 &amp;amp;&lt;/blockquote&gt;Check log files to see if pgpool is working.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;tail /opt/pgpoolII/log/pgpool.log&lt;br /&gt;
...&lt;br /&gt;
2009-10-29 18:49:07 DEBUG: pid 12752: num_backends: 2 num_backends: 2 total_weight: 2.000000&lt;br /&gt;
2009-10-29 18:49:07 DEBUG: pid 12752: backend 0 weight: 1073741823.500000&lt;br /&gt;
2009-10-29 18:49:07 DEBUG: pid 12752: backend 1 weight: 1073741823.500000&lt;br /&gt;
2009-10-29 18:49:07 DEBUG: pid 12753: I am 12753&lt;br /&gt;
...&lt;br /&gt;
2009-10-29 18:49:07 DEBUG: pid 12784: I am 12784&lt;br /&gt;
2009-10-29 18:49:07 LOG: &amp;nbsp; pid 12752: pgpool successfully started&lt;br /&gt;
2009-10-29 18:49:07 DEBUG: pid 12785: I am PCP 12785&lt;br /&gt;
...&lt;br /&gt;
2009-10-29 18:51:53 DEBUG: pid 17586: starting health checking&lt;br /&gt;
2009-10-29 18:51:53 DEBUG: pid 17586: health_check: 0 th DB node status: 1&lt;br /&gt;
2009-10-29 18:51:53 DEBUG: pid 17586: health_check: 1 th DB node status: 1&lt;br /&gt;
...&lt;/blockquote&gt;&lt;b&gt;&lt;/b&gt;&lt;/blockquote&gt;&amp;nbsp;&lt;b&gt;4. Check if replication is working&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;- postgres is running on all nodes&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;- pgpool is running on port 9999 on node 1&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;- shell session on node1 established&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;&lt;/blockquote&gt;&amp;nbsp;&lt;b&gt;4.1 create a test database and insert some data&lt;/b&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;blockquote&gt;psql -p 9999&lt;/blockquote&gt;If the above command is successfull, we are confirm that Pgpool is working. Tthen do the following steps.&lt;br /&gt;
&lt;blockquote&gt;createdb -p 9999 bench_replication&lt;br /&gt;
pgbench -i -p 9999 bench_replication&lt;br /&gt;
psql -p 9999 bench_replication&lt;br /&gt;
bench_replication=# insert into history (tid, bid,aid,mtime,filler) (select 1,1,1,now(),i::text from&lt;br /&gt;
(select generate_series(1,1000000) as i) as q);&lt;/blockquote&gt;&lt;b&gt;&lt;/b&gt;&lt;/blockquote&gt;&amp;nbsp;&lt;b&gt;4.2 Check data in each node&lt;/b&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;br /&gt;
At Node_1:&lt;br /&gt;
&lt;blockquote&gt;psql -p 9999 bench_replication&lt;br /&gt;
select count(*) from history;&lt;br /&gt;
Count&lt;br /&gt;
--------&lt;br /&gt;
1000000&lt;br /&gt;
(1 row)&lt;/blockquote&gt;At Node_1:&lt;br /&gt;
&lt;blockquote&gt;psql -p 5432 bench_replication&lt;br /&gt;
select count(*) from history;&lt;br /&gt;
Count&lt;br /&gt;
--------&lt;br /&gt;
1000000&lt;br /&gt;
(1 row)&lt;/blockquote&gt;At Node_2:&lt;br /&gt;
&lt;blockquote&gt;psql -p 5432 bench_replication&lt;br /&gt;
select count(*) from history;&lt;br /&gt;
Count&lt;br /&gt;
--------&lt;br /&gt;
1000000&lt;br /&gt;
(1 row)&lt;/blockquote&gt;The results indicate that the replication is working.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;&lt;/blockquote&gt;&amp;nbsp;&lt;b&gt;5. Enable online recovery&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;&lt;b&gt;5.1 Configure pgpool.conf parameters:&lt;/b&gt;&lt;br /&gt;
&lt;blockquote&gt;...&lt;br /&gt;
recovery_user = &amp;nbsp;&#39;postgres&#39;&lt;br /&gt;
recovery_1st_stage_command = &amp;nbsp;&#39;copy_base_backup&#39;&lt;br /&gt;
recovery_2nd_stage_command = &#39;pgpool_recovery_pitr&#39;&lt;br /&gt;
...&lt;/blockquote&gt;&amp;nbsp;Reload pgpool to reflect the changes.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;5.2 Create scripts&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;I have write scripts for both the nodes. If anyone wants to setup Online recovery from either side only, he may use only required scripts.&lt;br /&gt;
------------------------------------------------&lt;br /&gt;
&amp;nbsp;copy_base_backup at Node_1:&lt;br /&gt;
&amp;nbsp;------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;#! /bin/sh&lt;br /&gt;
psql -c &quot;select pg_start_backup(&#39;pgpool_recovery&#39;)&quot; postgres&lt;br /&gt;
echo &quot;restore_command = &#39;cp /var/lib/pgsql/wal_archives_36/%f %p&#39;&quot;&amp;gt;/var/lib/pgsql/data/recovery.conf&lt;br /&gt;
tar -C /var/lib/pgsql/data -zcf pgsql.tar.gz base global pg_clog pg_multixact pg_subtrans pg_tblspc pg_twophase pg_xlog recovery.conf&lt;br /&gt;
psql -c &quot;select pg_stop_backup()&quot; postgres&lt;br /&gt;
scp pgsql.tar.gz 10.0.0.34:/var/lib/pgsql/data&lt;br /&gt;
&amp;nbsp;#Expand a database backup&lt;br /&gt;
ssh -T 10.0.0.34 &#39;cd /var/lib/pgsql/data; tar zxf pgsql.tar.gz&#39; 2&amp;gt;/dev/null 1&amp;gt;/dev/null&lt;br /&gt;
rm -f recovery.conf&lt;/blockquote&gt;-------------------------------------------------&lt;br /&gt;
copy_base_backup at Node_2:&lt;br /&gt;
-------------------------------------------------&lt;br /&gt;
&lt;blockquote&gt;#! /bin/sh&lt;br /&gt;
&amp;nbsp;BINPATH=/opt/PostgreSQL/8.3/bin&lt;br /&gt;
$BINPATH/psql -c &quot;select pg_start_backup(&#39;pgpool_recovery&#39;)&quot; postgres&lt;br /&gt;
echo &quot;restore_command = &#39;scp postgres@10.0.0.34:/var/lib/pgsql/wal_archives_34/%f %p&#39;&quot;&amp;gt;/var/lib/pgsql/data/recovery.conf&lt;br /&gt;
tar -C /var/lib/pgsql/data -zcf pgsql.tar.gz base global pg_clog pg_multixact pg_subtrans pg_tblspc pg_twophase pg_xlog recovery.conf&lt;br /&gt;
$BINPATH/psql -c &quot;select pg_stop_backup()&quot; postgres&lt;br /&gt;
scp pgsql.tar.gz 10.0.0.36:/var/lib/pgsql/data&lt;br /&gt;
# Expand a database backup&lt;br /&gt;
ssh -T 10.0.0.36 &#39;cd /var/lib/pgsql/data; tar zxf pgsql.tar.gz&#39; 2&amp;gt;/dev/null 1&amp;gt;/dev/null&lt;br /&gt;
rm -f recovery.conf&lt;/blockquote&gt;-----------------------------------&lt;br /&gt;
pgpool_recovery_pitr:&lt;br /&gt;
-----------------------------------&lt;br /&gt;
#! /bin/sh&lt;br /&gt;
psql -c &quot;select pg_switch_xlog()&quot; postgres&lt;br /&gt;
--------------------------------------------------&lt;br /&gt;
pgpool_remote_start at Node_1:&lt;br /&gt;
--------------------------------------------------&lt;br /&gt;
&lt;blockquote&gt;#! /bin/sh&lt;br /&gt;
if [ $# -ne 2 ]&lt;br /&gt;
then&lt;br /&gt;
echo &quot;pgpool_remote_start remote_host remote_datadir&quot;&lt;br /&gt;
exit 1&lt;br /&gt;
fi&lt;br /&gt;
DEST=$1&lt;br /&gt;
DESTDIR=$2&lt;br /&gt;
PGCTL=/opt/PostgreSQL/8.3/bin/pg_ctl &amp;nbsp; &amp;nbsp;#postgesql bin directory at Node_2&lt;br /&gt;
#Startup PostgreSQL server&lt;br /&gt;
ssh -T $DEST $PGCTL -w -D $DESTDIR start 2&amp;gt;/dev/null 1&amp;gt;/dev/null&amp;nbsp;&lt;/blockquote&gt;--------------------------------------------------&lt;br /&gt;
pgpool_remote_start at Node_2:&lt;br /&gt;
--------------------------------------------------&lt;br /&gt;
&lt;blockquote&gt;#! /bin/sh&lt;br /&gt;
if [ $# -ne 2 ]&lt;br /&gt;
then&lt;br /&gt;
echo &quot;pgpool_remote_start remote_host remote_datadir&quot;&lt;br /&gt;
exit 1&lt;br /&gt;
fi&lt;br /&gt;
DEST=$1&lt;br /&gt;
DESTDIR=$2&lt;br /&gt;
PGCTL=/usr/local/pgsql/bin/pg_ctl &amp;nbsp;#Path for postgresql bin directory at Node_1&lt;br /&gt;
#Startup PostgreSQL server&lt;br /&gt;
ssh -T $DEST $PGCTL -w -D $DESTDIR start 2&amp;gt;/dev/null 1&amp;gt;/dev/null&amp;nbsp;&lt;/blockquote&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;6. Test failover:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;To test failover is working perfectly, I just killed postgres processes on node_2 while an update statement is running at node_1 using port 9999.&lt;br /&gt;
At Node_1:&lt;br /&gt;
psql -p 9999 bench_repplication&lt;br /&gt;
update history set tid=2;&lt;br /&gt;
&lt;br /&gt;
At Node_2:&lt;br /&gt;
pkill postgres&lt;br /&gt;
or&lt;br /&gt;
pg_ctl stop -m immediate&lt;br /&gt;
&lt;br /&gt;
Check that at Node_1 the update is still running.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;tail pgpool.log&lt;br /&gt;
...&lt;br /&gt;
2009-11-12 13:22:23 DEBUG: pid 13719: detect_error: kind: E&lt;br /&gt;
2009-11-12 13:22:23 DEBUG: pid 13719: detect_stop_postmaster_error: receive admin shutdown error from a node.&lt;br /&gt;
2009-11-12 13:22:23 LOG: &amp;nbsp; pid 13719: notice_backend_error: 1 fail over request from pid 13719&lt;br /&gt;
2009-11-12 13:22:23 DEBUG: pid 13715: failover_handler called&lt;br /&gt;
2009-11-12 13:22:23 DEBUG: pid 13715: failover_handler: starting to select new master node&lt;br /&gt;
2009-11-12 13:22:23 LOG: &amp;nbsp; pid 13715: starting degeneration. shutdown host 10.0.0.54(5432)&lt;br /&gt;
2009-11-12 13:22:23 DEBUG: pid 13715: VN:: Master_node_id is changing from 0 to 0&lt;br /&gt;
2009-11-12 13:22:23 LOG: &amp;nbsp; pid 13715: failover_handler: do not restart pgpool. same master node 0 was selected&lt;br /&gt;
2009-11-12 13:22:23 LOG: &amp;nbsp; pid 13715: failover done. shutdown host 10.0.0.54(5432)&lt;br /&gt;
2009-11-12 13:22:23 LOG: &amp;nbsp; pid 13715: execute command: echo host:10.0.0.54 new master id:0 old master id:0&amp;gt;/opt/pgpoolII/log/failover.log&lt;br /&gt;
2009-11-12 13:22:23 DEBUG: pid 13715: reap_handler called&lt;br /&gt;
2009-11-12 13:22:23 DEBUG: pid 13715: reap_handler: call wait3&lt;br /&gt;
2009-11-12 13:22:23 DEBUG: pid 13715: reap_handler: normally exited&lt;br /&gt;
2009-11-12 13:22:28 DEBUG: pid 13715: starting health checking&lt;br /&gt;
2009-11-12 13:22:28 DEBUG: pid 13715: health_check: 0 th DB node status: 2&lt;br /&gt;
2009-11-12 13:22:28 DEBUG: pid 13715: health_check: 1 th DB node status: 3&lt;br /&gt;
...&lt;/blockquote&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;7. Online Recovery and Re-attach node:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;After failover if we want to re-attach Node_1, we node to apply the changes happened at Node_2 through Pgpool. As a result , recovery at Node_1 is required.&lt;br /&gt;
&lt;blockquote&gt;/opt/pgpoolII/bin/pcp_recovery_node &amp;nbsp;20 10.0.0.36 9898 postgres postgres 1&lt;/blockquote&gt;Parameters are:&lt;br /&gt;
20 - timeout in seconds&lt;br /&gt;
10.0.0.36 - host ip where pgpool is running&lt;br /&gt;
9898 - port at which pgpool communication manager listens&lt;br /&gt;
postgres, postgres - username password at pcp.conf&lt;br /&gt;
1 - ID of the node we want to attach (refers to the backend number in pgpool.conf)&lt;br /&gt;
&lt;br /&gt;
pgpool.log messages:&lt;br /&gt;
&lt;blockquote&gt;...&lt;br /&gt;
DEBUG: pid 4411: pcp_child: start online recovery&lt;br /&gt;
LOG: pid 4411: starting recovering node 1&lt;br /&gt;
DEBUG: pid 4411: exec_checkpoint: start checkpoint&lt;br /&gt;
DEBUG: pid 4411: exec_checkpoint: finish checkpoint&lt;br /&gt;
LOG: pid 4411: CHECKPOINT in the 1st stage done&lt;br /&gt;
LOG: pid 4411: starting recovery command: &quot;SELECT pgpool_recovery(&#39;copy_base_backup&#39;, &#39;10.0.0.34&#39;,&#39;/usr/local/pgsql/data&#39;)&quot;&lt;br /&gt;
DEBUG: pid 4411: exec_recovery: start recovery&lt;br /&gt;
DEBUG: pid 29658: starting health checking&lt;br /&gt;
DEBUG: pid 29658: health_check: 0 the DB node status: 2&lt;br /&gt;
DEBUG: pid 29658: health_check: 1 the DB node status: 3&lt;br /&gt;
DEBUG: pid 4411: exec_recovery: finish recovery&lt;br /&gt;
LOG: pid 4411: 1st stage is done&lt;br /&gt;
LOG: pid 4411: starting 2nd stage&lt;br /&gt;
LOG: pid 4411: all connections from clients have been closed&lt;br /&gt;
DEBUG: pid 4411: exec_checkpoint: start checkpoint&lt;br /&gt;
DEBUG: pid 4411: exec_checkpoint: finish checkpoint&lt;br /&gt;
LOG: pid 4411: CHECKPOINT in the 2nd stage done&lt;br /&gt;
LOG: pid 4411: starting recovery command: &quot;SELECT pgpool_recovery(&#39;pgpool_recovery_pitr&#39;, &#39;10.0.0.34&#39;,&#39;/usr/local/pgsql/data&#39;)&quot;&lt;br /&gt;
DEBUG: pid 4411: exec_recovery: start recovery&lt;br /&gt;
DEBUG: pid 4411: exec_recovery: finish recovery&lt;br /&gt;
DEBUG: pid 4411: exec_remote_start: start pgpool_remote_start&lt;br /&gt;
DEBUG: pid 29658: starting health checking&lt;br /&gt;
DEBUG: pid 4411: exec_remote_start: finish pgpool_remote_start&lt;br /&gt;
DEBUG: pid 29658: starting health checking&lt;br /&gt;
LOG: pid 4411: 1 node restarted&lt;br /&gt;
LOG: pid 4411: send_failback_request: fail back 1 th node request from pid 4411&lt;br /&gt;
LOG: pid 4411: recovery done&lt;br /&gt;
DEBUG: pid 29658: failover_handler called&lt;br /&gt;
DEBUG: pid 29658: failover_handler: starting to select new master node...&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/blockquote&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: bold;&quot;&gt;8. Database Downtime:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: bold;&quot;&gt;&lt;/span&gt;During production period if pgpool can communicate with any node, then system will not need any downtime from database end. But during online recovery,&amp;nbsp;before 2nd stage, all connections with pgpool should be closed. It is designed in this way so that no transaction miss during the recover and re-attach of a node.</content><link rel='replies' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/356670483540596919/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://airumman.blogspot.com/2011/02/postgresql-failover-with-pgpool-ii.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/356670483540596919'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/356670483540596919'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/2011/02/postgresql-failover-with-pgpool-ii.html' title='Postgresql failover with Pgpool II replication'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1727938467293727772.post-1171620378318889672</id><published>2011-01-05T16:19:00.000+06:00</published><updated>2011-01-05T16:19:47.916+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><title type='text'>RAID level selection for databases</title><content type='html'>RAID, an acronym for Redundant Array of Independent Disks, is a technology that provides increased storage functions and reliability through redundancy, combining multiple disk drives components into a logical unit where all drives in the array are interdependent.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Different levels of RAID:&lt;/b&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;RAID 0 – Block level striping without mirroring&lt;/li&gt;
&lt;li&gt;RAID 1 - Mirroring without striping&lt;/li&gt;
&lt;li&gt;RAID 2 - Bit-level striping with dedicated Hamming-code parity.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;RAID 3 - Byte striping with dedicated parity drive&lt;/li&gt;
&lt;li&gt;RAID 4 - Block striping with dedicated parity&amp;nbsp;&lt;/li&gt;
&lt;li&gt;RAID 5 - Block striping with distributed parity&lt;/li&gt;
&lt;li&gt;RAID 6 - Block striping with double distributed parity&lt;/li&gt;
&lt;/ul&gt;&lt;b&gt;Comparison of RAID Levels:&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
Level &lt;/td&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
Advantages&lt;/td&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
Disadvantages &lt;/td&gt;  &lt;/tr&gt;
&lt;tr &#39;=&quot;&quot;&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
RAID 0 &lt;/td&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
Fastest I/O &lt;br /&gt;
&lt;br /&gt;
No overhead for parity&lt;br /&gt;
&lt;br /&gt;
Simple design, easily implemented &lt;/td&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
Not really RAID&lt;br /&gt;
&lt;br /&gt;
One drive failure destroys all data&lt;br /&gt;
&lt;br /&gt;
Not for mission-critical deployment &lt;/td&gt;  &lt;/tr&gt;
&lt;tr &#39;=&quot;&quot;&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
RAID 1 &lt;/td&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
All drives usable for data reads &lt;br /&gt;
&lt;br /&gt;
Can be implemented w/ 2 drives &lt;/td&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
Greatest storage overhead - 100%&lt;br /&gt;
&lt;br /&gt;
Highest cost/capacity ratio &lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 3;&quot;&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
RAID 3 &lt;/td&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
High transfer rates &lt;br /&gt;
&lt;br /&gt;
Degraded mode still fast &lt;/td&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
Requires spindle synchronization&lt;br /&gt;
&lt;br /&gt;
Can&#39;t do overlapped I/O &lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 4;&quot;&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
RAID 4 &lt;/td&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
High read transfer rates &lt;br /&gt;
&lt;br /&gt;
Efficient use of capacity &lt;/td&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
Poor write rates&lt;br /&gt;
&lt;br /&gt;
Parity drive can be bottleneck &lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 5;&quot;&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
RAID 5 &lt;/td&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
Very high read rate &lt;br /&gt;
&lt;br /&gt;
Efficient use of capacity &lt;/td&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
Slower write rates &lt;br /&gt;
&lt;br /&gt;
Slow rebuild times &lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 6;&quot;&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
RAID 6 &lt;/td&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
Allows failure of multiple drives &lt;/td&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
Very poor write performance &lt;br /&gt;
&lt;br /&gt;
Proprietary solution, rare &lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 7;&quot;&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
RAID 7 &lt;/td&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
Supposed to be fastest &lt;/td&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
Proprietary, very expensive &lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 8; mso-yfti-lastrow: yes;&quot;&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
RAID 1+0 &lt;/td&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
Very high reads and writes &lt;/td&gt;   &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot;&gt;&lt;br /&gt;
Most expensive &lt;/td&gt;  &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;font-weight: bold;&quot;&gt;RAID for databases:&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;There are a number of factors to consider when choosing the appropriate RAID level for a specific application’s data storage.&lt;br /&gt;
RAID 5 is better suited for mostly read-oriented applications while RAID 0+1 is also better suited for write intensive applications. In addition, stripping component (RAID 0) of RAID 0+1 offers the same read performance as RAID 5.&lt;br /&gt;
&lt;br /&gt;
In our case for CRM application’s database, where we had to ensure good read-write speed with data protection, we chose RAID 1 for 2 drives (500 GB SATA) in Dell PowerEdge 6850 server and for a sports portal we used RAID 10 in&amp;nbsp;&amp;nbsp;Dell PowerEdge M600 server and for a Bank database I had RAID 10 with remote mirroring in IBM Power System.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;font-weight: bold;&quot;&gt;References:&lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/RAID&quot;&gt;http://en.wikipedia.org/wiki/RAID&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.bolthole.com/uuala/RAID.html&quot;&gt;http://www.bolthole.com/uuala/RAID.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;</content><link rel='replies' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/1171620378318889672/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://airumman.blogspot.com/2011/01/raid-level-selection-for-databases.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/1171620378318889672'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/1171620378318889672'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/2011/01/raid-level-selection-for-databases.html' title='RAID level selection for databases'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1727938467293727772.post-4384715370733890121</id><published>2011-01-04T18:00:00.000+06:00</published><updated>2011-01-04T18:00:18.362+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Postgresql"/><title type='text'>Scheduled VACUUM instead of AutoVacuum</title><content type='html'>&lt;div class=&quot;MsoNormal&quot;&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Once I found in Postgresql 9.0.1 that one of the report queries was hanged in the DB server while it was perfectly running on the development server which is a virtual machine with only 2 GB of RAM. Investigating properly, I found that some tables and indexes which were used in joining for the report query were bloated. I executed VACUUM ANALYZE manually and the system started to perform better.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Then I came to solution that the autovacuum is not vacuuming all the tables properly and it is fact.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Present status of some tables:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;blockquote&gt;select last_vacuum, last_autovacuum, last_analyze, last_autoanalyze from pg_stat_user_tables&amp;nbsp;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;where relname =&#39;crm&#39;;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;u1:p&gt;&amp;nbsp;&lt;/u1:p&gt;-[ RECORD 1 ]----+------------------------------&lt;/blockquote&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;&lt;blockquote&gt;last_vacuum&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;| 2011-01-04 12:39:57.586728+06&lt;/blockquote&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/div&gt;&lt;blockquote&gt;last_autovacuum&amp;nbsp;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;| 2011-01-04 16:13:30.254226+06&lt;/blockquote&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/div&gt;&lt;blockquote&gt;last_analyze&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;| 2011-01-04 12:40:17.680571+06&lt;/blockquote&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/div&gt;&lt;blockquote&gt;last_autoanalyze | 2011-01-04 16:14:17.402896+06&lt;/blockquote&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Same as for other tables.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Data shows that tables were not vacuumed using autovacuum process and the reason behind the autovacuum parameters.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;At present, our autovacuum configuration are as follows:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/div&gt;&lt;blockquote&gt;autovacuum_naptime = 5min&lt;/blockquote&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/div&gt;&lt;blockquote&gt;autovacuum_vacuum_threshold = 150&lt;/blockquote&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/div&gt;&lt;blockquote&gt;autovacuum_analyze_threshold = 150&lt;/blockquote&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/div&gt;&lt;blockquote&gt;autovacuum_vacuum_scale_factor = 0.2 &amp;nbsp;&lt;/blockquote&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/div&gt;&lt;blockquote&gt;autovacuum_analyze_scale_factor = 0.1&amp;nbsp;&lt;/blockquote&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Thresholds for -&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;crm = 150 + 0.2 * 1446016 =&amp;nbsp;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;289353.2&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;So, according to postgresql docs, if 289353.2 number of rows have been modified for crm table since the last autovacuum &amp;nbsp;then it will be a candidate for autovacuum and&amp;nbsp;&lt;/span&gt;that&#39;s why the tables has not been vacuumed yet by the autovacuumn process.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;So I prefer schedule vacuum for the following reasons -&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;As, we have no online users during night time, so we may easily schedule routine vacuum. It&#39;ll remove the overhead of autovacuum process from the DB server during peak hour of operations.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Besides, it&#39;ll eliminate the parameter settings overhead though by table-level storage parameter settings we can ensure autovacuum for the tables.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Autovacuum does not work for temporary tables.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/4384715370733890121/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://airumman.blogspot.com/2011/01/scheduled-vacuum-instead-of-autovacuum.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/4384715370733890121'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/4384715370733890121'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/2011/01/scheduled-vacuum-instead-of-autovacuum.html' title='Scheduled VACUUM instead of AutoVacuum'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1727938467293727772.post-8386649983168422832</id><published>2010-12-21T15:59:00.002+06:00</published><updated>2010-12-21T16:01:38.353+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Postgresql"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><title type='text'>SQL Query to show current activities of the database server at Postgresql</title><content type='html'>I executed the following query at Postgresql 9.0.1:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;SELECT pg_stat_activity.datname, pg_stat_activity.procpid,&lt;/blockquote&gt;&lt;blockquote&gt;pg_stat_activity.usename,&amp;nbsp;&lt;/blockquote&gt;&lt;blockquote&gt;pg_stat_activity.current_query,&lt;/blockquote&gt;&lt;blockquote&gt;pg_stat_activity.waiting,&lt;/blockquote&gt;&lt;blockquote&gt;pg_stat_activity.query_start,pg_stat_activity.client_addr&lt;/blockquote&gt;&lt;blockquote&gt;FROM pg_stat_activity&lt;/blockquote&gt;&lt;blockquote&gt;WHERE ((pg_stat_activity.procpid &amp;lt;&amp;gt; pg_backend_pid())&lt;/blockquote&gt;&lt;blockquote&gt;AND (pg_stat_activity.current_query &amp;lt;&amp;gt; &#39;&lt;idle&gt;&#39;))&lt;/idle&gt;&lt;/blockquote&gt;&lt;blockquote&gt;ORDER BY pg_stat_activity.query_start;&lt;/blockquote&gt;</content><link rel='replies' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/8386649983168422832/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://airumman.blogspot.com/2010/12/sql-query-to-find-current-activities-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/8386649983168422832'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/8386649983168422832'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/2010/12/sql-query-to-find-current-activities-in.html' title='SQL Query to show current activities of the database server at Postgresql'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1727938467293727772.post-84305386943552883</id><published>2010-12-09T18:59:00.000+06:00</published><updated>2010-12-09T18:59:24.015+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Postgresql"/><title type='text'>Postgresql in Mission-Critical Financial System</title><content type='html'>The following presentation is based on Caixa, 3rd largest Bank in Brazil. I found it very interesting in planning Postgresql for 24x7 system and hope that the readers will also enjoy it.&lt;br /&gt;
&lt;br /&gt;
&lt;embed allowfullscreen=&quot;true&quot; allowscriptaccess=&quot;always&quot; height=&quot;372&quot; src=&quot;http://blip.tv/play/hdlkgeCqIAI%2Em4v&quot; type=&quot;application/x-shockwave-flash&quot; width=&quot;100%&quot;&gt;&lt;/embed&gt;</content><link rel='replies' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/84305386943552883/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://airumman.blogspot.com/2010/12/postgresql-in-mission-critical.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/84305386943552883'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/84305386943552883'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/2010/12/postgresql-in-mission-critical.html' title='Postgresql in Mission-Critical Financial System'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1727938467293727772.post-407859598836321711</id><published>2010-12-09T18:37:00.002+06:00</published><updated>2010-12-09T18:40:38.421+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Postgresql"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><title type='text'>Query to find unused indexes in Postgresql</title><content type='html'>Following query finds out the unused indexes for top 20 most used tables in Postgresql:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;SELECT&lt;/b&gt;&lt;br /&gt;
i.relname,i.indexrelname,i.idx_scan,i.idx_tup_read,i.idx_tup_fetch, c.reltuples, c.relpages&lt;br /&gt;
&lt;b&gt;FROM&lt;/b&gt;&lt;br /&gt;
pg_stat_user_indexes as i &lt;br /&gt;
INNER JOIN pg_class as c&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ON i.indexrelname = c.relname&lt;br /&gt;
&lt;b&gt;WHERE&lt;/b&gt;&lt;br /&gt;
i.relname IN&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; --top 20 most used tables&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;b&gt;SELECT&lt;/b&gt; c.relname as name&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;b&gt;FROM&lt;/b&gt; pg_stat_user_tables as t&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; INNER JOIN pg_class as c&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ON t.relid = c.oid&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;b&gt;WHERE&lt;/b&gt; c.relkind =&#39;r&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;b&gt;ORDER BY&lt;/b&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; COALESCE(t.idx_tup_fetch,0)+COALESCE(t.seq_tup_read,0) DESC&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;b&gt;LIMIT&lt;/b&gt; 20&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;br /&gt;
&lt;b&gt;ORDER BY&lt;/b&gt; i.relname, i.idx_scan DESC</content><link rel='replies' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/407859598836321711/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://airumman.blogspot.com/2010/12/query-to-find-unused-indexes-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/407859598836321711'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/407859598836321711'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/2010/12/query-to-find-unused-indexes-in.html' title='Query to find unused indexes in Postgresql'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1727938467293727772.post-5980937939002953797</id><published>2010-12-02T17:49:00.003+06:00</published><updated>2010-12-03T00:56:06.645+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Postgresql"/><title type='text'>How to get number of rows return by a query using MOVE in Postgresql</title><content type='html'>&lt;b&gt;Create and populate data:&lt;/b&gt;&lt;br /&gt;
&lt;blockquote&gt;CREATE TABLE emp&lt;br /&gt;
(&lt;br /&gt;
empno int,&lt;br /&gt;
empname varchar(100),&lt;br /&gt;
city varchar(100)&lt;br /&gt;
);&lt;/blockquote&gt;&lt;br /&gt;
&lt;blockquote&gt;ALTER TABLE emp&lt;br /&gt;
ADD CONSTRAINT empno_pk PRIMARY KEY (empno);&lt;/blockquote&gt;&lt;br /&gt;
&lt;blockquote&gt;INSERT INTO emp&lt;br /&gt;
select q.c as empno, &#39;testemp_&#39;||q.c as empname, &#39;testcity_&#39;||q.c as city&lt;br /&gt;
FROM&lt;br /&gt;
(SELECT generate_series(1,100) as c) AS q&lt;br /&gt;
;&lt;/blockquote&gt;&lt;b&gt;Create function:&lt;/b&gt;&lt;br /&gt;
&lt;blockquote&gt;CREATE FUNCTION reffunc(refcursor) RETURNS refcursor AS $$&lt;br /&gt;
BEGIN&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; OPEN $1 FOR &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT&amp;nbsp; *&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM emp&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; RETURN $1;&lt;br /&gt;
END;&lt;br /&gt;
$$ LANGUAGE plpgsql;&lt;/blockquote&gt;&lt;b&gt;Get number of rows return:&lt;/b&gt;&lt;br /&gt;
&lt;blockquote&gt;DECLARE&lt;br /&gt;
&amp;nbsp; i INT;&lt;br /&gt;
BEGIN;&lt;br /&gt;
SELECT reffunc(&#39;funccursor&#39;);&lt;br /&gt;
MOVE ALL IN funccursor;&lt;br /&gt;
COMMIT;&lt;/blockquote&gt;&lt;b&gt;Further Study:&lt;/b&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.postgresql.org/docs/current/static/sql-move.html&quot;&gt;http://www.postgresql.org/docs/current/static/sql-move.html&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/5980937939002953797/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://airumman.blogspot.com/2010/12/how-to-get-number-of-rows-return-by.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/5980937939002953797'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/5980937939002953797'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/2010/12/how-to-get-number-of-rows-return-by.html' title='How to get number of rows return by a query using MOVE in Postgresql'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1727938467293727772.post-1824974691191539385</id><published>2010-11-17T16:24:00.006+06:00</published><updated>2010-11-17T16:59:31.595+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="Postgresql"/><title type='text'>Enable SYSLOG facility for Postgresql instance</title><content type='html'>Modified values of the following parameters at postgresql.conf:&lt;br /&gt;
&lt;blockquote style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;log_destination = ‘syslog’&lt;br /&gt;
syslog_facility = ‘LOCAL0’&lt;br /&gt;
silent_mode = on&lt;/blockquote&gt;Added lines at /etc/syslog.conf&lt;br /&gt;
&lt;blockquote style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;LOCAL0.*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -/var/log/pgsql/pgsql.log&lt;/blockquote&gt;&amp;nbsp;Ignored PostgreSQL facility for the default log file otherwise you would log the queries twice:&lt;br /&gt;
&lt;blockquote style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;*.info;...;local0.none&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /var/log/messages&lt;/blockquote&gt;&lt;br /&gt;
Restarted the SYSLOG service:&lt;br /&gt;
&lt;blockquote style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;pre&gt;/etc/init.d/sysklogd restart&lt;/pre&gt;&lt;/blockquote&gt;Now, we got postgresql log at /var/log/pgsql/pgsql.log&amp;nbsp;</content><link rel='replies' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/1824974691191539385/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://airumman.blogspot.com/2010/11/enable-syslog-facility-for-postgresql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/1824974691191539385'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/1824974691191539385'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/2010/11/enable-syslog-facility-for-postgresql.html' title='Enable SYSLOG facility for Postgresql instance'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1727938467293727772.post-4571493970343035366</id><published>2010-11-17T16:10:00.003+06:00</published><updated>2010-12-09T18:40:49.693+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Postgresql"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><title type='text'>Top 20 tables acording to sequential scan in Postgresql</title><content type='html'>&lt;b&gt;select&lt;/b&gt; c.relname as name, c.reltuples as No_of_records, c.relpages as&amp;nbsp; No_of_pages,&lt;br /&gt;
&amp;nbsp;&amp;nbsp; pg_size_pretty(pg_relation_size(c.relname)) as size,&lt;br /&gt;
&amp;nbsp;&amp;nbsp; t.seq_scan, t.seq_tup_read, t.idx_scan, t.idx_tup_fetch, t.n_tup_ins, t.n_tup_upd, t.n_tup_del,&lt;br /&gt;
&amp;nbsp;&amp;nbsp; COALESCE(t.idx_tup_fetch,0) + COALESCE(t.seq_tup_read,0) as total_read&lt;br /&gt;
&lt;b&gt;from&lt;/b&gt; pg_stat_user_tables as t inner join pg_class as c&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on (t.relid = c.oid)&lt;br /&gt;
&lt;b&gt;where&lt;/b&gt; c.relkind =&#39;r&#39;&lt;br /&gt;
&lt;b&gt;order by&lt;/b&gt; seq_scan desc&lt;br /&gt;
&lt;b&gt;limit&lt;/b&gt; 20</content><link rel='replies' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/4571493970343035366/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://airumman.blogspot.com/2010/11/top-20-tables-accroding-to-sequential.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/4571493970343035366'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/4571493970343035366'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/2010/11/top-20-tables-accroding-to-sequential.html' title='Top 20 tables acording to sequential scan in Postgresql'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1727938467293727772.post-2596340544965060926</id><published>2010-11-01T01:41:00.005+06:00</published><updated>2010-11-17T17:14:41.649+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Postgresql"/><title type='text'>DB performance degrade and the action steps in Postgresql</title><content type='html'>Once I had to improve performance for the CRM application running on Postgresql 8.1. Customers was complaining that after 1 pm the system got slow. &lt;br /&gt;
At first, I ensured that no background process was running at that time. Then I studied a lot and communicated with psql-archive writers. I planned some action steps and send mail to top management. The mail was as follows:-&lt;br /&gt;
The prime suggestion is to upgrade DB as only a year support available for 8.1.&lt;br /&gt;
As it is not possible right now, we may go for the following:&lt;br /&gt;
&lt;br /&gt;
1. nohup psql crm -c &quot;vacuum verbose analyze&quot; &amp;gt; /tmp/vacuum_crm.log&lt;br /&gt;
- To get a vaccum  log&lt;br /&gt;
- restart no required&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Defragment the DB will increase performance. Take a dump and then restore. It&#39;ll reduce DB bloat. DB size&#39;ll be reduced to 3Gb from 12 gb.&lt;br /&gt;
&lt;br /&gt;
DB wise:&lt;br /&gt;
&lt;br /&gt;
3. default_statistics_target = 200&lt;br /&gt;
- increase this value to improve the quality of planner&#39;s estimates. &lt;br /&gt;
- restart not required&lt;br /&gt;
- set only for crm database&lt;br /&gt;
- current value 100&lt;br /&gt;
&lt;br /&gt;
4. effective_cache_size = 17 gb then 20 gb incrementaly&lt;br /&gt;
- increase this value will force more index scan&lt;br /&gt;
- restart not required&lt;br /&gt;
- current value 1835010 ( 14 gb)&lt;br /&gt;
- statistics suggest we have free memory regularly&lt;br /&gt;
- this may cause paging for server, we need to check it out&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
System wide:&lt;br /&gt;
&lt;br /&gt;
5. log_min_error_statement=error;&lt;br /&gt;
- To find out which statements are creating error in the DB.&lt;br /&gt;
- restart not required&lt;br /&gt;
- current value panic&lt;br /&gt;
&lt;br /&gt;
6. log_min_messages=notice;&lt;br /&gt;
- To get more information about DB activities&lt;br /&gt;
- restart not required&lt;br /&gt;
- current value error&lt;br /&gt;
&lt;br /&gt;
8. checkpoint_warning = 3600&lt;br /&gt;
- to find checkpoint time in peak time  to find a good value for  checkpoint_segment and checkpoint_timeout&lt;br /&gt;
- I got suggestion to go for 8-12, but I want to be confirm at first that checkpoint_segment is a performance issue in our case&lt;br /&gt;
- restart not required&lt;br /&gt;
&lt;br /&gt;
9. max_fsm_pages = 2546960&lt;br /&gt;
- to reduce table bloat &lt;br /&gt;
- new value comes from vacuum verbose output&lt;br /&gt;
- required restart&lt;br /&gt;
- we are getting message in DB log every night to increase it during vaccum&lt;br /&gt;
&lt;br /&gt;
10. shared_buffers = 2 gb&lt;br /&gt;
- the main shared memory for the DB&lt;br /&gt;
- doc suggests to increase it upto 25% of total RAM incrementaly&lt;br /&gt;
- current value 958 MB&lt;br /&gt;
- required restart  &lt;br /&gt;
&lt;br /&gt;
I have completed task #1 to find a good value for step 9.  &lt;br /&gt;
I&#39;ll suggest to implement these changes incrementally so that we may find whether we are in correct way or not.&lt;br /&gt;
Here the suspicious steps are #3, #4, #9 and #10. We may go for step #9 at first.&lt;br /&gt;
Step #5, #6 and #7 are just DB log facility, so we should go for these as soon as possible.&lt;br /&gt;
Whale query tuning is an on-going process and will be continued.&lt;br /&gt;
&lt;br /&gt;
So far, I modified two values - random_page_cost and work_mem and I got benefits.&lt;br /&gt;
&lt;br /&gt;
I think the mail may help people in finding root cause for performance decrease.</content><link rel='replies' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/2596340544965060926/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://airumman.blogspot.com/2010/11/db-performance-degrade-and-take-action.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/2596340544965060926'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/2596340544965060926'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/2010/11/db-performance-degrade-and-take-action.html' title='DB performance degrade and the action steps in Postgresql'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1727938467293727772.post-4287506768036567336</id><published>2010-10-21T20:32:00.002+06:00</published><updated>2010-10-21T20:36:35.854+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Postgresql"/><title type='text'>List all tables from a specific schema in Postgresql</title><content type='html'>&lt;br /&gt;
List of schemas in my database;&lt;br /&gt;
&lt;blockquote&gt;
postgres=# \dn&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; List of schemas&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse; width: 247px;&quot;&gt;&lt;col style=&quot;width: 116pt;&quot; width=&quot;154&quot;&gt;&lt;/col&gt;
 &lt;col style=&quot;width: 70pt;&quot; width=&quot;93&quot;&gt;&lt;/col&gt;
 &lt;tbody&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;
  &lt;td height=&quot;20&quot; style=&quot;height: 15pt; width: 116pt;&quot; width=&quot;154&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/td&gt;
  &lt;td style=&quot;width: 70pt;&quot; width=&quot;93&quot;&gt;&amp;nbsp;&amp;nbsp;
  Owner&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;19&quot; style=&quot;height: 14.25pt;&quot;&gt;
  &lt;td height=&quot;19&quot; style=&quot;height: 14.25pt;&quot;&gt;-------------------------&lt;/td&gt;
  &lt;td&gt;-------------&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;
  &lt;td height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;&amp;nbsp;information_schema&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;postgres84&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;
  &lt;td height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;&amp;nbsp;pg_catalog&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;postgres84&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;
  &lt;td height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;&amp;nbsp;pg_toast&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;postgres84&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;
  &lt;td height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;&amp;nbsp;pg_toast_temp_1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;postgres84&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;
  &lt;td height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;&amp;nbsp;public&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;postgres84&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;
  &lt;td height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;&amp;nbsp;statsinfo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;postgres84&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;
  &lt;td height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;&amp;nbsp;statsrepo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;postgres84&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;/blockquote&gt;
I need to get the list of tables from&amp;nbsp; the schema &quot;statsrepo&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;
postgres=# set search_path to statsrepo;&lt;br /&gt;
postgres=# \d&lt;/blockquote&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; List of relations&lt;br /&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse; width: 348px;&quot;&gt;&lt;col style=&quot;width: 49pt;&quot; width=&quot;65&quot;&gt;&lt;/col&gt;
 
 
&lt;tbody&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;
  &lt;td height=&quot;20&quot; style=&quot;height: 15pt; width: 49pt;&quot; width=&quot;65&quot;&gt;Schema&lt;/td&gt;
  &lt;td style=&quot;width: 107pt;&quot; width=&quot;142&quot;&gt;Name&lt;/td&gt;
  &lt;td style=&quot;width: 50pt;&quot; width=&quot;67&quot;&gt;Type&lt;/td&gt;
  &lt;td style=&quot;width: 56pt;&quot; width=&quot;74&quot;&gt;Owner&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;
  &lt;td height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;---------&lt;/td&gt;
  &lt;td&gt;-----------------------&lt;/td&gt;
  &lt;td&gt;-----------&lt;/td&gt;
  &lt;td&gt;------------&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;
  &lt;td height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;statsrepo&lt;/td&gt;
  &lt;td&gt;activity&lt;/td&gt;
  &lt;td&gt;table&lt;/td&gt;
  &lt;td&gt;postgres84&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;
  &lt;td height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;statsrepo&lt;/td&gt;
  &lt;td&gt;autoanalyze&lt;/td&gt;
  &lt;td&gt;table&lt;/td&gt;
  &lt;td&gt;postgres84&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;
  &lt;td height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;...&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;
  &lt;td height=&quot;20&quot; style=&quot;height: 15pt;&quot;&gt;statsrepo&lt;/td&gt;
  &lt;td&gt;tablespace&lt;/td&gt;
  &lt;td&gt;table&lt;/td&gt;
  &lt;td&gt;postgres84&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/4287506768036567336/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://airumman.blogspot.com/2010/10/list-all-tables-from-specific-schema-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/4287506768036567336'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/4287506768036567336'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/2010/10/list-all-tables-from-specific-schema-in.html' title='List all tables from a specific schema in Postgresql'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1727938467293727772.post-1400559523549170627</id><published>2010-10-19T10:16:00.000+06:00</published><updated>2010-10-19T10:19:26.171+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CentOS"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="Postgresql"/><title type='text'>Install dblink from contrib in Postgres 8.4</title><content type='html'>Postgresql 8.4.4 was installed from source at /var/lib/pgsql84, where all the source files were at /root/postgresql-8.4.4. &lt;br /&gt;To install dblink module from contrib, I followed the steps:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;
cd /root/postgresql-8.4.4/contrib/dblink&lt;br /&gt;
make install&lt;br /&gt;
------&lt;br /&gt;
/bin/sh ../../config/mkinstalldirs &#39;/var/lib/pgsql84/lib&#39;&lt;br /&gt;mkdir -p -- /var/lib/pgsql84/share/contrib&lt;br /&gt;/bin/sh ../../config/install-sh -c -m 755&amp;nbsp; dblink.so &#39;/var/lib/pgsql84/lib/dblink.so&#39;&lt;br /&gt;/bin/sh ../../config/install-sh -c -m 644 ./uninstall_dblink.sql &#39;/var/lib/pgsql84/share/contrib&#39;&lt;br /&gt;/bin/sh ../../config/install-sh -c -m 644 dblink.sql &#39;/var/lib/pgsql84/share/contrib&#39;&lt;/blockquote&gt;
&lt;blockquote&gt;
------&lt;br /&gt;&lt;br /&gt;ls&lt;br /&gt;dblink.c&amp;nbsp; dblink.h&amp;nbsp; dblink.o&amp;nbsp; dblink.so&amp;nbsp; dblink.sql&amp;nbsp; dblink.sql.in&amp;nbsp; expected&amp;nbsp; Makefile&amp;nbsp; sql&amp;nbsp; uninstall_dblink.sql&lt;/blockquote&gt;
&lt;br /&gt;Now dblink.sql was executed in order to create the required functions in template1 database.&lt;br /&gt;&lt;br /&gt;
&lt;blockquote&gt;
/var/lib/pgsql84/bin/psql -U postgres84 template1 -f dblink.sql&lt;br /&gt;/var/lib/pgsql84/bin/psql -U postgres84 template1&lt;br /&gt;select dblink_connect(&#39;statcollector51&#39;,&#39;hostaddr=10.0.0.51 port=5432 dbname=testdb user=testuser password=testpwd&#39;);&lt;/blockquote&gt;</content><link rel='replies' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/1400559523549170627/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://airumman.blogspot.com/2010/10/install-dblink-from-contrib-in-postgres.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/1400559523549170627'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/1400559523549170627'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/2010/10/install-dblink-from-contrib-in-postgres.html' title='Install dblink from contrib in Postgres 8.4'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1727938467293727772.post-543702975755251867</id><published>2010-10-18T23:57:00.000+06:00</published><updated>2010-10-18T23:57:56.196+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CentOS"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="Postgresql"/><title type='text'>Install Postgresql 8.3 using YUM in CentOS 5</title><content type='html'>In order to use Postgresql 8.3 using YUM in CentOS 5, pgdg repo configuration file can be used.&lt;br /&gt;&lt;blockquote&gt;
su - root&lt;br /&gt;cd /etc/yum.repos.d&lt;br /&gt;ls&lt;br /&gt;C5base.repo&amp;nbsp;&amp;nbsp; C5updates.repo&amp;nbsp;&amp;nbsp; CentOS-Base.repo&amp;nbsp;&amp;nbsp; CentOS-Media.repo&lt;/blockquote&gt;
&lt;br /&gt;Download pgdg-centos-8.3-7.noarch from&lt;br /&gt;
&lt;a href=&quot;http://yum.pgsqlrpms.org/reporpms/repoview/pgdg-centos.html&quot;&gt;yum.pgsqlrpms.org/reporpms/repoview/pgdg-centos.html&lt;/a&gt;.&lt;br /&gt;rpm -ivh pgdg-centos-8.3-7.noarch&lt;br /&gt;That is, I got&amp;nbsp; pgdg-83-centos.repo in my /etc/yum.repos.d and now I had to make sure yum installer use this repo configuration file for postgresql.&lt;br /&gt;&lt;br /&gt;For this, I added &lt;br /&gt;exclude=postgresql*&lt;br /&gt;to the bottom of the each section of other repos in order to exclude distro packages.&lt;br /&gt;&lt;br /&gt;
&lt;blockquote&gt;
vi C5base.repo&lt;br /&gt;-------------------&lt;br /&gt;[C5base]&lt;br /&gt;name=C5base&lt;br /&gt;baseurl=http://10.0.0.7/cobbler/repo_mirror/C5base&lt;br /&gt;enabled=1&lt;br /&gt;priority=1&lt;br /&gt;gpgcheck=0&lt;br /&gt;exclude=postgresql*&lt;br /&gt;-------------------&lt;/blockquote&gt;
&lt;br /&gt;
&lt;blockquote&gt;
vi CentOS-Base.repo&lt;br /&gt;--------------------&lt;br /&gt;[base]&lt;br /&gt;name=CentOS-5 - Base&lt;br /&gt;enabled=1&lt;br /&gt;mirrorlist=http://mirrorlist.centos.org/?release=5&amp;amp;arch=i386&amp;amp;repo=os&lt;br /&gt;#baseurl=http://mirror.centos.org/centos/5/os/i386/&lt;br /&gt;gpgcheck=1&lt;br /&gt;gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5&lt;br /&gt;priority=1&lt;br /&gt;exclude=postgresql*&lt;br /&gt;&lt;br /&gt;#released updates &lt;br /&gt;[updates]&lt;br /&gt;name=CentOS-5 - Updates&lt;br /&gt;enabled=1&lt;br /&gt;mirrorlist=http://mirrorlist.centos.org/?release=5&amp;amp;arch=i386&amp;amp;repo=updates&lt;br /&gt;#baseurl=http://mirror.centos.org/centos/5/updates/i386/&lt;br /&gt;gpgcheck=1&lt;br /&gt;gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5&lt;br /&gt;priority=1&lt;br /&gt;exclude=postgresql*&lt;br /&gt;-------------------------&lt;/blockquote&gt;
I checked that pgdg repo configuration file was using.&lt;br /&gt;
&lt;blockquote&gt;
yum list postgres&lt;br /&gt;...&lt;br /&gt;Loading mirror speeds from cached hostfile&lt;br /&gt;&amp;nbsp;* pgdg83: yum.pgrpms.org&lt;br /&gt;...&lt;br /&gt;postgresql.i386&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8.3.12-1PGDG.rhel5&lt;br /&gt;...&lt;/blockquote&gt;
Everything was correct and I started Postgresql installation from yum.&lt;br /&gt;&lt;br /&gt;
&lt;blockquote&gt;
yum install postgres&lt;br /&gt;yum install postgres-server&lt;br /&gt;&lt;br /&gt;adduser postgres&lt;br /&gt;groupadd postgres&lt;br /&gt;chown -R postgres:postgres /var/lib/pgsql&lt;br /&gt;su - postgres&lt;br /&gt;vi .bash_profile&lt;br /&gt;----------------&lt;br /&gt;...&lt;br /&gt;export PGDATA=/var/lib/pgsql/data&lt;br /&gt;...&lt;br /&gt;----------------&lt;/blockquote&gt;
Now, initdb is used in order to create postgresql cluster and other configuraton steps were followed according to the postgresql manual.&lt;br /&gt;&lt;br /&gt;
For reference, read the followings:&lt;br /&gt;&lt;a href=&quot;http://yum.pgrpms.org/howtoyum.php&quot;&gt;http://yum.pgrpms.org/howtoyum.php &lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.postgresonline.com/journal/index.php?/archives/45-An-Almost-Idiots-Guide-to-PostgreSQL-YUM.html&quot;&gt;http://www.postgresonline.com/journal/index.php?/archives/45-An-Almost-Idiots-Guide-to-PostgreSQL-YUM.html&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/543702975755251867/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://airumman.blogspot.com/2010/10/install-postgresql-83-using-yum-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/543702975755251867'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/543702975755251867'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/2010/10/install-postgresql-83-using-yum-in.html' title='Install Postgresql 8.3 using YUM in CentOS 5'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1727938467293727772.post-3982188368252668913</id><published>2010-10-17T19:47:00.002+06:00</published><updated>2010-10-17T20:00:52.382+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Postgresql"/><title type='text'>Migrate a database from Postgresql 8.1 to 8.4</title><content type='html'>I need to migrate a 11 GB database from Postgresql 8.1 to Postgresql 8.4. The database was for CRM application.&amp;nbsp; 
&lt;br /&gt;
&lt;b&gt;At the source server:&lt;/b&gt;
&lt;br /&gt;
Take backup of the Database:
&lt;br /&gt;
&lt;blockquote&gt;
pg_dump &amp;lt;db_name&amp;gt; -Fc -v &amp;gt; /tmp/db_backup.sqlc&lt;/blockquote&gt;
Copy this backup to the new server:&lt;br /&gt;
&lt;blockquote&gt;
scp /tmp/db_backup.sqlc postgres@x.x.x.x:/tmp/&lt;/blockquote&gt;
&lt;b&gt;At the destination server:&lt;/b&gt;
&lt;br /&gt;
Connected to the new server using ssh client.&lt;br /&gt;
&lt;br /&gt;
Installed Postgresql 8.4 using the following rpms in my Centos 5:&lt;br /&gt;
- postgresql-8.4.4-1PGDG.rhel5.x86_64.rpm&lt;br /&gt;
- postgresql-libs-8.4.4-1PGDG.rhel5.x86_64.rpm&lt;br /&gt;
- postgresql-server-8.4.4-1PGDG.rhel5.x86_64.rpm&lt;br /&gt;
&lt;br /&gt;
Check that Postrgesql server is running:&lt;br /&gt;
&lt;blockquote&gt;
$su - postgres&lt;br /&gt;
$pg_ctl status&lt;/blockquote&gt;
Set maintenance_work_mem to a high value for improvement in DB restore operation. I set it to 1 GB.&lt;br /&gt;
&lt;blockquote&gt;
-----------------------------&lt;br /&gt;
vi $PGDATA/postgresql.conf&lt;br /&gt;
...&lt;br /&gt;
maintenance_work_mem = 1024M&lt;br /&gt;
...&lt;br /&gt;
:wq&lt;br /&gt;
-----------------------------&lt;/blockquote&gt;
&amp;nbsp;At psql console:&lt;br /&gt;
&lt;blockquote&gt;
create user &amp;lt;my_user&amp;gt; with password &#39;password&#39; superuser;&lt;br /&gt;
create database &amp;lt;db_name&amp;gt; owner &amp;lt;my_user&amp;gt;;&lt;br /&gt;
\q&lt;/blockquote&gt;
At shell console:&lt;br /&gt;
&lt;blockquote&gt;
pg_restore -d &amp;lt;db_name&amp;gt; -v /tmp/db_backup.sqlc&lt;/blockquote&gt;
When this restore operation is complete, I found some FATAL ERROR in my application for query failure and these were occurred as Postgresql 8.4 does not have some implicit casting as 8.1.&lt;br /&gt;
To solve it, I executed the following commands at psql console: &lt;br /&gt;
&lt;blockquote&gt;
---------------------------------------------------------------&lt;br /&gt;
CREATE FUNCTION pg_catalog.text(integer) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS &#39;SELECT textin(int4out($1));&#39;;&lt;br /&gt;
CREATE CAST (integer AS text) WITH FUNCTION pg_catalog.text(integer) AS IMPLICIT;&lt;br /&gt;
CREATE FUNCTION pg_catalog.text(smallint) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS &#39;SELECT textin(int2out($1));&#39;;&lt;br /&gt;
CREATE CAST (smallint AS text) WITH FUNCTION pg_catalog.text(smallint) AS IMPLICIT;&lt;br /&gt;
CREATE FUNCTION pg_catalog.text(oid) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS &#39;SELECT textin(oidout($1));&#39;;&lt;br /&gt;
CREATE CAST (oid AS text) WITH FUNCTION pg_catalog.text(oid) AS IMPLICIT;&lt;br /&gt;
CREATE FUNCTION pg_catalog.text(date) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS &#39;SELECT textin(date_out($1));&#39;;&lt;br /&gt;
CREATE CAST (date AS text) WITH FUNCTION pg_catalog.text(date) AS IMPLICIT;&lt;br /&gt;
CREATE FUNCTION pg_catalog.text(double precision) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS &#39;SELECT textin(float8out($1));&#39;;&lt;br /&gt;
CREATE CAST (double precision AS text) WITH FUNCTION pg_catalog.text(double precision) AS IMPLICIT;&lt;br /&gt;
CREATE FUNCTION pg_catalog.text(real) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS &#39;SELECT textin(float4out($1));&#39;;&lt;br /&gt;
CREATE CAST (real AS text) WITH FUNCTION pg_catalog.text(real) AS IMPLICIT;&lt;br /&gt;
CREATE FUNCTION pg_catalog.text(time with time zone) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS &#39;SELECT textin(timetz_out($1));&#39;;&lt;br /&gt;
CREATE CAST (time with time zone AS text) WITH FUNCTION pg_catalog.text(time with time zone) AS IMPLICIT;&lt;br /&gt;
CREATE FUNCTION pg_catalog.text(time without time zone) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS &#39;SELECT textin(time_out($1));&#39;;&lt;br /&gt;
CREATE CAST (time without time zone AS text) WITH FUNCTION pg_catalog.text(time without time zone) AS IMPLICIT;&lt;br /&gt;
CREATE FUNCTION pg_catalog.text(timestamp with time zone) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS &#39;SELECT textin(timestamptz_out($1));&#39;;&lt;br /&gt;
CREATE CAST (timestamp with time zone AS text) WITH FUNCTION pg_catalog.text(timestamp with time zone) AS IMPLICIT;&lt;br /&gt;
CREATE FUNCTION pg_catalog.text(interval) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS &#39;SELECT textin(interval_out($1));&#39;;&lt;br /&gt;
CREATE CAST (interval AS text) WITH FUNCTION pg_catalog.text(interval) AS IMPLICIT;&lt;br /&gt;
CREATE FUNCTION pg_catalog.text(bigint) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS &#39;SELECT textin(int8out($1));&#39;;&lt;br /&gt;
CREATE CAST (bigint AS text) WITH FUNCTION pg_catalog.text(bigint) AS IMPLICIT;&lt;br /&gt;
CREATE FUNCTION pg_catalog.text(numeric) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS &#39;SELECT textin(numeric_out($1));&#39;;&lt;br /&gt;
CREATE CAST (numeric AS text) WITH FUNCTION pg_catalog.text(numeric) AS IMPLICIT;&lt;br /&gt;
CREATE FUNCTION pg_catalog.text(timestamp without time zone) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS &#39;SELECT textin(timestamp_out($1));&#39;;&lt;br /&gt;
CREATE CAST (timestamp without time zone AS text) WITH FUNCTION pg_catalog.text(timestamp without time zone) AS IMPLICIT;&lt;br /&gt;
---------------------------------------------------------------&lt;/blockquote&gt;</content><link rel='replies' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/3982188368252668913/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://airumman.blogspot.com/2010/10/migrate-database-from-postgresql-81-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/3982188368252668913'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/3982188368252668913'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/2010/10/migrate-database-from-postgresql-81-to.html' title='Migrate a database from Postgresql 8.1 to 8.4'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1727938467293727772.post-7547433360918054805</id><published>2010-10-17T15:21:00.007+06:00</published><updated>2010-10-17T19:24:01.498+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Postgresql"/><title type='text'>Modify the value of DB parameters in Postgresql</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;Often for different purposes we need to modify the value of database parameters. &lt;br /&gt;
Following command can be used from psql console to change the value of a parameter.&lt;br /&gt;
&lt;blockquote&gt;$psql –d bench_replication –U newuser&lt;br /&gt;
psql=#&amp;nbsp; show statement_timeout;&lt;br /&gt;
0ms&lt;br /&gt;
psql=# set statement_timeout=10;&lt;br /&gt;
psql=#&amp;nbsp; show statement_timeout;&lt;br /&gt;
10ms&lt;/blockquote&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Sometimes we need to restart the DB server after parameter’s value modification to take effect and sometimes a sighup signal is enough.&amp;nbsp; This is easily be identified when we need to restart DB server based on the context of the parameter. &lt;/div&gt;&lt;br /&gt;
Postgresql DB parameters can be categorized into 6 types on the basis of context and these are:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;- user&lt;/li&gt;
&lt;li&gt;- superuser&lt;/li&gt;
&lt;li&gt;- sighup&lt;/li&gt;
&lt;li&gt;- backend&lt;/li&gt;
&lt;li&gt;- postmaster&lt;/li&gt;
&lt;li&gt;- internal&lt;/li&gt;
&lt;/ul&gt;Following query gives us the context of a parameter:&lt;br /&gt;
&lt;blockquote&gt;Select context &lt;br /&gt;
from pg_settings &lt;br /&gt;
where name = &amp;lt;parameter_name&amp;gt;&lt;/blockquote&gt;Following table shows us when we need to restart the DB server in order to take effect the parameter modification:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcSmBsNFtxV6NDIH73S7nXXZXWktinAxnH4BX_kQO6DXGGjEU9C9D_b5huP7NPlFix3i719X4GNd4uW-gvLQovIBYebas8PJWPzuUi4iMjv4NBxsMcsQYC18SyJfCp3tG1TR23nXQzXYQ/s1600/tab.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;95&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcSmBsNFtxV6NDIH73S7nXXZXWktinAxnH4BX_kQO6DXGGjEU9C9D_b5huP7NPlFix3i719X4GNd4uW-gvLQovIBYebas8PJWPzuUi4iMjv4NBxsMcsQYC18SyJfCp3tG1TR23nXQzXYQ/s320/tab.JPG&quot; width=&quot;90%&quot; /&gt;&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/7547433360918054805/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://airumman.blogspot.com/2010/10/modify-value-of-db-parameters-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/7547433360918054805'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/7547433360918054805'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/2010/10/modify-value-of-db-parameters-in.html' title='Modify the value of DB parameters in Postgresql'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcSmBsNFtxV6NDIH73S7nXXZXWktinAxnH4BX_kQO6DXGGjEU9C9D_b5huP7NPlFix3i719X4GNd4uW-gvLQovIBYebas8PJWPzuUi4iMjv4NBxsMcsQYC18SyJfCp3tG1TR23nXQzXYQ/s72-c/tab.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1727938467293727772.post-5900429184103489047</id><published>2010-10-17T12:13:00.002+06:00</published><updated>2010-10-17T12:15:52.304+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Postgresql"/><title type='text'>Modify all primary key ID columns&#39; data type in Postgresql 8.1</title><content type='html'>I had to modify all primary key ID columns&#39; data type from integer to biginteger in Postgresql 8.1. I created two functions for this purpose.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Function unnest :&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
Thia is used for expanding an array into a set of rows.&lt;br /&gt;
I got it from &lt;a href=&quot;http://wiki.postgresql.org/wiki/Array_Unnest&quot;&gt;wiki.postgresql.org/wiki/Array_Unnest&lt;/a&gt;&lt;br /&gt;
&lt;blockquote&gt;CREATE OR REPLACE FUNCTION unnest(anyarray)&lt;br /&gt;
&amp;nbsp; RETURNS SETOF anyelement AS&lt;br /&gt;
$BODY$&lt;br /&gt;
SELECT $1[i] FROM&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; generate_series(array_lower($1,1),&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array_upper($1,1)) i;&lt;br /&gt;
$BODY$&lt;br /&gt;
&amp;nbsp; LANGUAGE &#39;sql&#39; IMMUTABLE&lt;/blockquote&gt;&lt;b&gt;Function modify_id_type_f:&lt;/b&gt;&lt;br /&gt;
This is function is used to modify the data type of the primary key columns.&lt;br /&gt;
&lt;blockquote&gt;CREATE OR REPLACE FUNCTION modify_id_type_f() RETURNS void AS $$&lt;br /&gt;
DECLARE&lt;br /&gt;
v_rec RECORD;&lt;br /&gt;
&lt;br /&gt;
BEGIN&lt;br /&gt;
&lt;br /&gt;
FOR v_rec IN &lt;br /&gt;
(&lt;br /&gt;
select tab_cols.table_name, tab_cols.col_name, tab_cols.col_type ,&lt;br /&gt;
&#39;alter table &#39;|| tab_cols.table_name ||&#39; alter &#39;|| tab_cols.col_name&amp;nbsp; ||&#39; type &#39;|| &#39; bigint &#39; as str &lt;br /&gt;
from&lt;br /&gt;
(&lt;br /&gt;
select relid as table_id,relname as table_name, a.attname as col_name,&amp;nbsp; t.typname as col_type, a.attnum, a.atttypid&lt;br /&gt;
from pg_stat_user_tables as c &lt;br /&gt;
inner join&amp;nbsp;&amp;nbsp; pg_attribute as a&amp;nbsp; on c.relid = a.attrelid&amp;nbsp; and a.attnum &amp;gt; 0&lt;br /&gt;
inner join pg_type as t on a.atttypid = t.oid&lt;br /&gt;
) as tab_cols &lt;br /&gt;
inner join&lt;br /&gt;
(&lt;br /&gt;
select relid as table_id, relname, si.indexrelname, unnest(i.indkey) as ind_cols&lt;br /&gt;
from pg_stat_user_indexes as si&lt;br /&gt;
inner join pg_index as i on si.indexrelid&amp;nbsp; = i.indexrelid&lt;br /&gt;
where i.indisprimary = true&lt;br /&gt;
) as ind_cols&lt;br /&gt;
on tab_cols.table_id =&amp;nbsp; ind_cols.table_id and&amp;nbsp;&amp;nbsp; tab_cols.attnum = ind_cols.ind_cols &lt;br /&gt;
where tab_cols.col_type = &#39;int4&#39;&lt;br /&gt;
)&lt;br /&gt;
LOOP&lt;br /&gt;
&lt;br /&gt;
--RAISE NOTICE &#39;Dname=%&#39;,v_rec.str;&lt;br /&gt;
EXECUTE v_rec.str;&lt;br /&gt;
END LOOP;&lt;br /&gt;
END;&lt;br /&gt;
$$ LANGUAGE plpgsql;&lt;/blockquote&gt;</content><link rel='replies' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/5900429184103489047/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://airumman.blogspot.com/2010/10/modify-all-primary-key-id-columns-data.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/5900429184103489047'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/5900429184103489047'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/2010/10/modify-all-primary-key-id-columns-data.html' title='Modify all primary key ID columns&#39; data type in Postgresql 8.1'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1727938467293727772.post-8160855974451505456</id><published>2010-10-16T18:54:00.000+06:00</published><updated>2010-10-16T18:54:16.913+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Postgresql"/><title type='text'>Query to get database size and location in Postgresql</title><content type='html'>&lt;b&gt;Postgresql 8.1&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
select d.oid, datname,datdba, pg_size_pretty(pg_database_size(datname)) as size, t.*&lt;br /&gt;
from pg_database as d&lt;br /&gt;
inner join pg_tablespace as t on&amp;nbsp; ( d.dattablespace&amp;nbsp; = t.oid)&lt;br /&gt;
order by pg_database_size(datname)&amp;nbsp; desc</content><link rel='replies' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/8160855974451505456/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://airumman.blogspot.com/2010/10/query-to-get-database-size-and-location.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/8160855974451505456'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/8160855974451505456'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/2010/10/query-to-get-database-size-and-location.html' title='Query to get database size and location in Postgresql'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1727938467293727772.post-3366019689326178794</id><published>2010-10-16T16:13:00.001+06:00</published><updated>2010-10-17T09:51:19.509+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Oracle"/><title type='text'>Index tune using job scheduler in Oracle 10g</title><content type='html'>Indexes are the key element for any Database Tuning. In Oracle 10g, REBUILD ONLINE is one of the key features that makes it possible to reorganize the indexes during production time.&lt;br /&gt;
An index should be considered for rebuilding under any of the following conditions:&lt;br /&gt;
• The percentage of deleted rows exceeds 30% of the total, i.e. if DEL_LF_ROWS / LF_ROWS &amp;gt; 0.3.&lt;br /&gt;
• If the ‘HEIGHT’ is greater than 4.&lt;br /&gt;
• If the number of rows in the index (‘LF_ROWS’) is significantly smaller than ‘LF_BLKS’ this can indicate a large number of deletes, indicating that the index should be rebuilt.&lt;br /&gt;
• BLOCK_GETS greater than 5&lt;br /&gt;
&lt;br /&gt;
In our system we have 180000 indexes. So rebuilding manually is not an easy task. So, we considered job scheduler for index rebuilding.&lt;br /&gt;
&lt;b&gt;Steps:&lt;/b&gt;&lt;br /&gt;
1. Create a table TEMP_INDEX_STAT, which is similar to INDEX_STATS&lt;br /&gt;
2. Create a procedure GEN_INDEX_STAT. It will analyze an index and store that data in TEMP_INDEX_STAT&lt;br /&gt;
3. Create a job class LOW_PRIORITY_CLASS with LOW_GROUP resource consumer group, so that the job might not hamper production transaction.&lt;br /&gt;
4. Create a job GET_INDEX_STAT_JOB&lt;br /&gt;
5. Create a table RUNNING_CMDS&lt;br /&gt;
6. Create a procedure REBUILD_INDEX, which will REBUILD the indexes&lt;br /&gt;
7. Create another job REBUILD_INDEX_JOB. This job will call the above procedure to rebuild the indexes.&lt;br /&gt;
&lt;br /&gt;
Please be sure that the load in the database is not at the peak. If yes, you may get resource timeout error during the job execution period and the job may be failed.&lt;br /&gt;
&lt;br /&gt;
Scripts:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;1. A temporary table&amp;nbsp; TEMP_INDEX_STAT created to store the index statistics.&lt;/b&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;br /&gt;
&amp;nbsp;CREATE TABLE TEMP_INDEX_STAT&lt;br /&gt;
AS&lt;br /&gt;
SELECT *&lt;br /&gt;
FOR INDEX_STATS&lt;br /&gt;
WHERE 1=2;&lt;/blockquote&gt;&lt;br /&gt;
&lt;b&gt;2. Create procedure GEN_INDEX_STAT to generate index statistics and store&lt;/b&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;br /&gt;
CREATE OR REPLACE PROCEDURE GEN_INDEX_STAT&lt;br /&gt;
(PRM_SCHEMA VARCHAR2)&lt;br /&gt;
IS&lt;br /&gt;
CURSOR INDEX_CUR IS&lt;br /&gt;
SELECT INDEX_NAME&lt;br /&gt;
FROM DBA_INDEXES d&lt;br /&gt;
WHERE OWNER = prm_schema&lt;br /&gt;
AND NOT EXISTS&lt;br /&gt;
(&lt;br /&gt;
SELECT 1&lt;br /&gt;
FROM temp_index_stat b&lt;br /&gt;
WHERE d.index_Name = b.NAME&lt;br /&gt;
)&lt;br /&gt;
AND INDEX_TYPE = &#39;NORMAL&#39;;&lt;br /&gt;
;&lt;br /&gt;
v_str VARCHAR2(500);&lt;br /&gt;
BEGIN&lt;br /&gt;
FOR INDEX_REC IN INDEX_CUR LOOP&lt;br /&gt;
v_str := &#39;ANALYZE INDEX&lt;br /&gt;
&#39;||PRM_SCHEMA||&#39;.&#39;||INDEX_REC.INDEX_NAME||&#39;&lt;br /&gt;
VALIDATE STRUCTURE &#39;;&lt;br /&gt;
EXECUTE IMMEDIATE v_str;&lt;br /&gt;
v_str := &#39;insert into TEMP_INDEX_STAT select * from index_stats&#39;;&lt;br /&gt;
EXECUTE IMMEDIATE v_str;&lt;br /&gt;
COMMIT;&lt;br /&gt;
END LOOP; --&lt;br /&gt;
END GEN_INDEX_STAT; &lt;/blockquote&gt;&lt;br /&gt;
&lt;b&gt;3. Create a job class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;begin&lt;br /&gt;
dbms_scheduler.create_job_class(&lt;br /&gt;
job_class_name =&amp;gt; &#39;LOW_PRIORITY_CLASS&#39;,&lt;br /&gt;
resource_consumer_group =&amp;gt; &#39;LOW_GROUP&#39;,&lt;br /&gt;
logging_level =&amp;gt; DBMS_SCHEDULER.LOGGING_FULL,&lt;br /&gt;
log_history =&amp;gt; 60,&lt;br /&gt;
comments =&amp;gt; &#39;LOW PRIORITY JOB CLASS&#39;);&lt;br /&gt;
end;&lt;/blockquote&gt;&lt;br /&gt;
&lt;b&gt;4. Create a job &lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
You may set START_DATE if you want to schedule the following job.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;BEGIN&lt;br /&gt;
dbms_scheduler.create_job&lt;br /&gt;
(&lt;br /&gt;
job_name=&amp;gt; &#39;GEN_INDEX_STAT_JOB&#39;,&lt;br /&gt;
job_type=&amp;gt; &#39;PLSQL_BLOCK&#39;,&lt;br /&gt;
job_action=&amp;gt;&#39;begin GEN_INDEX_STAT(&#39;&#39;T24&#39;&#39;); end;&#39;,&lt;br /&gt;
START_DATE=&amp;gt;NULL,&lt;br /&gt;
REPEAT_INTERVAL=&amp;gt;NULL,&lt;br /&gt;
ENABLED=&amp;gt;TRUE,&lt;br /&gt;
AUTO_DROP=&amp;gt;FALSE,&lt;br /&gt;
COMMENTS=&amp;gt;&#39;Generate Index Stat&#39;,&lt;br /&gt;
job_class=&amp;gt;&#39;LOW_PRIORITY_CLASS&#39;&lt;br /&gt;
);&lt;br /&gt;
END;&lt;/blockquote&gt;&lt;br /&gt;
Upto this point, we have collected statistics for all indexes in our schema. &lt;br /&gt;
Now we need to REBUILD the indexes according to the conditions described above.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Create a table to log the operations&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;CREATE TABLE RUNNING_CMDS&lt;br /&gt;
(&lt;br /&gt;
CMD VARCHAR2(200)&lt;br /&gt;
)&lt;/blockquote&gt;This table will store the commands so that we could easily identify which index is in rebuild process during the running of the following job.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Procedure to rebuild index&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;CREATE OR REPLACE PROCEDURE REBUILD_INDEX(PRM_SCHEMA VARCHAR2)&lt;br /&gt;
IS&lt;br /&gt;
CURSOR CUR IS&lt;br /&gt;
SELECT NAME&lt;br /&gt;
FROM TEMP_INDEX_STAT a&lt;br /&gt;
WHERE (HEIGHT &amp;gt;= 4&lt;br /&gt;
OR&lt;br /&gt;
(del_lf_rows/lf_rows &amp;gt; 0.3 AND lf_rows &amp;gt; 0)&lt;br /&gt;
or (blks_gets_per_access &amp;gt; 4)&lt;br /&gt;
)&lt;br /&gt;
AND EXISTS&lt;br /&gt;
(&lt;br /&gt;
SELECT 1&lt;br /&gt;
FROM dba_indexes d&lt;br /&gt;
WHERE a.NAME = D.index_name&lt;br /&gt;
AND d.index_type &amp;lt;&amp;gt; &#39;LOB&#39;&lt;br /&gt;
);&lt;br /&gt;
v_str varchar2(200);&lt;br /&gt;
&lt;br /&gt;
BEGIN&lt;br /&gt;
execute immediate &#39;truncate table RUNNING_CMDS&#39;;&lt;br /&gt;
FOR REC IN CUR LOOP&lt;br /&gt;
v_str := &#39;ALTER INDEX &#39;||PRM_SCHEMA||&#39;.&#39;||REC.NAME||&#39; REBUILD ONLINE&#39;;&lt;br /&gt;
INSERT INTO RUNNING_CMDS&lt;br /&gt;
VALUES(V_STR);&lt;br /&gt;
COMMIT;&lt;br /&gt;
EXECUTE IMMEDIATE v_str;&lt;br /&gt;
END LOOP;&lt;br /&gt;
END REBUILD_INDEX; &lt;/blockquote&gt;&lt;br /&gt;
&lt;b&gt;8. Create a job to execute index rebuilding process&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;BEGIN&lt;br /&gt;
dbms_scheduler.create_job&lt;br /&gt;
(&lt;br /&gt;
job_name=&amp;gt; &#39;REBUILD_INDEX_JOB&#39;,&lt;br /&gt;
job_type=&amp;gt; &#39;PLSQL_BLOCK&#39;,&lt;br /&gt;
job_action=&amp;gt;&#39;begin REBUILD_INDEX(&#39;&#39;T24&#39;&#39;); end;&#39;,&lt;br /&gt;
START_DATE=&amp;gt;NULL,&lt;br /&gt;
REPEAT_INTERVAL=&amp;gt;NULL,&lt;br /&gt;
ENABLED=&amp;gt;TRUE,&lt;br /&gt;
AUTO_DROP=&amp;gt;FALSE,&lt;br /&gt;
COMMENTS=&amp;gt;&#39;Rebuild Index&#39;,&lt;br /&gt;
job_class=&amp;gt;&#39;LOW_PRIORITY_CLASS&#39;&lt;br /&gt;
);&lt;br /&gt;
END; &lt;/blockquote&gt;&lt;br /&gt;
You may set START_TIME according to your requirement.</content><link rel='replies' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/3366019689326178794/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://airumman.blogspot.com/2010/10/index-tune-using-job-scheduler-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/3366019689326178794'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/3366019689326178794'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/2010/10/index-tune-using-job-scheduler-in.html' title='Index tune using job scheduler in Oracle 10g'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1727938467293727772.post-3870959693824014786</id><published>2010-10-15T19:43:00.004+06:00</published><updated>2010-10-19T20:44:28.150+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Oracle"/><title type='text'>Delete all records of all tables of a database schema in Oracle</title><content type='html'>&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Once I found a question in a forum where an user, who was using Oracle, needed to delete all records from all tables in a schema and he had only DML privileges on that schema. Even he was not able to execute expdp in the database. I wrote the following two procedures for him and he was quite happy.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;blockquote style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;CREATE OR REPLACE PROCEDURE p_del_tab &lt;br /&gt;
&amp;nbsp;( prm_table VARCHAR2 )&lt;/b&gt;&lt;br /&gt;
IS&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;/*&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;This procedure deletes all record from a table and if ORA-02292: occurs then recursively call the procedure again. &lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;*/&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;v_str VARCHAR2(500);&lt;br /&gt;
&lt;br /&gt;
BEGIN&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;EXECUTE IMMEDIATE &#39;DELETE FROM &#39;||prm_table;&lt;br /&gt;
&lt;br /&gt;
EXCEPTION&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;WHEN OTHERS THEN&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;--ORA-02292: integrity constraint (SCOTT.FK_DEPTNO) violated - child record found&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;v_str := SQLERRM;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;v_str := SUBSTR(v_str,INSTR(v_str,&#39;.&#39;)+1, INSTR(v_str,&#39;)&#39;)&amp;nbsp; -INSTR(v_str,&#39;.&#39;)-1&amp;nbsp; );&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;DECLARE&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;CURSOR cur IS&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;SELECT table_name&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;FROM user_constraints&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;WHERE constraint_name = v_str;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;BEGIN&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;FOR rec IN cur LOOP&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;P_DEL_tab(rec.table_name);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;END LOOP; &lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;END;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;p_del_tab(prm_table); &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;END p_del_tab;&lt;/b&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;br /&gt;
&lt;blockquote&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;CREATE OR REPLACE PROCEDURE p_del_all_data&lt;/span&gt;&lt;/b&gt;&lt;br style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot; /&gt;&lt;span style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;IS&lt;/span&gt;&lt;br style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot; /&gt;&lt;span style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;/* This procedure calls p_del_tab */&lt;/span&gt;&lt;br style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot; /&gt;&lt;br style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot; /&gt;&lt;span style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CURSOR cur IS&lt;/span&gt;&lt;br style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot; /&gt;&lt;span style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT table_name&lt;/span&gt;&lt;br style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot; /&gt;&lt;span style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM user_tables;&lt;/span&gt;&lt;br style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot; /&gt;&lt;br style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot; /&gt;&lt;span style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;BEGIN&lt;/span&gt;&lt;br style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot; /&gt;&lt;br style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot; /&gt;&lt;span style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&amp;nbsp;&amp;nbsp; FOR rec IN cur LOOP&lt;/span&gt;&lt;br style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot; /&gt;&lt;span style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p_del_tab(rec.table_name);&lt;/span&gt;&lt;br style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot; /&gt;&lt;span style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&amp;nbsp;&amp;nbsp; END LOOP;&lt;/span&gt;&lt;br style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot; /&gt;&lt;br style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot; /&gt;&lt;span style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;EXCEPTION&lt;/span&gt;&lt;br style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot; /&gt;&lt;br style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot; /&gt;&lt;span style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHEN OTHERS THEN&lt;/span&gt;&lt;br style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot; /&gt;&lt;span style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; DBMS_OUTPUT.PUT_LINE(&#39;p_del_all_data: &#39;||SQLERRM);&lt;/span&gt;&lt;br style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot; /&gt;&lt;br style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot; /&gt;&lt;b&gt;&lt;span style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;END &lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;p_del_all_data&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/blockquote&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;Now execute p_del_all_data:&lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;blockquote&gt;
BEGIN&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; p_del_all_data;&lt;br /&gt;
&lt;br /&gt;
END;&lt;/blockquote&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;Remember you will be in trouble if you have many-to-many relationship like&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;DEPT has a column reference to COUNTRY and COUNTRY has a column reference to DEPT at that time you will be in infinite recursive call loop; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/3870959693824014786/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://airumman.blogspot.com/2010/10/deleting-all-records-of-all-tables-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/3870959693824014786'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/3870959693824014786'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/2010/10/deleting-all-records-of-all-tables-of.html' title='Delete all records of all tables of a database schema in Oracle'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1727938467293727772.post-4111961977432907342</id><published>2010-10-15T15:02:00.008+06:00</published><updated>2010-12-23T16:25:48.402+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Mysql"/><title type='text'>Mysql-proxy installation and  filter “SHOW TABLES”</title><content type='html'>&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;What is Mysql-proxy?&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;MYSQL Proxy is a simple program that sits between the  client and MySQL server(s) that can monitor, analyze or transform their communication. Its flexibility allows for unlimited uses; common ones include:&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;• load balancing &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;• failover &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;• query analysis &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;• query filtering and modification &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;• ... and many more&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;Reason for mysql-proxy installation&lt;/span&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif; text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;I have been maintaining a 150 GB Mysql 5.1 Community Version Database with 1300000 tables. The database consists of all MYISAM tables. So, whenever a “SHOW TABLES” command is executed in the Database the server gets halt. As Mysql 5.1 has no privilege for SHOW TABLES, I used mysql-proxy between the web server and DB server.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif; text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Download required software&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;I downloaded mysql-proxy binary distribution for “Linux – Generic” from dev.mysql.com/downloads/mysql-proxy/ as my server’s operating was Centos 5.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;LUA is a scripting language which is required for mysql-proxy scripting. I downloaded the following lua rpms from rpm.pbone.net.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Step 1: Install LUA&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;rpm -ivh lua50-5.0.3-1.i386.rpm lua50-devel-5.0.3-1.i386.rpm lua50&amp;nbsp; \ &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -libs-5.0.3-1.i386.rpm&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Step 2: Extract mysql-proxy &lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;cd /root/&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;tar -zxvf mysql-proxy-0.8.1-linux-glibc2.3-x86-32bit.tar.gz&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;cp -R mysql-proxy-0.8.1-linux-glibc2.3-x86-32bit /var/lib/&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;cd /var/lib/&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;mv mysql-proxy-0.8.1-linux-glibc2.3-x86-32bit mysql-proxy&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Step 3: Edit $PATH variable&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;vi .bash_profile&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;----------&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;...&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;export PATH=$PATH:/var/lib/mysql-proxy/bin&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;export MYSQLPROXYHOME=/var/lib/mysql-proxy&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;----------&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Step 4: Create mysql-proxy configuration file&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;blockquote style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;cd $MYSQLPROXYHOME&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;vi mysql-proxy.cnf&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;-------------------&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;[mysql-proxy]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;admin-address=10.0.0.44:4401&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;proxy-address=10.0.0.44:4402&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;proxy-backend-addresses=10.0.0.44:3306&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;admin-username=admin&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;admin-password=std123&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;admin-lua-script=/var/lib/mysql-proxy/lib/mysql-proxy/lua/admin.lua&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;proxy-lua-script=/var/lib/mysql-proxy/lib/mysql-proxy/lua/block_show_tables.lua&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;pid-file=/var/lib/mysql-proxy/mysqlproxy.pid&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;log-file=/var/log/mysql-proxy.log&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;log-level=message&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;-------------------&lt;/span&gt;&lt;/blockquote&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Here all the addresses contain same IP addresses as I installed mysql-proxy and mysql server in the same host. &lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Step 5: Add scripts to block SHOW TABLES&lt;/span&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;cd /var/lib/mysql/mysql-proxy/lib/mysql-proxy/lua/&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;vi block_show_tables.lua&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;------------------------------------------&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;...   &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;local tokenizer = require(&quot;proxy.tokenizer&quot;)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;---&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;-- make_regexp_from_command()&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;--&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;-- creates a regular expression for fast scanning of the command&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;-- &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;-- @param cmd the command to be converted to regexp&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;--&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;function make_regexp_from_command(cmd)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;local regexp= &#39;^%s*&#39;;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;for ch in cmd:gmatch(&#39;(.)&#39;) do&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;regexp = regexp .. &#39;[&#39; .. ch:upper() .. ch:lower() .. &#39;]&#39;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;return regexp&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;local SHOW_REGEXP = make_regexp_from_command(&#39;show&#39;)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;local EXECUTE_REGEXP = make_regexp_from_command(&#39;execute&#39;)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;local SELECT_REGEXP = make_regexp_from_command(&#39;select&#39;)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;queries_to_filter = {&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;prefix = SHOW_REGEXP,&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;keywords = { &#39;SHOW&#39;, &#39;TABLE&#39;, &#39;STATUS&#39;} ,&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;},&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;prefix = SHOW_REGEXP,&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;keywords = { &#39;SHOW&#39;, &#39;TABLES&#39;} ,&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;},&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;prefix = SELECT_REGEXP,&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;keywords = { &#39;SELECT&#39;, &#39;FROM&#39;, &#39;INFORMATION_SCHEMA&#39;, &#39;TABLES&#39;} ,&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;},&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;prefix = SELECT_REGEXP,&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;keywords = { &#39;SELECT&#39;, &#39;FROM&#39;, &#39;INFORMATION_SCHEMA&#39;, &#39;COLUMNS&#39;} ,&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;},&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;prefix = SELECT_REGEXP,&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;keywords = { &#39;SELECT&#39;, &#39;FROM&#39;, &#39;TABLES&#39;} ,&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;},&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;prefix = SELECT_REGEXP,&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;keywords = { &#39;SELECT&#39;, &#39;FROM&#39;, &#39;COLUMNS&#39;} ,&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;},&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;prefix = EXECUTE_REGEXP,&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;keywords = { &#39;EXECUTE&#39;} ,&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;},&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;function error_result (msg)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;proxy.response = {&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;type = proxy.MYSQLD_PACKET_ERR,&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;errmsg = msg,&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;errcode = 7777,&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;sqlstate = &#39;X7777&#39;,&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;return proxy.PROXY_SEND_RESULT&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;function read_query( packet )&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;if (packet:byte() ~= proxy.COM_QUERY) then&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;return&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;local query = packet:sub(2)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;for i,query_to_filter in pairs(queries_to_filter)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;do&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;if query:match(query_to_filter.prefix) then&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;local full_tokens = tokenizer.tokenize(query)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;local tokens = tokenizer.bare_tokens(full_tokens, true)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;local found = 0&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;local requested = #query_to_filter.keywords&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;for j,keyword in pairs(query_to_filter.keywords) do&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;for k, token in pairs(tokens) do&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;if token:upper() == keyword then&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;found = found + 1&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;break&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;if found == requested then -- to be filtered off&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;blockquote&gt;local log_file = os.getenv(&quot;MYSQLPROXYHOME&quot;) .. &#39;/mysql-proxy.log&#39;&lt;/blockquote&gt;&lt;blockquote&gt;print (log_file)&lt;/blockquote&gt;&lt;blockquote&gt;local str = os.date(&#39;%Y-%m-%d %H:%M:%S&#39;) .. &#39; &amp;nbsp;: &#39; .. proxy.connection.client.src.name .. &#39; executed &#39; .. table.concat(query_to_filter.keywords,&#39; &#39;) &amp;nbsp;&lt;/blockquote&gt;&lt;blockquote&gt;local file = io.open(log_file,&#39;a+&#39;)&lt;/blockquote&gt;&lt;blockquote&gt;file:write(string.format(&quot;%s \n&quot;,str))&lt;/blockquote&gt;&lt;blockquote&gt;file:flush()&lt;/blockquote&gt;&lt;blockquote&gt;return error_result(&#39;command &amp;lt;&#39; ..   table.concat(query_to_filter.keywords,&#39; &#39;) ..   &#39;&amp;gt; is not allowed&#39; )&lt;/blockquote&gt;&lt;blockquote&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;------------------------------------------&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;The above script is downloaded from http://forge.mysql.com/wiki/Lua_Scripts_For_MySQL_Proxy_Examples&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Step 6: Set file permission &lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;chown –R mysql:mysql $ MYSQLPROXYHOME&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;chmod 660 $MYSQLPROXYHOME/mysql-proxy.cnf &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;cd /var/lib/mysql/mysql-proxy/lib/mysql-proxy/lua/&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;chmod 644 block_show_tables.lua&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;ls -lh&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;-rw-r--r-- 1 mysql mysql   2741 Sep  3 16:52 admin.lua&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;-rw-r--r-- 1 mysql mysql   2979 Oct 12 17:00 block_show_tables.lua&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Step 7: Check if mysql-proxy is starting&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;/var/lib/mysql-proxy/bin/mysql-proxy --defaults-file=/var/lib/mysql \ -proxy/mysql-proxy.cnf –daemon&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;pidof -s &quot;$MYSQLPROXYHOME/libexec/mysql-proxy&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;6411&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;cat $MYSQLPROXYHOME/mysqlproxy.pid&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;6411&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Step 8: Stop mysql-proxy&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;kill -9 6411 &lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Step 9: Set mysql-proxy service script at /etc/init.d/&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;vi /etc/init.d/mysqlproxy&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;--------------------------&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;#!/bin/sh&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;# Source function library.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;. /etc/rc.d/init.d/functions&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;# Find the name of the script&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;NAME=`basename $0`&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;if [ ${NAME:0:1} = &quot;S&quot; -o ${NAME:0:1} = &quot;K&quot; ]&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;NAME=${NAME:3}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;fi&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;export MYSQLPROXYHOME=/var/lib/mysql-proxy&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;export MYSQLPROXYENGINE=/var/lib/mysql-proxy/bin&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;script_result=0&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;STARTLOG=$MYSQLPROXYHOME/startup_failure.log&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;i=0&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;message_display()&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;ret=$?&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;if [ $ret -eq 0 ]&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;#success  &quot;$DISPLAY&quot;   &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;echo_success&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;else&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;#failure &quot;$DISPLAY&quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;echo_failure&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;script_result=1&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;fi&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;echo&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;start()&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;DISPLAY=$&quot;Starting ${NAME} service: &quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;echo -n $DISPLAY&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;pid=`pidof -s &quot;$MYSQLPROXYHOME/libexec/mysql-proxy&quot;`&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;if [ $pid ] &amp;amp;&amp;amp; [ -f &quot;$MYSQLPROXYHOME/mysqlproxy.pid&quot; ]&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;echo &quot;ERROR: mysql-proxy already running at pid $pid &quot; &amp;gt; $STARTLOG&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;sleep 1&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;failure &quot;$DISPLAY&quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;echo&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;script_result=1 &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;exit 1&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;fi&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;su -l mysql -c  &quot;$MYSQLPROXYENGINE/mysql-proxy --defaults-file=$MYSQLPROXYHOME/mysql-proxy.cnf --daemon&quot; &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;sleep 2&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;pid=`pidof -s &quot;$MYSQLPROXYHOME/libexec/mysql-proxy&quot;`&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;if [ $pid ] &amp;amp;&amp;amp; [ -f &quot;$MYSQLPROXYHOME/mysqlproxy.pid&quot; ]&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;success &quot;$DISPLAY&quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;touch /var/lock/subsys/${NAME}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;head -n 1 &quot;$MYSQLPROXYHOME/mysqlproxy.pid&quot; &amp;gt; &quot;/var/run/mysqlproxy.pid&quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;echo&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;script_result=0&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;else&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;failure &quot;$DISPLAY&quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;echo&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;script_result=1 &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;fi&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;#message_display;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;} #end of start&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;stop()&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;DISPLAY=$&quot;Stopping ${NAME} service: &quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;echo -n $DISPLAY   &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;sleep 1 &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;pid=`pidof -s &quot;$MYSQLPROXYHOME/libexec/mysql-proxy&quot;`&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;if [ $pid ] &amp;amp;&amp;amp; [ -f &quot;$MYSQLPROXYHOME/mysqlproxy.pid&quot; ]&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;kill -9 &quot;$pid&quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;rm -f $MYSQLPROXYHOME/mysqlproxy.pid&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;rm -f /var/run/mysqlproxy.pid&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;rm -f &quot;/var/lock/subsys/${NAME}&quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;success &quot;$DISPLAY&quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;echo&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;else&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;failure &quot;$DISPLAY&quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;echo&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;script_result=1 &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;fi&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;#message_display;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;} # end of stop&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;restart()&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;stop;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;start;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;} #end of restart&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;case $1 in&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;start) start;;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;stop)  stop;;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;restart) restart;;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;*)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;echo $&quot;Usage: $0 {start|stop|restart}&quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;exit 1&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;esac&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;exit $script_result &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;----------------------------------------------------------------&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Step 10: Start and Stop mysql-proxy&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt; with the service script&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;/etc/init.d/mysqlproxy start&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;/etc/init.d/mysqlproxy stop&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;br /&gt;
Filter everything that goes to the DB server and enjoy !!!&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: large;&quot;&gt;References&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;a href=&quot;http://www.chriscalender.com/?tag=proxy-functions&quot;&gt;http://www.chriscalender.com/?tag=proxy-functions&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;a href=&quot;http://lua-users.org/wiki/OsLibraryTutorial&quot;&gt;http://lua-users.org/wiki/OsLibraryTutorial&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;a href=&quot;http://dev.mysql.com/tech-resources/articles/proxy-gettingstarted.html&quot;&gt;http://dev.mysql.com/tech-resources/articles/proxy-gettingstarted.html&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/4111961977432907342/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://airumman.blogspot.com/2010/10/mysql-proxy-installation-and-stop-show.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/4111961977432907342'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/4111961977432907342'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/2010/10/mysql-proxy-installation-and-stop-show.html' title='Mysql-proxy installation and  filter “SHOW TABLES”'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1727938467293727772.post-1253426660792840834</id><published>2010-06-07T11:57:00.003+06:00</published><updated>2012-02-19T12:09:28.995+06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Consultancy"/><title type='text'>Database Consultancy</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
Database is always critical issue and maintain of it is also the most important in an organization. Performance of application greatly depends on performance of database. In order to maintain database you need plan and great experience. I started consultancy in Bangladesh in the field of database.&lt;br /&gt;
&lt;br /&gt;
I have expertise in&lt;br /&gt;
&lt;br /&gt;
- Oracle&lt;br /&gt;
- Postgrsql&lt;br /&gt;
- Mysql&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I provide:&lt;br /&gt;
&lt;br /&gt;
- Backup policy setup and implementation&lt;br /&gt;
- Data recover using backups&lt;br /&gt;
- Database system tuning&lt;br /&gt;
- Data restore&lt;br /&gt;
- Database System Integration&lt;br /&gt;
- Database upgradation&lt;br /&gt;
- Database migration&lt;br /&gt;
&lt;br /&gt;
&lt;b style=&quot;background-color: #eeeeee;&quot;&gt;Packages&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Value Pack:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Rate= BDT 2000/- &amp;nbsp;per hour&lt;br /&gt;
Details -&lt;br /&gt;
•Maximum hours per month/per week will depend on your budget.&lt;br /&gt;
•I recommend a session should span 2 hours.&lt;br /&gt;
•You are free to discuss about your budget limit during consultancy phase.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Fixed Pack:&lt;/b&gt;&lt;br /&gt;
Rate=Depends on the task scope starting from BDT 15000/-&lt;br /&gt;
Details -&lt;br /&gt;
First analysis of the project will be done to identify the scope.&lt;br /&gt;
The rate will be fixed afterwards.&lt;br /&gt;
If the project is successful, then the client have to pay full, otherwise only BDT 1000/- &amp;nbsp;will be charged.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Contact Details&lt;/b&gt;&lt;br /&gt;
If you want me as a consultant you may contact me at +8801674669343&lt;br /&gt;
Alternatively you may mail me for more details at irumman@gmail.com&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://airumman.blogspot.com/feeds/1253426660792840834/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://airumman.blogspot.com/2010/06/database-consultancy.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/1253426660792840834'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1727938467293727772/posts/default/1253426660792840834'/><link rel='alternate' type='text/html' href='http://airumman.blogspot.com/2010/06/database-consultancy.html' title='Database Consultancy'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10320231627876920453</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>