<?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-2844187126830320432</id><updated>2026-04-04T17:04:27.966+05:30</updated><category term="postgresql job scheduler"/><category term="Customized Log in PostgreSQL"/><category term="PL/C in PostgreSQL"/><category term="batch scripts for postgresql"/><category term="foreign servers"/><category term="job scheduler for postgresql"/><category term="/*NO LOAD BALANCE*/"/><category term="/proc/loadavg in winodws"/><category term="2011 Year Calendar"/><category term="32-bit postgresql on 64-bit"/><category term="7z in windows"/><category term="ACID"/><category term="ACID properties"/><category term="CSV log postgres regex"/><category term="CSV regex for postgres"/><category term="Calendar Query"/><category term="Cartoon in PG"/><category term="Circle in c"/><category term="Circle in c through ASCII"/><category term="DB Growth Percentage in postgresql"/><category term="DB Growth size in postgres"/><category term="DB Size in postgresql"/><category term="DBMS_HS_PASSTHROUGH Oracle Trigger"/><category term="DBMS_HS_PASSTHROUGH postgresql"/><category term="Dblink from postgres to oracle"/><category term="Dblink from postgresplus to oracle"/><category term="Decode in Oracle"/><category term="Default File Permissions in Linux"/><category term="Default Permissions"/><category term="Directory default permissions"/><category term="EDB Loader"/><category term="ERROR:  java.lang.ClassNotFoundException: com.mycompany.helloworld.HelloWorld"/><category term="Email from PostgreSQL"/><category term="Email in PostgreSQL"/><category term="EnterpriseDB edbldr"/><category term="FATAL  localListenThread"/><category term="FATAL  localListenThread: postgresql"/><category term="FATAL slon_node_health_check() returned false - fatal health problem"/><category term="Failback in postgres"/><category term="Faillback in pgpool"/><category term="File Retention"/><category term="File Retention Script Windows"/><category term="File write in oracle"/><category term="Flat files in oracle"/><category term="Forfiles in windows"/><category term="Fun Oracle"/><category term="Fun With PostgreSQL"/><category term="Fun with Oracle"/><category term="Game in postgresql"/><category term="Group by vs distinct"/><category term="HS db connection in Oracle"/><category term="HS db connection to PostgreSQL"/><category term="How to compress files in windows"/><category term="How to configure plpython"/><category term="How to configure radius authentication in postgresql"/><category term="How to get Oracle Errors"/><category term="How to insert child with out any refference."/><category term="How to send E-Mail From PostgreSQL"/><category term="How to send email from libcurl"/><category term="How to send gmail from libcurl"/><category term="How to track oracle error causing statements"/><category term="How to write custmize information into pg_logs"/><category term="How to write data into a file in oracle"/><category term="Input from PostgreSQL"/><category term="Interactive PostgreSQL"/><category term="Interactive SQL in PostgreSQL"/><category term="Interactive psql"/><category term="JDBC Connection with PostgreSQL"/><category term="JDBC Example PostgreSQL"/><category term="JDBC In PostgreSQL"/><category term="JDBC Sample PostgreSQL"/><category term="JDBC Sample Program With PostgreSQL"/><category term="Londiste"/><category term="Londiste replication in postgresql"/><category term="Mail from PostgrSQL"/><category term="Mail in PostgreSQL"/><category term="NOT VALID in postgresql"/><category term="NOVALIDATE Oralce"/><category term="NOVALIDATE in PostgreSQL"/><category term="Normal user as super user"/><category term="OCI from Postgres To Oracle"/><category term="OCI in postgresql"/><category term="OS commands from PostgreSQL"/><category term="OS results from PostgreSQL"/><category term="Oracle Architecture"/><category term="Oracle Architecture Diagram."/><category term="Oracle Errors Log"/><category term="Oracle SERVERERROR"/><category term="Oraerror"/><category term="Os commands in PostgreSQL"/><category term="PG XC installation"/><category term="PG XC setup"/><category term="PG plpythony"/><category term="PGQ"/><category term="PGQ in postgresql"/><category term="PL/C"/><category term="PL/C Functions"/><category term="PL/C concat_text"/><category term="Parallel pl/pgsql"/><category term="Permissions"/><category term="Pgpool Prefixes"/><category term="Pgpool replicates Cursors"/><category term="Pgpool replicating fetch to slave nodes. Pgppol"/><category term="Pipelined in Oracle"/><category term="Pipelined in PostgreSQL"/><category term="PostgreSQL Agent"/><category term="PostgreSQL High Performance Cookbook"/><category term="PostgreSQL Interactive"/><category term="PostgreSQL Job Agent"/><category term="PostgreSQL PL/C"/><category term="PostgreSQL Query Tuning"/><category term="PostgreSQL Query tricks"/><category term="PostgreSQL Radius authentication"/><category term="PostgreSQL tricks"/><category term="Postgres XC installation"/><category term="Postgres XC tutorial"/><category term="Query Tune"/><category term="Query Tuning"/><category term="Query tips and tricks"/><category term="Query tricks"/><category term="Query tuning tips"/><category term="REPAIR CONFIG SLONIK"/><category term="Radius in postgresql"/><category term="Radius postgresql"/><category term="Return Multiple Rows In PostgreSQL"/><category term="SMTP Libcurl"/><category term="Scripts in windows"/><category term="Skytools"/><category term="Skytools in PostgreSQL"/><category term="The connection to the server was lost. Attempting reset: Failed."/><category term="UDT in PostgreSQL"/><category term="UTL_FILE"/><category term="Walfiles"/><category term="Walfiles difference in postgresql"/><category term="XC configuration"/><category term="XC setup"/><category term="XCEPT in PostgreSQL"/><category term="Zipping files in windows"/><category term="automicity"/><category term="autonomous transactions"/><category term="background jobs in windows"/><category term="batch script in windows"/><category term="bucardo postgresql"/><category term="co-relations vs joins"/><category term="commit in functions"/><category term="commit in oracle"/><category term="commit in oracle plsql functions"/><category term="commit in plsql functions"/><category term="commit in triggers"/><category term="compile 32-bit postgresql on 64-bit linux."/><category term="concurrent job scheduler for postgresql"/><category term="configure plpythonu"/><category term="cronjob in windows"/><category term="csv files in oracle"/><category term="data wrappers"/><category term="dblinks in postgresql"/><category term="dbms_system.ksdwrt in PostgreSQL"/><category term="dg4odbc from oracle to postgres"/><category term="dg4odbc postgresql"/><category term="ecpg"/><category term="ecpg example in postgres"/><category term="ecpg in postgresql"/><category term="edbldr"/><category term="failback postgres setup"/><category term="fdw in postgresql"/><category term="foregin data wrappers"/><category term="foreign data wrapers"/><category term="foreign tables"/><category term="foreign tables in postgresql."/><category term="game with postgresql"/><category term="games in postgresql"/><category term="group by rollup"/><category term="group by rollup() in oracle"/><category term="heterogeneous database connection between Oracle and PostgreSQL"/><category term="index growth"/><category term="index growth percent"/><category term="job scheduler for postgres"/><category term="jobs in windows"/><category term="ksdwrt in PostgreSQL"/><category term="load average in windows"/><category term="load avg in windows"/><category term="load in windows"/><category term="loadavg in windows"/><category term="mailsend"/><category term="mailsend in windows"/><category term="mailsend postgres in windows"/><category term="mutli master replication in postgresql"/><category term="ng"/><category term="non zero min value"/><category term="olive in c"/><category term="online game with postgresql"/><category term="optimizer"/><category term="parallel execution in pl/pgsql"/><category term="parallel execution in postgres"/><category term="parallel operations in postgres"/><category term="parse line strtok()"/><category term="parse multiple lines strtok()"/><category term="pg job scheduler"/><category term="pg optimizer"/><category term="pg plpython"/><category term="pg seq vs index"/><category term="pg_Agent windows pg_dump job"/><category term="pg_dump batch script"/><category term="pg_dump in windows"/><category term="pg_dump remote"/><category term="pg_dump with load balance"/><category term="pg_stat_activity as non super user."/><category term="pg_xlogs"/><category term="pg_xogs difference"/><category term="pgbucket"/><category term="pgping batch"/><category term="pgping in batch"/><category term="pgping in windows"/><category term="pgping windows"/><category term="pgpool postgres setup"/><category term="pl/java in postgres"/><category term="pl/java in postgresql"/><category term="pljava"/><category term="pljava in enterprisedb"/><category term="pljava in postgresplus"/><category term="pljava postgresql"/><category term="plpython"/><category term="plpythonu in postgresql"/><category term="postgres index growth percent"/><category term="postgres job scheduler"/><category term="postgres table growth percent"/><category term="postgresql optimizer"/><category term="postgresql pg_dump windows"/><category term="postgresql scheduler"/><category term="postgresql sequences for the given tables"/><category term="regex to parse postgresql log files"/><category term="required fields from a table in Postgresql"/><category term="rollup in oracle"/><category term="rownum in postgres"/><category term="rownum in postgresql"/><category term="rownum postgres"/><category term="rownum work arround in postgres"/><category term="sample ecpg example"/><category term="scans in pg"/><category term="scans in postgresql"/><category term="scheduling in windows"/><category term="seq scan vs index scan"/><category term="seqscan vs indexscan"/><category term="sequential scan vs index scan"/><category term="slony FATAL  localListenThread:"/><category term="strtok"/><category term="strtok()"/><category term="table growth"/><category term="table growth percent"/><category term="tables related sequences"/><category term="unnest PostgreSQL"/><category term="unnest in Postgresql"/><category term="updatereloid slony"/><category term="uptime in windows"/><category term="wals"/><category term="wals diff in postgresql"/><category term="windows pg_dump"/><category term="windows postgresql avilability check batch script"/><title type='text'>DevAdmin</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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>67</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2844187126830320432.post-2062034227117720887</id><published>2017-05-03T12:18:00.001+05:30</published><updated>2017-05-03T12:18:29.766+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="job scheduler for postgresql"/><category scheme="http://www.blogger.com/atom/ns#" term="postgresql job scheduler"/><category scheme="http://www.blogger.com/atom/ns#" term="postgresql scheduler"/><title type='text'>pgBucket 2.0 Beta Is Ready</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
I am so glad to announce pgBucket 2.0 beta version, which is evolved from the version 1.0. Below are this version feature highlights and hoping that everybody likes these features.&lt;br /&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Event jobs (Cascading jobs)&lt;/li&gt;
&lt;li&gt;Dedicated configuration file&lt;/li&gt;
&lt;li&gt;Extended table print&lt;/li&gt;
&lt;li&gt;Auto job disable&lt;/li&gt;
&lt;li&gt;Custom job failure&lt;/li&gt;
&lt;li&gt;Dedicated connection pooler&lt;/li&gt;
&lt;li&gt;Improved the daemon stability/coding standards&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
Please find the below URL for the features review.&lt;/div&gt;
&lt;div&gt;
&lt;a data-saferedirecturl=&quot;https://www.google.com/url?hl=en&amp;amp;q=https://bitbucket.org/dineshopenscg/pgbucket/overview&amp;amp;source=gmail&amp;amp;ust=1493880178349000&amp;amp;usg=AFQjCNGxnvzhenIQaYrsnmA0azT6OnqpOQ&quot; href=&quot;https://bitbucket.org/dineshopenscg/pgbucket/overview&quot; style=&quot;background-color: white; color: #1155cc; font-family: arial, sans-serif; font-size: 12.8px;&quot; target=&quot;_blank&quot;&gt;https://bitbucket.org/&lt;wbr&gt;&lt;/wbr&gt;dineshopenscg/pgbucket/&lt;wbr&gt;&lt;/wbr&gt;overview&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
--Dinesh&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/2062034227117720887/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2017/05/pgbucket-20-beta-is-ready.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/2062034227117720887'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/2062034227117720887'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2017/05/pgbucket-20-beta-is-ready.html' title='pgBucket 2.0 Beta Is Ready'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2844187126830320432.post-8544636408508568095</id><published>2017-04-14T15:54:00.004+05:30</published><updated>2022-03-30T17:43:06.671+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="PostgreSQL High Performance Cookbook"/><title type='text'>PostgreSQL High Performance Cookbook</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Sharing knowledge which I have gained from last 6 years.&lt;br /&gt;
&lt;br /&gt;
So glad to be part of PostgreSQL High Performance Cookbook, where I have discussed all the knowledge I have gained from PostgreSQL database.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://www.packtpub.com/big-data-and-business-intelligence/postgresql-high-performance-cookbook&quot;&gt;PostgreSQL High Performance Cookbook&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Working with PostgreSQL from last 6 years, I have gained so much of knowledge about database management systems. Being a DBA for several years, I explored so many tools which work&amp;nbsp;great with PostgreSQL database. During this 6 years journey, I got a chance to meet many wonderful peoples who guided me very well. I would like to say thanks to everyone who taught me PostgreSQL database in soft/hard ways :-). Also, would like to say thanks to every PostgreSQL developer, and authors and bloggers, from where I have learned many more things.&lt;br /&gt;
&lt;br /&gt;
Finally thanks to OpenSCG team&lt;br /&gt;
Thanks to my wife manoja&amp;nbsp; for her wonderful support, and my friend Baji Shaik for his help in writing the content.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/8544636408508568095/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2017/04/postgresql-high-performance-cookbook.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/8544636408508568095'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/8544636408508568095'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2017/04/postgresql-high-performance-cookbook.html' title='PostgreSQL High Performance Cookbook'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2844187126830320432.post-3266346962215465899</id><published>2016-10-06T14:35:00.001+05:30</published><updated>2016-10-06T14:35:42.383+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="PostgreSQL Agent"/><category scheme="http://www.blogger.com/atom/ns#" term="PostgreSQL Job Agent"/><category scheme="http://www.blogger.com/atom/ns#" term="postgresql job scheduler"/><title type='text'>pgBucket v1.0 is ready</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
pgBucket v1.0&lt;/h2&gt;
&lt;div&gt;
pgBucket v1.0 (concurrent job scheduler for PostgreSQL) is released. This version is more stable and fixed the issues which was observed in the previous beta releases.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Highlights of this tool are&lt;/div&gt;
&lt;div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Schedule OS/DB level jobs&lt;/li&gt;
&lt;li&gt;Cron style syntax {Schedule up to seconds}&lt;/li&gt;
&lt;li&gt;On fly job modifications&lt;/li&gt;
&lt;li&gt;Instant daemon status by retrieving live job queue, job hash&lt;/li&gt;
&lt;li&gt;Enough cli options to deal with all the configured/scheduled job&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
Here is the URL for the pgBucket build/usage instructions.&amp;nbsp;&lt;a href=&quot;https://bitbucket.org/dineshopenscg/pgbucket&quot;&gt;https://bitbucket.org/dineshopenscg/pgbucket&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
I hope this tool will be helpful for the PostgreSQL users to get things done in the scheduled time.&lt;/div&gt;
&lt;div&gt;
&lt;i&gt;Note: This tool requires c++11{gcc version &amp;gt;= 4.9.3} to compile.&lt;/i&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
--Dinesh&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/3266346962215465899/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2016/10/pgbucket-v10-is-ready.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/3266346962215465899'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/3266346962215465899'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2016/10/pgbucket-v10-is-ready.html' title='pgBucket v1.0 is ready'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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-2844187126830320432.post-8678092675009017006</id><published>2016-08-03T08:19:00.001+05:30</published><updated>2016-08-03T08:19:56.192+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="concurrent job scheduler for postgresql"/><category scheme="http://www.blogger.com/atom/ns#" term="job scheduler for postgresql"/><category scheme="http://www.blogger.com/atom/ns#" term="postgresql job scheduler"/><title type='text'>pgBucket beta2 is ready</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hi Everyone,&lt;br /&gt;
&lt;br /&gt;
I would like to inform to you all that,&amp;nbsp;&lt;a href=&quot;https://bitbucket.org/dineshopenscg/pgbucket&quot;&gt;pgBucket&lt;/a&gt;&amp;nbsp;beta2[Simple concurrent job scheduler for postgresql] version is ready with more stability.&lt;br /&gt;
&lt;br /&gt;
Thank you all in advance for your inputs/comments/suggestions.&lt;br /&gt;
&lt;br /&gt;
--Dinesh&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/8678092675009017006/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2016/08/pgbucket-beta2-is-ready.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/8678092675009017006'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/8678092675009017006'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2016/08/pgbucket-beta2-is-ready.html' title='pgBucket beta2 is ready'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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-2844187126830320432.post-6157535379107484229</id><published>2016-07-04T01:50:00.003+05:30</published><updated>2016-07-04T01:50:49.708+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="job scheduler for postgres"/><category scheme="http://www.blogger.com/atom/ns#" term="pgbucket"/><category scheme="http://www.blogger.com/atom/ns#" term="postgresql job scheduler"/><title type='text'>pgBucket beta version is ready</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hi Everyone,&lt;br /&gt;
&lt;br /&gt;
I would like to inform to you all that, &lt;a href=&quot;https://bitbucket.org/dineshopenscg/pgbucket&quot;&gt;pgBucket&lt;/a&gt;[Simple concurrent job scheduler for postgresql] beta version is ready with enhanced architecture and new features.&lt;br /&gt;
&lt;br /&gt;
It would be more great if you could share your inputs and suggestions on this, which will help me to make this tool as stable.&lt;br /&gt;
&lt;br /&gt;
Thank you all in advance.&lt;br /&gt;
&lt;br /&gt;
--Dinesh&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/6157535379107484229/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2016/07/pgbucket-beta-version-is-ready.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/6157535379107484229'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/6157535379107484229'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2016/07/pgbucket-beta-version-is-ready.html' title='pgBucket beta version is ready'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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-2844187126830320432.post-2885199776955760739</id><published>2016-06-03T12:11:00.002+05:30</published><updated>2016-06-04T00:00:09.828+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="pg job scheduler"/><category scheme="http://www.blogger.com/atom/ns#" term="postgres job scheduler"/><title type='text'>pgBucket - A new concurrent job scheduler</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hi All,&lt;br /&gt;
&lt;br /&gt;
I&#39;m so excited to announce about my first contribution tool for postgresql. I have been working with PostgreSQL from 2011 and I&#39;m really impressed with such a nice database.&lt;br /&gt;
&lt;br /&gt;
I started few projects in last 2 years like pgHawk[A beautiful report generator for Openwatch] , pgOwlt [CUI monitoring. It is still under development, incase you are interested to see what it is, attaching the image here for you ],&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/AVvXsEiz1ZpdVlsuYgRt9R8OY5Y0exTMlETOG7xdmCm_OJ8l9AUOVVLdOubXm8YWkQXGf6CCUnjlvFBCUjPJevXUySw6Q5wuk8yL06jaxoFp6rHffecjoCLm_h932N8SonXgXmMRwMyolthp8KE/s1600/Owlt+%25281%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;250&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiz1ZpdVlsuYgRt9R8OY5Y0exTMlETOG7xdmCm_OJ8l9AUOVVLdOubXm8YWkQXGf6CCUnjlvFBCUjPJevXUySw6Q5wuk8yL06jaxoFp6rHffecjoCLm_h932N8SonXgXmMRwMyolthp8KE/s400/Owlt+%25281%2529.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
pgBucket [Which I&#39;m gonna talk about] and learned a lot and lot about PostgreSQL/Linux internals.&lt;br /&gt;
&lt;br /&gt;
Using pgBucket we can schedule jobs easily and we can also maintain them using it&#39;s CLI options. We can update/insert/delete jobs at online. And here is its architecture which gives you a basic idea about how it works.&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/AVvXsEiJzA03OOOoXMTHg3c5hM83-KAzeKPn2IYF6g316Jt_4siOj1eepbWQhXCB_1AMFYwmg8g-0ScLcc1_CMDoFfMMqYuhT0aCzGO7FcHns4IN_aBgnQvTbkzillXw5H4inGKoxQhrXCIMsNM/s1600/2633692012-pgBucket.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;271&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJzA03OOOoXMTHg3c5hM83-KAzeKPn2IYF6g316Jt_4siOj1eepbWQhXCB_1AMFYwmg8g-0ScLcc1_CMDoFfMMqYuhT0aCzGO7FcHns4IN_aBgnQvTbkzillXw5H4inGKoxQhrXCIMsNM/s400/2633692012-pgBucket.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Yeah, I know there are other good job schedulers available for PostgreSQL. I haven&#39;t tested them and not comparing them with this, as I implemented it in my way.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Features are:&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;OS/DB jobs&lt;/li&gt;
&lt;li&gt;Cron style sytax&lt;/li&gt;
&lt;li&gt;Online job modifications&lt;/li&gt;
&lt;li&gt;Required cli options&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Dependencies:&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;C++11&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;a href=&quot;https://bitbucket.org/dineshopenscg/pgbucket/overview&quot;&gt;Here&lt;/a&gt;&amp;nbsp;is the link for the source/build instructions, which hopefully helpful for you.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Let me know your inputs/suggestions/comments, which will help me to improve this tool.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Thanks as always.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
--Dinesh Kumar&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/2885199776955760739/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2016/06/pgbucket-new-concurrent-job-scheduler.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/2885199776955760739'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/2885199776955760739'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2016/06/pgbucket-new-concurrent-job-scheduler.html' title='pgBucket - A new concurrent job scheduler'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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/AVvXsEiz1ZpdVlsuYgRt9R8OY5Y0exTMlETOG7xdmCm_OJ8l9AUOVVLdOubXm8YWkQXGf6CCUnjlvFBCUjPJevXUySw6Q5wuk8yL06jaxoFp6rHffecjoCLm_h932N8SonXgXmMRwMyolthp8KE/s72-c/Owlt+%25281%2529.png" height="72" width="72"/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2844187126830320432.post-7590605436846621039</id><published>2015-07-09T18:21:00.001+05:30</published><updated>2016-06-01T17:22:57.573+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="parallel execution in pl/pgsql"/><category scheme="http://www.blogger.com/atom/ns#" term="parallel execution in postgres"/><category scheme="http://www.blogger.com/atom/ns#" term="parallel operations in postgres"/><category scheme="http://www.blogger.com/atom/ns#" term="Parallel pl/pgsql"/><title type='text'>Parallel Operations With pl/pgSQL</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif; font-size: 11pt;&quot;&gt;
Hi,

I am pretty sure that, there will be a right heading for this post. For now, i am going with this. If you could suggest me proper heading, i will update it :-)

OK. let me explain the situation. Then will let you know what i am trying to do here, and how i did it.

&lt;u&gt;&lt;i&gt;Situation here is,&lt;/i&gt;&lt;/u&gt;

&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt; We have a table, which we need to run update on “R” no.of records. The update query is using some joins to get the desired result, and do update the table.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif; font-size: 11pt;&quot;&gt; To process these “R” no.of records, it is taking “H” no.of hours. That too, it’s giving load on the production server. So, we planned to run this UPDATE as batch process.&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif; font-size: 11pt;&quot;&gt; Per a batch process, we took “N” no.or records. To process this batch UPDATE, it is taking “S” no.of seconds.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif; font-size: 11pt;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt; With the above batch process, production server is pretty stable, and doing great. So, we planned to run these Batch updates parallel.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif; font-size: 11pt;&quot;&gt; I mean, “K” sessions, running different record UPDATEs. Of-course, we can also increase the Batch size here.&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif; font-size: 11pt;&quot;&gt; But we want to use much cpus to complete all these UPDATES as soon as possible.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif; font-size: 11pt;&quot;&gt;
&lt;u&gt;&lt;i&gt;Problem here is&lt;/i&gt;&lt;/u&gt;,

So, as i said, we need to run multiple UPDATEs on multiple records in parallel. But, how can one session is going to communicate with other sessions on this batch records.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif; font-size: 11pt;&quot;&gt;I mean, If one session is running updates on 1 to 1000, how could the second session knows that the other session was processing from 1 to 1000.
If the second session knows this information, this will start from 1001 to 2000 in parallel. This is the problem i am trying to solve here.

I am not sure whether this is the optimal solution, but as per my requirement it’s working. :-)  Let me know if you see any problems in it.&lt;/span&gt;
&lt;/pre&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Object Definitions&lt;/b&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;                      Table &quot;public.test&quot;
 Column |  Type   |                     Modifiers
--------+---------+----------------------------------------------------
 t      | text    |
 i      | boolean |
 seq    | bigint  | not null default nextval(&#39;test_seq_seq&#39;::regclass)

postgres=# INSERT INTO test VALUES(generate_series(1, 9000), false, generate_series(1, 9000));
INSERT 0 9000

postgres=# \ds testing
           List of relations
 Schema |  Name   |   Type   |  Owner
--------+---------+----------+----------
 public | testing | sequence | postgres
(1 row)


CREATE OR REPLACE FUNCTION public.update_test_parallel(batch integer)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
VAR BIGINT;
DUMMY TEXT;
BEGIN

-- Adding this for Demo
--

SELECT pg_sleep(10) INTO DUMMY;

SELECT pg_advisory_lock(-1234) INTO DUMMY;

        SELECT nextval(&#39;testing&#39;) INTO VAR;
        EXECUTE E&#39;SELECT nextval(\&#39;testing\&#39;) FROM generate_series(&#39;||VAR||&#39;,&#39;||VAR+BATCH||&#39;)&#39;;

        -- We need to decrease the sequence value by one, since we executed nextval expression once
        -- Otherwise, it will affect the other session&#39;&#39;s  execution.
        --
        SELECT setval(&#39;testing&#39;, currval(&#39;testing&#39;)-1) INTO DUMMY;

SELECT pg_advisory_unlock(-1234) INTO DUMMY;

        -- I want to update the test table of the column &quot;I&quot; with value &quot;true&quot;.
        --
UPDATE test SET I=true WHERE SEQ BETWEEN VAR AND (VAR+BATCH);


RAISE NOTICE &#39;VAR IS %, VAR+BATCH IS %&#39;, VAR, (VAR+BATCH);
RAISE NOTICE &#39;CURRENT SEQ VALUE IS %&#39;, currval(&#39;testing&#39;);

EXCEPTION WHEN OTHERS THEN

        -- If there is an exception, we need to reset the sequence to it&#39;&#39;s start position again.
        -- So that, the other sessions, will try with the same sequence numbers.
        --
        SELECT setval(&#39;testing&#39;, VAR-1) INTO DUMMY;
        SELECT pg_advisory_unlock(-1234) INTO DUMMY;
        RAISE EXCEPTION &#39;%&#39;, SQLERRM;
END;
$function$;
&lt;/pre&gt;
&lt;b&gt;Session 1&lt;/b&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt; 
postgres=# SELECT public.update_test_parallel(3000);
NOTICE:  VAR IS 1, VAR+BATCH IS 3001
NOTICE:  CURRENT SEQ VALUE IS 3000
update_test_parallel
----------------------

(1 row)
&lt;/pre&gt;
&lt;b&gt;Session 2&lt;/b&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt; 
postgres=# SELECT public.update_test_parallel(3000);
NOTICE:  VAR IS 3001, VAR+BATCH IS 6001
NOTICE:  CURRENT SEQ VALUE IS 6000
update_test_parallel
----------------------

(1 row)
&lt;/pre&gt;
&lt;b&gt;Session 3&lt;/b&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt; 
postgres=# SELECT public.update_test_parallel(3000);
NOTICE:  VAR IS 6001, VAR+BATCH IS 9001
NOTICE:  CURRENT SEQ VALUE IS 9000
update_test_parallel
----------------------

(1 row)
&lt;/pre&gt;
&lt;b&gt;Desired result&lt;/b&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt; 
postgres=# SELECT COUNT(*) FROM test WHERE i is true;
count
-------
  9000
(1 row)
&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif; font-size: 11pt;&quot;&gt;
In the above implementation, i took &quot;sequence&quot; for the session&#39;s parallel execution with the help of advisory locks. Hope this helps to others as well.

Thanks as always for reading it, and welcome your inputs.
&lt;/span&gt;&lt;/pre&gt;
&amp;nbsp;--Dinesh Kumar&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/7590605436846621039/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2015/07/parallel-operations-with-plpgsql_9.html#comment-form' title='41 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/7590605436846621039'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/7590605436846621039'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2015/07/parallel-operations-with-plpgsql_9.html' title='Parallel Operations With pl/pgSQL'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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>41</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2844187126830320432.post-7608254693299555578</id><published>2014-12-30T20:30:00.001+05:30</published><updated>2015-04-27T20:50:03.289+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="DBMS_HS_PASSTHROUGH Oracle Trigger"/><category scheme="http://www.blogger.com/atom/ns#" term="DBMS_HS_PASSTHROUGH postgresql"/><title type='text'>Heterogeneous Database Sync</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hi&lt;br /&gt;
&lt;br /&gt;
As a part of ORACLE to PostgreSQL Migration, I come across to implement a trigger on Oracle, which sync it&#39;s data to PostgreSQL. I have tried with&lt;br /&gt;
a simple table as below, which is hopefully helpful to others.&lt;br /&gt;
&lt;br /&gt;
Find this &lt;a href=&quot;http://manojadinesh.blogspot.in/2012/05/heterogeneous-db-connection-between.html&quot;&gt;link &lt;/a&gt;to configure the heterogeneous dblink to postgres.&lt;br /&gt;
&lt;br /&gt;
I believe, the below approach works effectively with the Primary Key tables of Oracle Database.&lt;br /&gt;
If we don&#39;t have primary key in a table, then the UPDATE,DELETE statements going to fire multiple times in Postgres, which leads performance issues.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;ORACLE&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;CREATE TABLE test(t INT PRIMARY KEY);

CREATE OR REPLACE TRIGGER testref AFTER INSERT OR UPDATE OR DELETE ON test
FOR EACH ROW
DECLARE
 PRAGMA AUTONOMOUS_TRANSACTION;
 C number;
 N number;
BEGIN
 c:=DBMS_HS_PASSTHROUGH.OPEN_CURSOR@pglink;
 IF INSERTING THEN
  DBMS_HS_PASSTHROUGH.PARSE@pglink(c, &#39;INSERT INTO test VALUES(&#39;||:NEW.t||&#39;);&#39;);
  n:=DBMS_HS_PASSTHROUGH.EXECUTE_NON_QUERY@pglink(c);
 ELSIF DELETING THEN
  DBMS_HS_PASSTHROUGH.PARSE@pglink(c, &#39;DELETE FROM test WHERE t=&#39;||:OLD.t);
  n:=DBMS_HS_PASSTHROUGH.EXECUTE_NON_QUERY@pglink(c);
 ELSIF UPDATING THEN
  DBMS_HS_PASSTHROUGH.PARSE@pglink(c, &#39;UPDATE test SET t=&#39;||:NEW.T||&#39; WHERE t=&#39;||:OLD.T);
  n:=DBMS_HS_PASSTHROUGH.EXECUTE_NON_QUERY@pglink(c);
 END IF;
 DBMS_HS_PASSTHROUGH.CLOSE_CURSOR@pglink(c);
COMMIT;
END;
/
SQL&amp;gt; INSERT INTO test VALUES(1);
SQL&amp;gt; INSERT INTO test VALUES(2);
SQL&amp;gt; INSERT INTO test VALUES(3);


SQL&amp;gt; DELETE FROM test WHERE t=2;

SQL&amp;gt; UPDATE test SET t=10 WHERE t=1;
SQL&amp;gt; COMMIT;
Commit complete.&lt;/pre&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;/pre&gt;
&lt;b&gt;&lt;u&gt;PostgreSQL&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;CREATE TABLE test(t INT PRIMARY KEY);
postgres=# SELECT * FROM test;
t
----
3
10
(2 rows)
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;NOTE&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
Oracle&#39;s DG4ODBC don&#39;t support the 2 phase commit with PostgreSQL. In the above case, if we issue ROLLBACK in oracle, the data in postgresql will remain, which will lead to inconsistency. To fix this, i believe we have to use Asynchronous data copy by scheduling a job in Oracle as below.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;CREATE SEQUENCE test_seq ORDER;&lt;/pre&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;CREATE TABLE test_backup(SEQ INT, EVT VARCHAR(2), t INT, PRIMARY KEY(SEQ, EVT, t));&lt;/pre&gt;
-- Trigger, which records the test table&#39;s information into test_backup.&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;CREATE OR REPLACE TRIGGER testref AFTER INSERT OR UPDATE OR DELETE ON test
FOR EACH ROW
DECLARE
BEGIN
IF INSERTING THEN
  INSERT INTO test_backup VALUES(test_seq.nextval, &#39;I&#39;, :NEW.t);
ELSIF DELETING THEN
  INSERT INTO test_backup VALUES(test_seq.nextval, &#39;D&#39;, :OLD.t);
ELSIF UPDATING THEN
    INSERT INTO test_backup VALUES(test_seq.nextval, &#39;UD&#39;, :OLD.t);
  INSERT INTO test_backup VALUES(test_seq.nextval, &#39;UI&#39;, :NEW.t);
END IF;
END;
/&lt;/pre&gt;
&lt;br /&gt;
-- Procedure, which sync the test_backup table to postgres test table. &lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;create or replace PROCEDURE SYNCORATOPG
IS
REC TEST_BACKUP%ROWTYPE;
C NUMBER;
N NUMBER;
PRAGMA AUTONOMOUS_TRANSACTION;
TYPE SYNCID IS TABLE OF INTEGER;
SYNCNUM SYNCID;
CNT INT:=0;
BEGIN
  
    BEGIN
        SYNCNUM:=SYNCID();
        FOR REC IN (SELECT * FROM test_backup ORDER BY SEQ ASC)
        LOOP
        SYNCNUM.EXTEND;
        CNT:=CNT+1;
        SYNCNUM(CNT):=REC.SEQ;
        c:=DBMS_HS_PASSTHROUGH.OPEN_CURSOR@TOPG;
        IF REC.EVT = &#39;I&#39; OR REC.EVT=&#39;UI&#39; THEN
           DBMS_HS_PASSTHROUGH.PARSE@TOPG(c, &#39;INSERT INTO test VALUES(&#39;||REC.t||&#39;);&#39;);
        ELSIF REC.EVT = &#39;D&#39; OR REC.EVT=&#39;UD&#39; THEN
           DBMS_HS_PASSTHROUGH.PARSE@TOPG(c, &#39;DELETE FROM test WHERE t=&#39;||REC.T);
        END IF;
      
         n:=DBMS_HS_PASSTHROUGH.EXECUTE_NON_QUERY@TOPG(c);
         DBMS_HS_PASSTHROUGH.CLOSE_CURSOR@TOPG(c);
        END LOOP;
        
        COMMIT;
    END;
    
    BEGIN
      FOR i IN 1..SYNCNUM.COUNT
      LOOP
        DELETE FROM test_backup WHERE SEQ=SYNCNUM(i);
        SYNCNUM.DELETE(i);
      END LOOP;
       COMMIT;
    END;
  EXCEPTION
    WHEN OTHERS THEN
      RAISE_APPLICATION_ERROR(-20000, &#39;Fatal error.&#39;||SQLERRM);
END;&lt;/pre&gt;
&lt;br /&gt;
--Scheduling a JOB in Oracle, which call the above SYNC procedure for every 1 minute.&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;BEGIN
DBMS_JOB.isubmit (
job =&amp;gt; 113,
what =&amp;gt; &#39;BEGIN SYNCORATOPG; END;&#39;,
next_date =&amp;gt; SYSDATE,
interval =&amp;gt; &#39;SYSDATE + 1/(24*60) /* 1 Minute */&#39;);

COMMIT;
END;
/&lt;/pre&gt;
-- Inserting Sample Data In Oracle&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;INSERT INTO test VALUES(-1);
INSERT INTO test VALUES(-2);
INSERT INTO test VALUES(-3);

UPDATE test SET t=-20 WHERE t=-2;
DELETE FROM test WHERE t=-1;
INSERT INTO test VALUES(-2);
COMMIT;&lt;/pre&gt;
&lt;br /&gt;
-- PostgreSQL&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;postgres=# SELECT * FROM test;
 t
----
  -3
 -20
  -2
(3 rows)&lt;/pre&gt;
&lt;br /&gt;
As usual, welcome your inputs.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;--Dinesh Kumar
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/7608254693299555578/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2014/12/heterogeneous-database-sync.html#comment-form' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/7608254693299555578'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/7608254693299555578'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2014/12/heterogeneous-database-sync.html' title='Heterogeneous Database Sync'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2844187126830320432.post-2055698180230497137</id><published>2014-06-03T13:16:00.002+05:30</published><updated>2014-06-04T18:41:15.231+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="32-bit postgresql on 64-bit"/><category scheme="http://www.blogger.com/atom/ns#" term="compile 32-bit postgresql on 64-bit linux."/><title type='text'>32-bit PostgreSQL Compilation On 64-bit CentOS 6.x</title><content type='html'>I am sure that, most of you aware of this. But, for me it&#39;s the first time, I accomplished it.&lt;br /&gt;
&lt;br /&gt;
As one of my assigned tasks to build a 32-bit instance of postgresql on 64-bit machine, I have followed the below approach. I hope, it will be helpful to others as well, if you got any problems.&lt;br /&gt;
&lt;br /&gt;
As an initial step on this task, I have tried to build a sample &quot;c&quot; program using &quot;gcc -m32&quot;. Once, I resolved this, I moved to compile the PostgreSQL 9.0.&lt;br /&gt;

&lt;pre class=&quot;prettyprint&quot;&gt;
[root@localhost Desktop]# gcc -m32 -o test test.c
In file included from /usr/include/features.h:385,
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;from /usr/include/stdio.h:28,
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;from test.c:1:
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory
&lt;/pre&gt;
To resolve the above issue, I have installed the 32-bit glibc-devel package through yum.
&lt;pre class=&quot;prettyprint&quot;&gt;
yum -y install glibc-devel.i686 glibc-devel
&lt;/pre&gt;

Again, I have tried to run the same command.
&lt;pre class=&quot;prettyprint&quot;&gt;
[root@localhost Desktop]# gcc -m32 -o test test.c
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.4.6/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.4.6/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status
&lt;/pre&gt;

Now, I got a different error message, and tried to install the 32-bit libgcc.

&lt;pre class=&quot;prettyprint&quot;&gt;
[root@localhost Desktop]# yum install libgcc-*.i686
--&amp;gt; Running transaction check
---&amp;gt; Package libgcc.i686 0:4.4.7-4.el6 will be installed
--&amp;gt; Finished Dependency Resolution
Error: Protected multilib versions: libgcc-4.4.7-4.el6.i686 != libgcc-4.4.6-3.el6.x86_64
&lt;/pre&gt;

As it&#39;s complaining, we have the old version of x86_64, when compared the new one. Hence, I have tried to update the existing x86_64.

&lt;pre class=&quot;prettyprint&quot;&gt;
[root@localhost Desktop]# yum update libgcc-4.4.6-3.el6.x86_64
---&amp;gt; Package libgcc.x86_64 0:4.4.6-3.el6 will be updated
---&amp;gt; Package libgcc.x86_64 0:4.4.7-4.el6 will be an update
--&amp;gt; Finished Dependency Resolution
&lt;/pre&gt;

Once, it&#39;s updated the given library, I have again tried to install the libgcc-*.i686.

&lt;pre class=&quot;prettyprint&quot;&gt;
[root@localhost Desktop]# yum install libgcc-*.i686
Resolving Dependencies
--&amp;gt; Running transaction check
---&amp;gt; Package libgcc.i686 0:4.4.7-4.el6 will be installed
--&amp;gt; Finished Dependency Resolution
&lt;/pre&gt;

Now, I am trying to run the same &quot;gcc -m32&quot; command to check for any further issues.

&lt;pre class=&quot;prettyprint&quot;&gt;
[root@localhost Desktop]# gcc -m32 -o test test.c
[root@localhost Desktop]# ./test
Hello World
&lt;/pre&gt;

It looks, the sample &quot;c program&quot; is working fine, as a 32-bit application.

Now, i am moving to PostgreSQL 9.0. As per my observation I have updated, installed the below components for the PostgreSQL.

&lt;pre class=&quot;prettyprint&quot;&gt;
yum update readline-6.0-3.el6.x86_64
yum install *readline*i686
yum update zlib-1.2.3-27.el6.x86_64
yum install *zlib*i686
&lt;/pre&gt;

Once, I got the all required 32-bit libraries, I have tried to compile the postgresql as below.

&lt;pre class=&quot;prettyprint&quot;&gt;
[root@localhost build]# CFLAGS=-m32 LDFLAGS=-m32 CXXFLAGS=-m32 ./configure --prefix=/opt/PostgreSQL/build
[root@localhost build]# make -j 4; make install;
....
make[1]: Leaving directory `/root/Downloads/postgresql-9.0.17/config&#39;
PostgreSQL installation complete.
&lt;/pre&gt;

It seems, postgresql has built successfully on 64-bit machine as a 32-bit application.
&lt;br/&gt;
&lt;br/&gt;
Checking for the confirmation from OS, PG.

&lt;pre class=&quot;prettyprint&quot;&gt;
postgres=# SELECT version();
&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; version &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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
-------------------------------------------------------------------------------------------------------------------
&amp;nbsp;PostgreSQL 9.0.17 on x86_64-unknown-linux-gnu, compiled by GCC gcc (GCC) 4.4.6 20110731 (Red Hat 4.4.6-3), 32-bit
(1 row)

[root@localhost build]# file /sbin/init
/sbin/init: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
&lt;/pre&gt;

And, at the end, I have the postgresql as 32-bit application in 64-bit machine.
&lt;br/&gt;&lt;br/&gt;
Thank you for reading, and please comment on this, if you have any questions.
&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;
--Dinesh Kumar</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/2055698180230497137/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2014/06/32-bit-postgresql-compilation-on-64-bit.html#comment-form' title='13 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/2055698180230497137'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/2055698180230497137'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2014/06/32-bit-postgresql-compilation-on-64-bit.html' title='32-bit PostgreSQL Compilation On 64-bit CentOS 6.x'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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>13</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2844187126830320432.post-4580051939221643842</id><published>2014-04-24T13:42:00.000+05:30</published><updated>2014-04-26T17:08:55.260+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="bucardo postgresql"/><category scheme="http://www.blogger.com/atom/ns#" term="mutli master replication in postgresql"/><title type='text'>N-Node Mutlimaster Replication With Bucardo...!</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Our team recently got&amp;nbsp; a problem, which is to solve the N-Node multi master replication in PostgreSQL.&lt;br /&gt;
&lt;br /&gt;
We all know that, there are some other db engines like Postgres-XC which works in this way. But, we don&#39;t have any tool available in PostgreSQL, except Bucardo.&lt;br /&gt;
&lt;br /&gt;
Bucardo is the nice solution for 2-Nodes. Is there a way we can exceed this limitation from 2 to N..?&lt;br /&gt;
&lt;br /&gt;
As an initial step on this, I have done with 3 Nodes, which I believe, we can extend this upto N. { I might be wrong here.}&lt;br /&gt;
&lt;br /&gt;
Please follow the below steps to set up the 1 - 1 multi master replication.&lt;br /&gt;
&lt;br /&gt;
1. Follow the below steps to get all the pre-requisites for the Bucardo.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;yum install perl-DBIx-Safe
or
apt-get install libdbix-safe-perl

Install the below components from CPAN.

DBI
DBD::Pg
Test::Simple
boolean (Bucardo 5.0 and higher)

Download the latest tarball from &lt;a href=&quot;http://bucardo.org/wiki/Bucardo#Obtaining_Bucardo&quot;&gt;here&lt;/a&gt;.

tar xvfz Bucardo-4.4.8.tar.gz
cd Bucardo-4.4.8
perl Makefile.PL
make
sudo make install
&lt;/pre&gt;
2. We need to create plperl extension in db. For this, download the required active perl to set up or simply do as below.&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;apt-get install postgresql-plperl-9.3
or
yum install postgresql-plperl-9.3

Make a copy of Old $PGLIBPATH/plperl.so
Move the new plperl.so to $PGLIBPATH/plperl.so
&lt;/pre&gt;
3. plperl extension.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;Create extension plperl;
&lt;/pre&gt;
4. Create 3 databases like &quot;node1&quot;, &quot;node2&quot;, &quot;node3&quot;.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;CREATE DATABASE node1;
CREATE DATABASE node2;
CREATE DATABASE node3;
&lt;/pre&gt;
5. Execute below statements on 2 databases (node1, node2).
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;CREATE TABLE test1(t INT PRIMARY KEY);
INSERT INTO test1 VALUES(generate_series(1, 10));
&lt;/pre&gt;
6. Install Bucardo catalog database using the below command.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;postgres@dinesh-VirtualBox:~/Bucardo-4.5.0$ ./bucardo_ctl install
Postgres version is: 9.3
Attempting to create and populate the bucardo database and schema
Database creation is complete
Connecting to database &#39;bucardo&#39; as user &#39;bucardo&#39;
Updated configuration setting &quot;piddir&quot;
Installation is now complete.
&lt;/pre&gt;
7. Adding databases, those will be part of mutli-master replication.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;postgres@dinesh-VirtualBox:~/Bucardo-4.5.0$ ./bucardo_ctl add db db1 dbname=&quot;node1&quot;
Added database &quot;db1&quot;
postgres@dinesh-VirtualBox:~/Bucardo-4.5.0$ ./bucardo_ctl add db db2 dbname=&quot;node2&quot;
Added database &quot;db2&quot;
&lt;/pre&gt;
8. Creating a herd of db1 tables.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;postgres@dinesh-VirtualBox:~/Bucardo-4.5.0$ ./bucardo_ctl add all tables db=db1 herd=db1_herd
Creating herd: db1_herd
New tables added: 1
Already added: 0
&lt;/pre&gt;
9. Creating a sync of this herd from db1-&amp;gt;db2.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;postgres@dinesh-VirtualBox:~/Bucardo-4.5.0$ ./bucardo_ctl add sync db1_to_db2 type=pushdelta source=db1_herd targetdb=db2
Added sync &quot;db1_to_db2&quot;
&lt;/pre&gt;
10. Creating a herd of db2 tables.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;postgres@dinesh-VirtualBox:~/Bucardo-4.5.0$ ./bucardo_ctl add all tables db=db2 herd=db2_herd
Creating herd: db2_herd
New tables added: 1
Already added: 0
&lt;/pre&gt;
11. Creating a sync of this herd from db2-&amp;gt;db1.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;postgres@dinesh-VirtualBox:~/Bucardo-4.5.0$ ./bucardo_ctl add sync db2_to_db1 type=pushdelta source=db2_herd targetdb=db1
Added sync &quot;db2_to_db2&quot;
&lt;/pre&gt;
12. Start the Bucardo process. Default log location for the Bucardo instance is SYSLOG.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;postgres@dinesh-VirtualBox:~/Bucardo-4.5.0$ ./bucardo_ctl start
Checking for existing processes
Removing /tmp/fullstopbucardo
Starting Bucardo

postgres@dinesh-VirtualBox:~/Bucardo-4.5.0$ ps -ef|grep bucardo
postgres 2740 1128 0 21:26 ? 00:00:00 postgres: bucardo bucardo [local] idle
postgres 2743 1128 0 21:26 ? 00:00:00 postgres: bucardo node1 [local] idle
&lt;/pre&gt;
13. Check the DML activities between these two nodes.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;node1=# INSERT INTO test1 VALUES(-1);
INSERT 0 1
node1=# \c node2
node2=# SELECT * FROM test1 WHERE t=-1;
 t
---
-1
(1 row)

node2=# INSERT INTO test1 VALUES(-2)
INSERT 0 1
node2=# \c node1
node1=# SELECT * FROM test1 WHERE t=-2;
 t
---
-2
(1 row)
&lt;/pre&gt;
14. Check the status from the below command.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;postgres@dinesh-VirtualBox:~/Bucardo-4.5.0$ ./bucardo_ctl status
Days back: 3&amp;nbsp; User: bucardo&amp;nbsp; Database: bucardo&amp;nbsp; PID of Bucardo MCP: 2739
Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Type&amp;nbsp; State PID&amp;nbsp; Last_good Time&amp;nbsp; I/U/D Last_bad Time
==========+=====+=====+====+=========+=====+=====+========+====
db1_to_db2| P&amp;nbsp;&amp;nbsp; |idle |2746|7m49s&amp;nbsp;&amp;nbsp;&amp;nbsp; |0s&amp;nbsp;&amp;nbsp; |1/0/0|unknown |&amp;nbsp;&amp;nbsp;&amp;nbsp; 
db2_to_db1| P&amp;nbsp;&amp;nbsp; |idle |2745|6m11s&amp;nbsp;&amp;nbsp;&amp;nbsp; |0s&amp;nbsp;&amp;nbsp; |1/0/0|unknown |&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&lt;/span&gt;
&lt;/pre&gt;
It seems everything is perfect, and data is replicating from node1 to node2 and vice-versa.
Now, let&#39;s try to add a new node, &quot;node3&quot; as part of this mutli-master replication.
&lt;br /&gt;&lt;br /&gt;
15. Add new replication database to Bucardo.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;postgres@dinesh-VirtualBox:~/Bucardo-4.5.0$ ./bucardo_ctl add db db3 dbname=&quot;node3&quot;
Added database &quot;db3&quot;
&lt;/pre&gt;
16. Dump and restore of test1 table from either node1 or node2.
&lt;br /&gt;&lt;br/&gt;
17. Create a herd of db3 tables
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;postgres@dinesh-VirtualBox:~/Bucardo-4.5.0$ ./bucardo_ctl add all tables db=db3 herd=db3_herd
Creating herd: db3_herd
New tables added: 1
Already added: 0
&lt;/pre&gt;
18. Create a new sync from db2-&amp;gt;db3, db3-&amp;gt;db2.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;postgres@dinesh-VirtualBox:~/Bucardo-4.5.0$ ./bucardo_ctl add sync db2_to_db3 type=pushdelta source=db2_herd targetdb=db3
Added sync &quot;db2_to_db3&quot;
postgres@dinesh-VirtualBox:~/Bucardo-4.5.0$ ./bucardo_ctl add sync db3_to_db2 type=pushdelta source=db3_herd targetdb=db2
Added sync &quot;db3_to_db2&quot;
&lt;/pre&gt;
&lt;br/&gt;
19. Restart the Bucardo to check for the latest node status.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;postgres@dinesh-VirtualBox:~/Bucardo-4.5.0$ ./bucardo_ctl stop
Creating /tmp/fullstopbucardo ... Done
&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;
postgres@dinesh-VirtualBox:~/Bucardo-4.5.0$ ./bucardo_ctl start
Checking for existing processes
Removing /tmp/fullstopbucardo
Starting Bucardo
&amp;nbsp;&lt;/span&gt;

&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;postgres@dinesh-VirtualBox:~/Bucardo-4.5.0$ ./bucardo_ctl status
Days back: 3&amp;nbsp; User: bucardo&amp;nbsp; Database: bucardo&amp;nbsp; PID of Bucardo MCP: 2553
Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Type&amp;nbsp; State PID&amp;nbsp; Last_good Time&amp;nbsp; I/U/D Last_bad Time
==========+=====+=====+====+=========+=====+=====+========+====
db1_to_db2| P&amp;nbsp;&amp;nbsp; |idle |2563|1s&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |0s&amp;nbsp;&amp;nbsp; |0/0/0|unknown |&amp;nbsp;&amp;nbsp;&amp;nbsp; 
db2_to_db1| P&amp;nbsp;&amp;nbsp; |idle |2560|1s&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |0s&amp;nbsp;&amp;nbsp; |0/0/0|unknown |&amp;nbsp;&amp;nbsp;&amp;nbsp; 
db2_to_db3| P&amp;nbsp;&amp;nbsp; |idle |2561|0s&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |0s&amp;nbsp;&amp;nbsp; |1/0/1|unknown |&amp;nbsp;&amp;nbsp;&amp;nbsp; 
db3_to_db2| P&amp;nbsp;&amp;nbsp; |idle |2562|0s&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |0s&amp;nbsp;&amp;nbsp; |0/0/0|unknown |&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;/pre&gt;
20. Here is the small hack, which makes you to embed this db3 into the multi master replication.

As Burcardo replication system works based on triggers, we need to make all the triggers what it created on nodes to &quot;ENABLE ALWAYS&quot; for each table.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;Node1
-=-=-
node1=# \d test1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Table &quot;public.test1&quot;
&amp;nbsp;Column |&amp;nbsp; Type&amp;nbsp;&amp;nbsp; | Modifiers 
--------+---------+-----------
&amp;nbsp;t&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; | integer | not null
Indexes:
&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;test1_pkey&quot; PRIMARY KEY, btree (t)
Triggers:
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;b&gt;bucardo_add_delta&lt;/b&gt; AFTER INSERT OR DELETE OR UPDATE ON test1 FOR EACH ROW EXECUTE PROCEDURE bucardo.bucardo_add_delta_t()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;b&gt; bucardo_triggerkick_db1_to_db2 &lt;/b&gt;AFTER INSERT OR DELETE OR UPDATE OR TRUNCATE ON test1 FOR EACH STATEMENT EXECUTE PROCEDURE bucardo.bucardo_triggerkick_db1_to_db2()

&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;node1=# ALTER TABLE test1 ENABLE ALWAYS TRIGGER bucardo_add_delta;
ALTER TABLE
node1=# ALTER TABLE test1 ENABLE ALWAYS TRIGGER bucardo_triggerkick_db1_to_db2;
ALTER TABLE&lt;/span&gt;

&lt;/pre&gt;
Do &quot;ENABLE ALWAYS&quot; these two triggers on this table. Similarly, do the same activity on all nodes.
&lt;br/&gt;&lt;br/&gt;
Testing Multi-Master replication.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;node3=# INSERT INTO test1 VALUES(-1010);
INSERT 0 1
node3=# \c node2
node2=# SELECT * FROM test1 WHERE t=-1010;
&amp;nbsp;&amp;nbsp; t&amp;nbsp;&amp;nbsp; 
-------
&amp;nbsp;-1010
(1 row)

node2=# \c node1
node1=# SELECT * FROM test1 WHERE t=-1010;
&amp;nbsp;&amp;nbsp; t&amp;nbsp;&amp;nbsp; 
-------
&amp;nbsp;-1010
(1 row)


node2=# INSERT INTO test1 VALUES(-2020);&amp;nbsp; 
INSERT 0 1
node2=# \c node3
node3=# SELECT * FROM test1 WHERE t=-2020;
&amp;nbsp;&amp;nbsp; t&amp;nbsp;&amp;nbsp; 
-------
&amp;nbsp;-2020
(1 row)

node3=# \c node1
node1=# SELECT * FROM test1 WHERE t=-2020;
&amp;nbsp;&amp;nbsp; t&amp;nbsp;&amp;nbsp; 
-------
&amp;nbsp;-2020
(1 row)&lt;/pre&gt;
Seems Bucardo is doing 3 node mulit master replication. Thanks to Bucardo Team. :)&lt;br /&gt;
&lt;br /&gt;
--Dinesh Kumar
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/4580051939221643842/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2014/04/n-node-mutlimaster-replication-with.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/4580051939221643842'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/4580051939221643842'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2014/04/n-node-mutlimaster-replication-with.html' title='N-Node Mutlimaster Replication With Bucardo...!'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2844187126830320432.post-8853863311908162777</id><published>2014-04-04T09:08:00.000+05:30</published><updated>2014-04-24T13:41:46.617+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Normal user as super user"/><category scheme="http://www.blogger.com/atom/ns#" term="pg_stat_activity as non super user."/><title type='text'>Normal User As Super User</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;style type=&quot;text/css&quot;&gt;P { margin-bottom: 0.21cm; }&lt;/style&gt;


&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0.42cm;&quot;&gt;
&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: ArialMT, sans-serif;&quot;&gt;Recently
i faced a problem with some catalog views, which do not give you the
complete information as a normal user. For example, take
pg_stat_activity, pg_stat_replication, pg_settings, e.t.c. If we run
the above catalog views as non super user, you don&#39;t get the result
what we get as a superuser. This is really a good security between
super user and normal user.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;
&lt;/span&gt;

&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0.42cm;&quot;&gt;
&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: ArialMT, sans-serif;&quot;&gt;What
we need to do, if we want to collect these metrics as normal user. I
think the possible solution is &quot;Write a wrapper function with
security definer as like below&quot; and grant/revoke the required
privileges to the user/public.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;
&lt;/span&gt;

&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0.42cm;&quot;&gt;
&lt;span style=&quot;color: #262626; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: CourierNewPSMT, monospace;&quot;&gt;CREATE
OR REPLACE FUNCTION pg_stat_activity(&lt;br /&gt;RETURNS SETOF
pg_catalog.pg_stat_activity &lt;br /&gt;AS&lt;br /&gt;$$&lt;br /&gt;BEGIN&lt;br /&gt;RETURN
QUERY(SELECT * FROM pg_catalog.pg_stat_activity);&lt;br /&gt;END&lt;br /&gt;$$&lt;br /&gt;LANGUAGE
PLPGSQL SECURITY DEFINER;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;
&lt;/span&gt;
&lt;br /&gt;
&lt;div style=&quot;line-height: 0.64cm; margin-bottom: 0.42cm;&quot;&gt;
&lt;span style=&quot;color: #262626; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: CourierNewPSMT, monospace;&quot;&gt;REVOKE
ALL ON FUNCTION pg_stat_activity() FROM public;&lt;br /&gt;CREATE VIEW
pg_stat_activity AS SELECT * FROM pg_stat_activity(); &lt;br /&gt;REVOKE ALL
ON pg_stat_activity FROM public;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;
&lt;/span&gt;
&lt;br /&gt;
&lt;div style=&quot;line-height: 0.64cm; margin-bottom: 0.42cm;&quot;&gt;
&lt;span style=&quot;color: #262626; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: ArialMT, sans-serif;&quot;&gt;This
is really a good approach to get the statistics from
pg_stat_activity. What if i need the values from&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #262626; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier, monospace;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #262626; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: ArialMT, sans-serif;&quot;&gt;pg_stat_replication,
pg_settings or some tablespace information as normal user. So, do we
need to create&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #262626; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier, monospace;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #262626; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: ArialMT, sans-serif;&quot;&gt;wrapper
function for each catalog view ? { I assume, this is the only way to
get these metrics by creating&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #262626; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier, monospace;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #262626; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: ArialMT, sans-serif;&quot;&gt;required
wrapper functions for each catalog view.}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;
&lt;/span&gt;
&lt;br /&gt;
&lt;div style=&quot;line-height: 0.64cm; margin-bottom: 0.42cm;&quot;&gt;
&lt;span style=&quot;color: #262626; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: ArialMT, sans-serif;&quot;&gt;Rather
than creating these multiple catalog views, here is the simple &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #f80000; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: ArialMT, sans-serif;&quot;&gt;&lt;b&gt;hack&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #262626; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: ArialMT, sans-serif;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;
we can do without creating the&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #262626; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier, monospace;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #262626; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: ArialMT, sans-serif;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;wrapper
functions. Here i am going to update the pg_authid catalog by
creating a single function&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #262626; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Courier, monospace;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #262626; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: ArialMT, sans-serif;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;as
below. I know, this is &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #f80000; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: ArialMT, sans-serif;&quot;&gt;&lt;b&gt;against
the security policy&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #262626; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: ArialMT, sans-serif;&quot;&gt;&lt;b&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #262626; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: ArialMT, sans-serif;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;and
wanted to share one possible and simple way.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;
&lt;/span&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span style=&quot;color: #f80000;&quot;&gt;&lt;b&gt;Function&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;
&lt;/span&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;CREATE OR REPLACE FUNCTION make_me_superuser(isSuper bool)
RETURNS
VOID
AS $$
BEGIN
UPDATE pg_catalog.pg_authid SET
rolsuper=$1::boolean where rolname=&amp;lt;role name&amp;gt;;
END;
$$
LANGUAGE PLPGSQL SECURITY DEFINER;
REVOKE ALL ON FUNCTION make_me_superuser(bool) FROM public;
GRANT EXECUTE ON FUNCTION make_me_superuser(bool) TO &amp;lt;role name&amp;gt;;
&lt;/pre&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;
&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;span style=&quot;color: #f80000;&quot;&gt;&lt;b&gt;Sample
Case&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 0.64cm; margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;
&lt;/span&gt;
&lt;br /&gt;
&lt;div style=&quot;font-weight: normal; line-height: 0.64cm; margin-bottom: 0.42cm;&quot;&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;color: #1a1a1a; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: CourierNewPSMT, monospace;&quot;&gt;postgres=&amp;gt;BEGIN WORK;
BEGIN
postgres=&amp;gt; select make_me_superuser(TRUE);
&lt;span style=&quot;color: #3c0042;&quot;&gt;make_me_superuser
-------------------
(1 row)
postgres=&amp;gt; show data_directory;
  data_directory&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;
--------------------------------------------&lt;span style=&quot;color: #1a1a1a;&quot;&gt;&lt;span style=&quot;font-family: CourierNewPSMT, monospace;&quot;&gt;
C:/Program Files (x86)/PostgreSQL/9.2/data
&lt;span style=&quot;color: #3c0042;&quot;&gt;(1 row)
postgres=&amp;gt; select make_me_superuser(false);
make_me_superuser
-------------------
(1 row)&lt;/span&gt;
postgres=&amp;gt; END WORK;
COMMIT&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;
&lt;/span&gt;
&lt;br /&gt;
&lt;div style=&quot;font-weight: normal; line-height: 0.64cm; margin-bottom: 0.35cm;&quot;&gt;
&lt;span style=&quot;color: #1a1a1a; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: ArialMT, sans-serif;&quot;&gt;Since
we are running this in a transaction mode, which restricts the other same user
session&#39;s superuser activities.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;
&lt;/span&gt;
&lt;br /&gt;
&lt;div style=&quot;line-height: 0.64cm; margin-bottom: 0.35cm;&quot;&gt;
&lt;span style=&quot;color: #1a1a1a; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: ArialMT, sans-serif;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;**Don&#39;t
implement this in production servers, where your security is crucial.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;
&lt;br /&gt;
--Dinesh Kumar
&lt;/span&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/8853863311908162777/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2014/04/normal-user-as-super-user.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/8853863311908162777'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/8853863311908162777'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2014/04/normal-user-as-super-user.html' title='Normal User As Super User'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2844187126830320432.post-7785451757593482124</id><published>2014-04-02T11:59:00.000+05:30</published><updated>2014-06-29T14:50:53.760+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Cartoon in PG"/><category scheme="http://www.blogger.com/atom/ns#" term="Fun With PostgreSQL"/><title type='text'>Cartoon in pg.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
I hope this gives you a bit FUN with pg SQL.&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/AVvXsEihBKvonL3aiJyTDrcgtaU5H0r_NNaAIpw3Qo80Sb09pAi_so0aKibJp0IZbhuQ1ZZOEQ0m2l3W7PuENbbnebYQeYvGrL-13Qq3tpjFkGAyW4oV96hICDCI-fOeeNZJSFZtgDAh5xa7K4s/s1600/Screen+Shot+2013-11-18+at+3.24.21+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihBKvonL3aiJyTDrcgtaU5H0r_NNaAIpw3Qo80Sb09pAi_so0aKibJp0IZbhuQ1ZZOEQ0m2l3W7PuENbbnebYQeYvGrL-13Qq3tpjFkGAyW4oV96hICDCI-fOeeNZJSFZtgDAh5xa7K4s/s640/Screen+Shot+2013-11-18+at+3.24.21+PM.png&quot; height=&quot;250&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint sql&quot;&gt;select * from
(select array_to_string(array_agg(CASE WHEN (power((xx.x-25),2)/130+power((yy.y-25),2)/130)=1 THEN
&#39;$&#39; WHEN (sqrt(power(xx.x-20,2)+power(yy.y-20,2)))&amp;lt;2 THEN &#39;#&#39; WHEN (sqrt(power(xx.x-20,2)+power(yy.y-30,2)))&amp;lt;2 THEN
 &#39;#&#39; WHEN (sqrt(power(xx.x-29,2)+power(yy.y-25,2)))&amp;lt;4 THEN &#39;#&#39; WHEN (power((xx.x-10),2)/40+power((yy.y-10),2)/40)=1 THEN
 &#39;$&#39; WHEN (power((xx.x-10),2)/40+power((yy.y-40),2)/40=1) THEN &#39;$&#39; ELSE &#39; &#39; END),&#39; &#39;) as cartoon from
(select generate_series(1,40) as x) as xx,(select generate_series(1,50) as y) as yy group by xx.x order by xx.x)
as co_ord;
&lt;/pre&gt;
&lt;br /&gt;

Oracle Mode

&lt;pre class=&quot;prettyprint sql&quot;&gt;

CREATE OR REPLACE TYPE series AS TABLE OF NUMBER;

CREATE OR REPLACE FUNCTION generate_series(n INT, m INT) RETURN series PIPELINED
IS
BEGIN
FOR i IN n..m LOOP
PIPE ROW (i);
END LOOP;
RETURN;
END;

SELECT 
  REPLACE(WM_CONCAT(
    CASE
        WHEN (power((xx.COLUMN_VALUE-25),2)/130+power((yy.COLUMN_VALUE-25),2)/130)=1
        THEN &#39;$&#39;
        WHEN (sqrt(power(xx.COLUMN_VALUE-20,2)+power(yy.COLUMN_VALUE-20,2)))&lt;2
        THEN &#39;#&#39;
        WHEN (sqrt(power(xx.COLUMN_VALUE-20,2)+power(yy.COLUMN_VALUE-30,2)))&lt;2
        THEN &#39;#&#39;
        WHEN (sqrt(power(xx.COLUMN_VALUE-29,2)+power(yy.COLUMN_VALUE-25,2)))&lt;4
        THEN &#39;#&#39;
        WHEN (power((xx.COLUMN_VALUE-10),2)/40+power((yy.COLUMN_VALUE-10),2)/40)=1
        THEN &#39;$&#39;
        WHEN (power((xx.COLUMN_VALUE-10),2)/40+power((yy.COLUMN_VALUE-40),2)/40=1)
        THEN &#39;$&#39;
        ELSE &#39; &#39;
      END
    ), &#39;,&#39;, &#39; &#39;) cartoon
FROM
  ( SELECT * FROM TABLE(generate_series(1, 40))) xx,
  ( SELECT * FROM TABLE(generate_series(1, 50))) yy
  GROUP BY xx.COLUMN_VALUE
  ORDER BY xx.COLUMN_VALUE;
  
&lt;/pre&gt;

Dinesh Kumar&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/7785451757593482124/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2014/04/cartoon-in-pg.html#comment-form' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/7785451757593482124'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/7785451757593482124'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2014/04/cartoon-in-pg.html' title='Cartoon in pg.'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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/AVvXsEihBKvonL3aiJyTDrcgtaU5H0r_NNaAIpw3Qo80Sb09pAi_so0aKibJp0IZbhuQ1ZZOEQ0m2l3W7PuENbbnebYQeYvGrL-13Qq3tpjFkGAyW4oV96hICDCI-fOeeNZJSFZtgDAh5xa7K4s/s72-c/Screen+Shot+2013-11-18+at+3.24.21+PM.png" height="72" width="72"/><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2844187126830320432.post-4513169058124182175</id><published>2014-03-11T15:48:00.002+05:30</published><updated>2014-03-11T15:55:41.933+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="non zero min value"/><title type='text'>How to get non zero min value from MIN(0, 1, 2)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hi,&lt;br /&gt;
&lt;br /&gt;
Today, i have faced an interesting problem like below.&lt;br /&gt;
&lt;br /&gt;
I want to get MIN(UNNEST(ARRAY[0, 1, 2, ....])) &amp;nbsp;as non-zero small element. In this case, it&#39;s 1.&lt;br /&gt;
&lt;br /&gt;
Below is my problem description.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-SQL&quot;&gt;
postgres=# SELECT SUM(val), MAX(val), MIN(val)
FROM
(
SELECT UNNEST(ARRAY[1, 2, 3]) val
UNION ALL
--Appending some dummy rows, for getting what i would like to expect.
SELECT UNNEST(ARRAY[0, 0, 0]) val
) AS FOO;
&amp;nbsp;sum | max | min
-----+-----+-----
&amp;nbsp; &amp;nbsp;6 | &amp;nbsp;3 &amp;nbsp;| 0
(1 row)
&lt;div&gt;
&lt;/div&gt;
&lt;/pre&gt;

&lt;br/&gt;
As you see, i can able to identify the sum, max without any problem. But when it comes to &quot;min&quot;, i am getting the value as 0. But, I want the minimum as 1 as per my requirement. I can able to get the min, max, sum from the first array it self. But, my implementation doesn&#39;t allow this. :(
&lt;br/&gt;

&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
I have tried it in so many ways, and finally found the following solution. I believe, there will be some better ways also, but just wanted to keep a note on this.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;pre class=&quot;prettyprint lang-SQL&quot;&gt;
postgres=# SELECT SUM(val), MAX(val),&amp;nbsp;
COALESCE((SELECT * FROM UNNEST(array_agg(val)) WHERE unnest!=0 ORDER BY unnest ASC LIMIT 1), 0) AS min
postgres-# FROM
postgres-# (
postgres(# SELECT UNNEST(ARRAY[1, 2, 3]) val
postgres(# UNION ALL
postgres(# SELECT UNNEST(ARRAY[0, 0, 0]) val
postgres(# ) AS FOO;
&amp;nbsp;sum | max | min&amp;nbsp;
-----+-----+-----
&amp;nbsp; &amp;nbsp;6 | &amp;nbsp; 3 | &amp;nbsp; 1

(1 row)
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Hope it helps to someone.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br/&gt;
Dinesh Kumar&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/4513169058124182175/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2014/03/how-to-get-non-zero-min-value-from-min0.html#comment-form' title='11 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/4513169058124182175'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/4513169058124182175'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2014/03/how-to-get-non-zero-min-value-from-min0.html' title='How to get non zero min value from MIN(0, 1, 2)'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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>11</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2844187126830320432.post-952357744593681812</id><published>2014-02-06T17:13:00.003+05:30</published><updated>2014-02-06T22:55:52.267+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Oracle Architecture"/><category scheme="http://www.blogger.com/atom/ns#" term="Oracle Architecture Diagram."/><title type='text'>Oracle Architecture</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
Hi&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Isn&#39;t the nice&amp;nbsp;way to represent the Oracle Architecture.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Soon i will be posting the PostgreSQL architecture as well.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&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/AVvXsEgOySRvE4tyjCloI5bfuLoBh3ffWzqPBAyd2HekNV4iqpweO8T1X_sjBqDkuN4pWREeM4IhpamzWoi1n8lng9GgkVuQPY4qBeOV0vuufsTc2QVXTFYZEStCCLNsMrx336dwwRPoQuwLWNQ/s1600/Oracle+Architecture.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOySRvE4tyjCloI5bfuLoBh3ffWzqPBAyd2HekNV4iqpweO8T1X_sjBqDkuN4pWREeM4IhpamzWoi1n8lng9GgkVuQPY4qBeOV0vuufsTc2QVXTFYZEStCCLNsMrx336dwwRPoQuwLWNQ/s1600/Oracle+Architecture.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #666666; font-family: &#39;Trebuchet MS&#39;, Trebuchet, sans-serif; font-size: 13px; line-height: 18.200000762939453px;&quot;&gt;Dinesh Kumar&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/952357744593681812/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2014/02/oracle-architecture.html#comment-form' title='17 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/952357744593681812'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/952357744593681812'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2014/02/oracle-architecture.html' title='Oracle Architecture'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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/AVvXsEgOySRvE4tyjCloI5bfuLoBh3ffWzqPBAyd2HekNV4iqpweO8T1X_sjBqDkuN4pWREeM4IhpamzWoi1n8lng9GgkVuQPY4qBeOV0vuufsTc2QVXTFYZEStCCLNsMrx336dwwRPoQuwLWNQ/s72-c/Oracle+Architecture.PNG" height="72" width="72"/><thr:total>17</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2844187126830320432.post-1372085902559390690</id><published>2013-12-31T23:27:00.001+05:30</published><updated>2015-04-27T20:57:30.013+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Failback in postgres"/><category scheme="http://www.blogger.com/atom/ns#" term="failback postgres setup"/><category scheme="http://www.blogger.com/atom/ns#" term="Faillback in pgpool"/><category scheme="http://www.blogger.com/atom/ns#" term="pgpool postgres setup"/><title type='text'>Pgpool Configuration &amp; Failback</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
I would like to share the pgpool configuration, and it&#39;s failback mechanism in this post.&lt;br /&gt;
&lt;br /&gt;
Hope it will be helpful to you in creating pgpool and it&#39;s failback setup.&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;, Arial, Helvetica, sans-serif;&quot;&gt;Pgpool Installation &amp;amp; Configuration&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;1. Download the pgpool from below link(Latest version is 3.2.1).&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; http://www.pgpool.net/mediawiki/index.php/Downloads&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt; 2. Untart the pgpool-II-3.2.1.tar.gz and goto pgpool-II-3.2.1 directory.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
3. Install the pgpool by executing the below commands:&lt;br /&gt;
&amp;nbsp;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;./configure ­­prefix=/opt/PostgreSQL92/ ­­--with­-pgsql­-includedir=/opt/PostgreSQL92/include/
--with­-pgsql­-libdir=/opt/PostgreSQL92/lib/
make
make install
&lt;/pre&gt;
4. You can see the pgpool files in /opt/PostgreSQL92/bin location.&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;/opt/PostgreSQL92/bin $ ls
clusterdb&amp;nbsp;&amp;nbsp; droplang&amp;nbsp; pcp_attach_node&amp;nbsp; pcp_proc_count pcp_systemdb_info&amp;nbsp; pg_controldata&amp;nbsp; pgpool pg_test_fsync pltcl_loadmod&amp;nbsp; reindexdb createdb&amp;nbsp;&amp;nbsp;&amp;nbsp; dropuser&amp;nbsp; pcp_detach_node&amp;nbsp; pcp_proc_info createlang&amp;nbsp; ecpg&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pcp_node_count&amp;nbsp;&amp;nbsp; pcp_promote_node oid2name&amp;nbsp; pcp_pool_status&amp;nbsp; pcp_stop_pgpool&amp;nbsp;

/opt/PostgreSQL92/bin $ ./pgpool ­version
pgpool­II version 3.2.1 (namameboshi)

&lt;/pre&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;, Arial, Helvetica, sans-serif;&quot;&gt;Pgpool Parameters&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;listen_addresses = &#39;*&#39; &lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;# This parameter tells about, which clients can connect to the pgpool. If we mention the listen_addresses = &#39;ip1,ip2&#39;, then these two ip&#39;s only can access this pgpool.
&amp;nbsp;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;port = 9999&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt; # We can define the pgpool port using this parameter.
&amp;nbsp;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;socket_dir = &#39;/tmp&#39; &lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;# This parameter tells about the socket directory.&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;pcp_port = 9898&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt; # PCP is pgpool admin utility port. Using pcp port, we can execute some node attach and detaches.
&amp;nbsp;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;pcp_socket_dir = &#39;/tmp&#39;&amp;nbsp;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;# PCP socket directory.&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;backend_hostname0 = &#39;0.176.112.188&#39;&amp;nbsp;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;# Node 0 Host IP&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
backend_port0 = 5432&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;# Node 0 Port&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
backend_weight0 = 1 &lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;# Node 0 Weight in load balance mode.&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
backend_data_directory0 = &#39;/opt/PostgreSQL92/data&#39;&amp;nbsp;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;# Node 0 Data Direcotry&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
backend_flag0 = &#39;ALLOW_TO_FAILOVER&#39;&amp;nbsp;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;# Node 0 can allow failover or not.&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
backend_hostname1 = &#39;0.176.112.189&#39;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;# Node 1 Host IP
backend_port1 = 5432&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;# Node 1 Port&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
backend_weight1 = 1&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt; # Node 1 Weight in load balance mode.&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
backend_data_directory1 = &#39;/opt/PostgreSQL92/data&#39;&amp;nbsp;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;# Node 1 Data Directory&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
backend_flag1 = &#39;ALLOW_TO_FAILOVER&#39;&amp;nbsp;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;# Node 1 can allow failover or not.&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
enable_pool_hba = on&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt; # Enabling pool hba authentication like pg_hba authentication. In any case, we need to have the same pg_hba.conf entries in pool_hba.conf.If we do have different values, then we some of the users can face connectivity issues. Hence, requesting you to make sure both values are same. If we enable the pool_hba, then we need to create &quot;pool_passwd&quot; file in the pgpool.conf paramter&#39;s location. pool_passwd must contain the values &quot;username:md5password&quot;. You can get this username and passwords from &quot;pg_shadow&quot; postgres table.&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
authentication_timeout = 60 &lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;# Pgpool client authentication timeout.&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
num_init_children = 32&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt; # This parameter tells about how many initial pg connections need to make while pgpool starts.&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
max_pool = 3 &lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;# This parameter defines about how many pools for each num_init_children connections.&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
pid_file_name = &#39;/opt/PostgreSQL92/data/pgpool.pid&#39;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt; # This parameter defines where the pgpool.pid file need to place.&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
replication_mode = off&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt; # This parameter need to off, if we are using pgpool on top of Slony/Streaming replication. We can also enable this parameter, if you want the pgpool replication rather than Slony/Streaming.&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
load_balance_mode = off &lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;# This parameter need to on, if we are doing the load balance. i.e, if you want to distribute the &quot;SELECT&quot; queries between the primary and slave servers, then we need to enable this parameter. By enabling this parameter, we can balance work load between the primary and slave.&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
white_function_list = &#39;&#39; &lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;# Readonly functions/procedures we can mention in this list.&amp;nbsp;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;black_function_list = &#39;nextval,setval&#39; &lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;# Readwrite functions/procedures we need to mention in this list.&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
recovery_user = &#39;postgres&#39; &lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;# We need to provide recovery user name.&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
recovery_password = &#39;adminedb&#39;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt; # We need to provide recovery user password. The above two parameters works only to the pcp commands like pcp_recovery_command, pcp_attach_node, pcp_detach_node.&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
revery_1st_stage_command = &#39;basebackup&#39; &lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;# We need to provide recovery 1st command which is doing the failback.&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
You can find more details of these parameters from the below link.
http://www.pgpool.net/docs/latest/tutorial-en.html&lt;/span&gt;

&lt;/pre&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;&lt;b&gt;Pgpool start and stop commands&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
1. Start the pgpool using below command:

&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;./pgpool ­f /opt/PostgreSQL92/etc/pgpool.conf -­F /opt/PostgreSQL92/etc/pcp.conf -a /opt/PostgreSQL92/etc/pool_hba.conf -­d -D -n &amp;gt;/opt/PostgreSQL92/data/pgpool.log 2&amp;gt;&amp;amp;1 &amp;amp;
&lt;/pre&gt;
2. Check whether pgpool status:
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;postgres~/bin&amp;gt; ps ­ef|grep pgpool
postgres  4288  3754  0 07:55 pts/1    00:00:00 ./pgpool ­f
/opt/PostgreSQL92/etc/pgpool.conf -F /opt/PostgreSQL92/etc/pcp.conf
­a /opt/PostgreSQL92/etc/pool_hba.conf -d -­D -­n
postgres  4289  4288  0 07:55 pts/1
connection request
&lt;/pre&gt;
3. Connect to database using pgpool port 9999.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;postgres@localhost:~/bin&amp;gt; psql ­p 9999
Password:
psql.bin (9.2.1)

Type &quot;help&quot; for help.
postgres=# show port;

 port
­­­­­­ 5432
(1 row)
&lt;/pre&gt;
4. You can stop the pgpool by using below command:
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;./pgpool ­f /opt/PostgreSQL92/etc/pgpool.conf -F /opt/PostgreSQL92/etc/pcp.conf -a /opt/PostgreSQL92/etc/pool_hba.conf ­-m fast stop
&lt;/pre&gt;
5. you can reload the pgpool by using below command:
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;./pgpool ­f /opt/PostgreSQL92/etc/pgpool.conf -F /opt/PostgreSQL92/etc/pcp.conf -a /opt/PostgreSQL92/etc/pool_hba.conf reload
&lt;/pre&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;, Arial, Helvetica, sans-serif;&quot;&gt;Pgpool Failback&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
Failback is one of the features of PGPOOL which will re-initiate the failed master as a new slave server to the new master. For doing this operation, we need to follow the below steps.&lt;br /&gt;
1) Go to the Pgpool installer location on new master server.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;cd /tmp/pgpool­II­3.2.1/sql/pgpool­recovery
export PATH=/opt/PostgreSQL92/bin:$PATH
make
make install
&lt;/pre&gt;
2) Then execute the pgpool-recovery.sql file in &quot;template1&quot; database of new master server.

&lt;br /&gt;
3) Then prepare a script &quot;basebackup&quot; &amp;amp; &quot;pgpool_remote_start&quot; &amp;amp; &quot;test1.sh&quot; as like attached scripts and place in new master&#39;s data directory.

&lt;br /&gt;
4) Then include the following parameters in pgpool.conf where the pgpool instance is running . Once the modifications done,then reload the pgpool using the following command.

&lt;span style=&quot;color: red;&quot;&gt;Reload Command&lt;/span&gt;
­­­­­­­­­­­­­­&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;/opt/PostgreSQL92/bin/pgpool -­f /opt/PostgreSQL92/etc/pgpool.conf -F /opt/PostgreSQL92/etc/pcp.conf -a /opt/PostgreSQL92/etc/pool_hba.conf reload
&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: red;&quot;&gt;Pgpool Parameters&lt;/span&gt;
­­­­­­­­­­­­­­­­­&lt;pre class=&quot;prettyprint lang-*&quot;&gt;recovery_user = &#39;postgres&#39;
recovery_password = &#39;adminedb&#39;
recovery_1st_stage_command = &#39;basebackup&#39;
&lt;/pre&gt;
&lt;/pre&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
**Note: recovery_user credentials must match with the pcp.conf credentials.&lt;/span&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
5) As a final step, we need to execute the pcp_recovery_command from either new master or new slave as shown below.
&lt;/div&gt;
&lt;pre&gt;&lt;pre class=&quot;prettyprint lang-*&quot;&gt;/opt/PostgreSQL92/bin/pcp_recovery_node ­d 1 0.176.112.189 9898
postgres adminedb 0
DEBUG: send: tos=&quot;R&quot;, len=46
DEBUG: recv: tos=&quot;r&quot;, len=21, data=AuthenticationOK
DEBUG: send: tos=&quot;D&quot;, len=6
DEBUG: recv: tos=&quot;c&quot;, len=20, data=CommandComplete
DEBUG: send: tos=&quot;X&quot;, len=4
&lt;/pre&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;If we get the above kind of message from the recovery command, then our setup has been accomplished.
pcp_recovery_node Explanation
­­­­­­­­­­­­­­­­­­­­­­­­­­­­­  ­d, ­debug : enable debug message (optional)
  timeout     : connection timeout value in seconds. command exits on timeout
  hostname    : pgpool­II hostname
  port#       : PCP port number
  username    : username for PCP authentication
  password    : password for PCP authentication
  nodeID      : ID of a node to recover&lt;/span&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;, Arial, Helvetica, sans-serif;&quot;&gt;test1.sh&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;#!/bin/sh
export PATH=/opt/PostgreSQL92/bin:$PATH
export LD_LIBRARY_PATH=/opt/PostgreSQL92/lib:$LD_LIBRARY_PATH
export PGPASSWORD=adminedb
mv /opt/PostgreSQL92/data1 /opt/PostgreSQL92/data_old
mv /opt/PostgreSQL92/backup /opt/PostgreSQL92/data1
echo &quot;restore_command = &#39;cp /var/arch_test/%f %p&#39;&quot;&amp;gt;/opt/PostgreSQL92/data1/recovery.conf
echo &quot;standby_mode = &#39;on&#39;&quot;&amp;gt;&amp;gt;/opt/PostgreSQL92/data1/recovery.conf
echo &quot;primary_conninfo = &#39;host=0.176.112.188 port=5433 user=replication password=replication application_name=Async_Rep&#39;&quot;&amp;gt;&amp;gt;/opt/PostgreSQL92/data1/recovery.conf
rm -f /opt/PostgreSQL92/data1/_Promote_Me_Primary_Is_Down_5433
echo &quot;trigger_file = &#39;/opt/PostgreSQL92/data1/_Promote_Me_Primary_Is_Down_5433&#39;&quot;&amp;gt;&amp;gt;/opt/PostgreSQL92/data1/recovery.conf
&lt;/pre&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;, Arial, Helvetica, sans-serif;&quot;&gt;basebackup&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;#!/bin/sh
export PATH=/opt/PostgreSQL92/bin:$PATH
export LD_LIBRARY_PATH=/opt/PostgreSQL92/lib:$LD_LIBRARY_PATH
export PGPASSWORD=adminedb
echo &quot;archive_command = &#39;cp %p /var/arch_test/%f &amp;amp;&amp;amp; scp %p postgres@0.176.112.189:/var/arch_test/%f&#39;&quot; &amp;gt;&amp;gt; /opt/PostgreSQL92/data1/postgresql.conf
pg_ctl reload
psql -c &quot;select pg_start_backup(&#39;pgpool_recovery&#39;)&quot; -p 5433
ssh postgres@0.176.112.189 mkdir /opt/PostgreSQL92/backup
rsync -C -a --exclude &#39;postmaster.pid&#39; --exclude &#39;postmaster.opts&#39; --exclude &#39;recovery.done&#39; /opt/PostgreSQL92/data1/ postgres@0.176.112.189:/opt/PostgreSQL92/backup/
export PGPASSWORD=adminedb
psql -c &quot;select pg_stop_backup()&quot; -p 5433
rm -f /opt/PostgreSQL92/data/recovery.done
ssh postgres@0.176.112.189 sh /opt/PostgreSQL92/test1.sh
&lt;/pre&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;pgpool_remote_start&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;#/bin/bash
ssh postgres@0.176.112.189 pg_ctl -D /opt/PostgreSQL92/data1 start&lt;/pre&gt;
&lt;br /&gt;
Dinesh Kumar


&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/1372085902559390690/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2013/12/pgpool-configuration-failback.html#comment-form' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/1372085902559390690'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/1372085902559390690'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2013/12/pgpool-configuration-failback.html' title='Pgpool Configuration &amp; Failback'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2844187126830320432.post-7922441047622370962</id><published>2013-12-27T12:35:00.001+05:30</published><updated>2014-02-06T22:56:10.815+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CSV log postgres regex"/><category scheme="http://www.blogger.com/atom/ns#" term="CSV regex for postgres"/><category scheme="http://www.blogger.com/atom/ns#" term="regex to parse postgresql log files"/><title type='text'>Regex to parse PostgreSQL CSV log files.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;It took sometime to me to understand the powerful concept, i.e, REGEX.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;Below is the REGEX expression to parse the CSV log files, which have been generated by PostgreSQL.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Regex is :-&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;-=-=-=-=-=&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;&lt;span class=&quot;s&quot;&gt;&quot;^((([^,&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;\n\r&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;]*)|(&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;([^&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;]|(&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;\&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;))*&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;)),){22}(&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;([^&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;]|(&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;\&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;))*&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\r\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;]+)&quot;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;Use any regex tools like RegexBuddy, which will give you detailed information about this regular expression.&lt;/span&gt;&lt;/span&gt;

&lt;br /&gt;
&lt;pre&gt;
&lt;/pre&gt;
&lt;pre&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Times;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;Dinesh Kumar&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Times; white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/7922441047622370962/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2013/12/regex-to-parse-postgresql-csv-log-files.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/7922441047622370962'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/7922441047622370962'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2013/12/regex-to-parse-postgresql-csv-log-files.html' title='Regex to parse PostgreSQL CSV log files.'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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-2844187126830320432.post-4756285845171484676</id><published>2013-12-26T15:44:00.001+05:30</published><updated>2014-02-06T22:56:24.404+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Game in postgresql"/><category scheme="http://www.blogger.com/atom/ns#" term="game with postgresql"/><category scheme="http://www.blogger.com/atom/ns#" term="games in postgresql"/><category scheme="http://www.blogger.com/atom/ns#" term="online game with postgresql"/><title type='text'>Game with postgreSQL</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
I developed this game a bit long ago, and would like to share with the world.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Yes, ofcourse, we can optimize the code of c here, but i have concentrated only on desired functionality for this. Once, i got the desired result, i haven&#39;t looked into any of the line in this code. {Very bad habbit, i need to over come this.}&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
I hope you enjoy it, and correct if any problems occurs.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
This game is for only 2 players, which will give you the realtime game feel with your opponent.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
First find the code, and then instructions.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;C Program&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;-=-=-=-=-=-
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-c&quot;&gt;#include &quot;stdio.h&quot;
#include &quot;ncurses.h&quot;
#include &quot;/opt/PostgreSQL/9.0/include/libpq-fe.h&quot;
#include &quot;stdlib.h&quot;
#include &quot;string.h&quot;
char symbol[3];
PGconn * PGconnect(char ch)
{
PGconn *conn;
PGresult *res;
FILE *fp;
int cnt,i=0;
char conn_string[500],hostaddr[32],port[7],dbname[50],user[50],password[50],name[10];
const char *paramValues[2];
fp=fopen(&quot;/tmp/.cred&quot;,&quot;r&quot;);
if(ch==&#39;y&#39;)
{
fscanf(fp,&quot;%[^:]s&quot;,hostaddr);
fscanf(fp,&quot;:%[^:]s&quot;,port);
fscanf(fp,&quot;:%[^:]s&quot;,dbname);
fscanf(fp,&quot;:%[^:]s&quot;,user);
fscanf(fp,&quot;:%s&quot;,password);
sprintf(conn_string,&quot;hostaddr=%s port=%s dbname=%s user=%s password=%s&quot;,hostaddr,port,dbname,user,password);
}
else
{
fscanf(fp,&quot;%[^\n]s&quot;,conn_string);
conn_string[0]=&#39;\0&#39;;
fscanf(fp,&quot;\n%[^:]s&quot;,hostaddr);
fscanf(fp,&quot;:%[^:]s&quot;,port);
fscanf(fp,&quot;:%[^:]s&quot;,dbname);
fscanf(fp,&quot;:%[^:]s&quot;,user);
fscanf(fp,&quot;:%s&quot;,password);
sprintf(conn_string,&quot;hostaddr=%s port=%s dbname=%s user=%s password=%s&quot;,hostaddr,port,dbname,user,password);
}

conn = PQconnectdb(conn_string);
if (PQstatus(conn) == CONNECTION_BAD)
        {
                 fprintf(stderr,&quot;Not able to connect to the database %s&quot;,PQerrorMessage(conn));
                 return NULL;
        }
if(ch==&#39;y&#39;)
{
res=PQexec(conn,&quot;BEGIN&quot;);
PQclear(res);
res=PQexec(conn,&quot;DECLARE find_taken CURSOR FOR select count(*) from public.pggame_control where taken=true&quot;);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
        {
                fprintf(stderr, &quot;Erorr %s&quot;, PQerrorMessage(conn));
                PQclear(res);
        }
PQclear(res);
res = PQexec(conn, &quot;FETCH ALL in find_taken&quot;);
cnt=atoi(PQgetvalue(res,0,0));
PQclear(res);
res=PQexec(conn,&quot;END&quot;);
PQclear(res);

if(cnt==0)
{
res=PQexec(conn,&quot;TRUNCATE public.pggame_control&quot;);
PQclear(res);
res=PQexec(conn,&quot;INSERT INTO public.pggame_control values(false,false)&quot;);
PQclear(res);
}
printf(&quot;Enter Your Name -&amp;gt; &quot;);
scanf(&quot;%s&quot;,name);
paramValues[0]=name;
printf(&quot;Enter Your Symbol -&amp;gt; &quot;);
scanf(&quot;%s&quot;,symbol);
paramValues[1]=symbol;
res=PQexec(conn,&quot;TRUNCATE public.pggame_status&quot;);
PQclear(res);
res=PQexecParams(conn,&quot;INSERT INTO public.pggame_status(name,symbol,comments,status) values($1,$2,&#39;&#39;,false)&quot;,2,NULL,paramValues,NULL,NULL,1);
                if (PQresultStatus(res) != PGRES_COMMAND_OK)
                {
                fprintf(stderr, &quot;INSERT failed: %s&quot;, PQerrorMessage(conn));
                PQclear(res);
                }
                PQclear(res);
}
res=PQexec(conn,&quot;TRUNCATE public.pggame_spots&quot;);
PQclear(res);
res=PQexec(conn,&quot;TRUNCATE public.pggame_positions&quot;);
PQclear(res);
res=PQexec(conn,&quot;INSERT INTO public.pggame_positions values(0,0)&quot;);
PQclear(res);
fclose(fp);
return conn;
}

int main()
{
int y=1,x=1,i=1,one=0;
char ch,x1[10],y1[10],cnt,remote_spot_check[200];
PGconn     *your_conn,*other_conn;
PGresult   *res;
FILE *log;
const char *paramValues[2];
log=fopen(&quot;/tmp/pggame.log&quot;,&quot;w&quot;);
if(!((your_conn=PGconnect(&#39;y&#39;))&amp;amp;&amp;amp;(other_conn=PGconnect(&#39;o&#39;))))
return 1;
initscr();
keypad(stdscr,TRUE);
noecho();
x=1;
y=1;
while(x+10&amp;lt;140)
{
x=x+2;
mvprintw(0,x+9,&quot;-=&quot;);
mvprintw(36,x+9,&quot;-=&quot;);
y=1;
}
y=0;
while(y&amp;lt;35)
{
++y;
mvprintw(y,12,&quot;.&quot;);
mvprintw(y,141,&quot;.&quot;);
}
y=2;
x=15;
refresh();
while(1)
{
res=PQexec(other_conn,&quot;BEGIN&quot;);
PQclear(res);
res=PQexec(other_conn,&quot;DECLARE find_spots CURSOR FOR select count(*) from public.pggame_spots&quot;);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
        {
                fprintf(stderr, &quot;Erorr %s&quot;, PQerrorMessage(your_conn));
                PQclear(res);
        }
PQclear(res);
res = PQexec(other_conn, &quot;FETCH ALL in find_spots&quot;);
cnt=atoi(PQgetvalue(res,0,0));
PQclear(res);
res=PQexec(other_conn,&quot;END&quot;);
PQclear(res);
if(cnt&amp;gt;=1)
{
res=PQexec(other_conn,&quot;BEGIN&quot;);
PQclear(res);
res=PQexec(other_conn,&quot;DECLARE get_remote_pos CURSOR FOR select * from public.pggame_spots where ctid=(select max(ctid) from public.pggame_spots)&quot;);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
        {
                fprintf(stderr, &quot;Erorr %s&quot;, PQerrorMessage(your_conn));
                PQclear(res);
        }
PQclear(res);
res = PQexec(other_conn, &quot;FETCH ALL in get_remote_pos&quot;);
y=atoi(PQgetvalue(res,0,0));
x=atoi(PQgetvalue(res,0,1));
PQclear(res);
res=PQexec(other_conn,&quot;END&quot;);
PQclear(res);
res=PQexec(other_conn,&quot;BEGIN&quot;);
PQclear(res);
res=PQexec(other_conn,&quot;DECLARE get_symbol CURSOR FOR select symbol from public.pggame_status&quot;);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
        {
                fprintf(stderr, &quot;Erorr %s&quot;, PQerrorMessage(your_conn));
                PQclear(res);
        }
PQclear(res);
res = PQexec(other_conn, &quot;FETCH ALL in get_symbol&quot;);
mvprintw(y+1,x+15,&quot;%s&quot;,PQgetvalue(res,0,0));
PQclear(res);
res=PQexec(other_conn,&quot;END&quot;);
PQclear(res);
}
res=PQexec(other_conn,&quot;BEGIN&quot;);
PQclear(res);
res=PQexec(other_conn,&quot;DECLARE find_win CURSOR FOR select count(*) from public.pggame_status where status=true&quot;);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
        {
                fprintf(stderr, &quot;Erorr %s&quot;, PQerrorMessage(other_conn));
                PQclear(res);
        }
PQclear(res);
res = PQexec(other_conn, &quot;FETCH ALL in find_win&quot;);
cnt=atoi(PQgetvalue(res,0,0));
PQclear(res);
res=PQexec(other_conn,&quot;END&quot;);
if(cnt&amp;gt;=1)
{
res=PQexec(other_conn,&quot;BEGIN&quot;);
PQclear(res);
res=PQexec(other_conn,&quot;DECLARE find_win CURSOR FOR select name from public.pggame_status where status=true&quot;);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
        {
                fprintf(stderr, &quot;Erorr %s&quot;, PQerrorMessage(other_conn));
                PQclear(res);
        }
PQclear(res);
res = PQexec(other_conn, &quot;FETCH ALL in find_win&quot;);
mvprintw(15,40,&quot;***** %s WIN The Game ***** .... Press Any Key To Exit ... &quot;,PQgetvalue(res,0,0));
refresh();
PQclear(res);
res=PQexec(other_conn,&quot;END&quot;);
getch();
getch();
endwin();
PQfinish(your_conn);
PQfinish(other_conn);
return 0;
}

res=PQexec(other_conn,&quot;BEGIN&quot;);
PQclear(res);
res=PQexec(other_conn,&quot;DECLARE find_table CURSOR FOR select count(*) from public.pggame_positions&quot;);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
        {
                fprintf(stderr, &quot;Erorr %s&quot;, PQerrorMessage(your_conn));
                PQclear(res);
        }
PQclear(res);
res = PQexec(other_conn, &quot;FETCH ALL in find_table&quot;);
cnt=atoi(PQgetvalue(res,0,0));
PQclear(res);
res=PQexec(other_conn,&quot;END&quot;);
PQclear(res);
if(cnt==1)
{
res=PQexec(other_conn,&quot;BEGIN&quot;);
PQclear(res);
res=PQexec(other_conn,&quot;DECLARE find_table CURSOR FOR select * from public.pggame_positions&quot;);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
        {
                fprintf(stderr, &quot;Erorr %s&quot;, PQerrorMessage(your_conn));
                PQclear(res);
        }
PQclear(res);
res = PQexec(other_conn, &quot;FETCH ALL in find_table&quot;);
y=atoi(PQgetvalue(res,0,0));
x=atoi(PQgetvalue(res,0,1));
PQclear(res);
res=PQexec(other_conn,&quot;END&quot;);
PQclear(res);
mvprintw(37,125,&quot;CONTROL ==&amp;gt;&amp;gt; &quot;);
mvprintw(y,x,&quot;&quot;);
}
else
{
mvprintw(37,125,&quot;CONTROL ==&amp;gt;&amp;gt; &quot;);
mvprintw(1,1,&quot;&quot;);
}

refresh();
usleep(10000);
one=0;
continue;
}
mvprintw(37,125,&quot;CONTROL &amp;lt;&amp;lt;== &quot;);
mvprintw(y,x,&quot;&quot;);
refresh();
if(cnt==0)
{
res=PQexec(other_conn,&quot;UPDATE public.pggame_control SET taken=true&quot;);
   if (PQresultStatus(res) != PGRES_COMMAND_OK)
                {
                fprintf(stderr, &quot;Update failed: %s&quot;, PQerrorMessage(other_conn));
                PQclear(res);
                }
                PQclear(res);
if(one==0)
{
one=one+1;
res=PQexec(other_conn,&quot;BEGIN&quot;);
PQclear(res);
res=PQexec(other_conn,&quot;DECLARE find_spots CURSOR FOR select count(*) from public.pggame_spots&quot;);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
        {
                fprintf(stderr, &quot;Erorr %s&quot;, PQerrorMessage(your_conn));
                PQclear(res);
        }
PQclear(res);
res = PQexec(other_conn, &quot;FETCH ALL in find_spots&quot;);
cnt=atoi(PQgetvalue(res,0,0));
PQclear(res);
res=PQexec(other_conn,&quot;END&quot;);
PQclear(res);

if(cnt&amp;gt;=1)
{
res=PQexec(other_conn,&quot;BEGIN&quot;);
PQclear(res);
res=PQexec(other_conn,&quot;DECLARE get_remote_pos CURSOR FOR select * from public.pggame_spots where ctid=(select max(ctid) from public.pggame_spots)&quot;);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
        {
                fprintf(stderr, &quot;Erorr %s&quot;, PQerrorMessage(your_conn));
                PQclear(res);
        }
PQclear(res);
res = PQexec(other_conn, &quot;FETCH ALL in get_remote_pos&quot;);
y=atoi(PQgetvalue(res,0,0));
x=atoi(PQgetvalue(res,0,1));
PQclear(res);
res=PQexec(other_conn,&quot;END&quot;);
PQclear(res);
res=PQexec(other_conn,&quot;BEGIN&quot;);
PQclear(res);
res=PQexec(other_conn,&quot;DECLARE get_symbol CURSOR FOR select symbol from public.pggame_status&quot;);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
        {
                fprintf(stderr, &quot;Erorr %s&quot;, PQerrorMessage(your_conn));
                PQclear(res);
        }
PQclear(res);
res = PQexec(other_conn, &quot;FETCH ALL in get_symbol&quot;);
mvprintw(y+1,x+15,&quot;%s&quot;,PQgetvalue(res,0,0));
PQclear(res);
res=PQexec(other_conn,&quot;END&quot;);
PQclear(res);
res=PQexec(other_conn,&quot;BEGIN&quot;);
PQclear(res);
res=PQexec(other_conn,&quot;DECLARE find_table CURSOR FOR select * from public.pggame_positions&quot;);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
        {
                fprintf(stderr, &quot;Erorr %s&quot;, PQerrorMessage(your_conn));
                PQclear(res);
        }
PQclear(res);
res = PQexec(other_conn, &quot;FETCH ALL in find_table&quot;);
y=atoi(PQgetvalue(res,0,0));
x=atoi(PQgetvalue(res,0,1));
PQclear(res);
res=PQexec(other_conn,&quot;END&quot;);
PQclear(res);
mvprintw(y,x,&quot;&quot;);
refresh();
}
}




res=PQexec(your_conn,&quot;BEGIN&quot;);
PQclear(res);
res=PQexec(your_conn,&quot;DECLARE find_spotted CURSOR FOR select count(*) from public.pggame_control where spot=true&quot;);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
        {
                fprintf(stderr, &quot;Erorr %s&quot;, PQerrorMessage(your_conn));
                PQclear(res);
        }
PQclear(res);
res = PQexec(your_conn, &quot;FETCH ALL in find_spotted&quot;);
cnt=atoi(PQgetvalue(res,0,0));
PQclear(res);
res=PQexec(your_conn,&quot;END&quot;);
PQclear(res);
if(cnt&amp;gt;=1)
{
res=PQexec(your_conn,&quot;UPDATE public.pggame_control SET taken=true where taken=false&quot;);
  if (PQresultStatus(res) != PGRES_COMMAND_OK)
                {
                fprintf(stderr, &quot;Update failed: %s&quot;, PQerrorMessage(your_conn));
                PQclear(res);
                }
                PQclear(res);
res=PQexec(other_conn,&quot;UPDATE public.pggame_control SET taken=false where taken=true&quot;);
  if (PQresultStatus(res) != PGRES_COMMAND_OK)
                {
                fprintf(stderr, &quot;Update failed: %s&quot;, PQerrorMessage(other_conn));
                PQclear(res);
                }
                PQclear(res);
res=PQexec(your_conn,&quot;UPDATE public.pggame_control set spot=false where spot=true&quot;);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
                {
                fprintf(stderr, &quot;Update failed: %s&quot;, PQerrorMessage(your_conn));
                PQclear(res);
                }
                PQclear(res);
}
}

ch=getch();
if(ch==&#39;q&#39;||ch==&#39;Q&#39;)
break;
switch(ch)
{
case &#39;a&#39;:case &#39;A&#39;:
if(x==15)
x=137;
else
x=x-2;
mvprintw(y,x,&quot;&quot;);
break;
case &#39;s&#39;:case &#39;S&#39;:
if(y==34)
y=1;
else
y=y+1;
mvprintw(y,x,&quot;&quot;);
break;
case &#39;w&#39;:case &#39;W&#39;:
if(y==1)
y=34;
else
y=y-1;
mvprintw(y,x,&quot;&quot;);
break;
case &#39;d&#39;:case &#39;D&#39;:
if(x==137)
x=15;
else
x=x+2;
mvprintw(y,x,&quot;&quot;);
break;
case &#39;j&#39;:case &#39;J&#39;:

res=PQexec(other_conn,&quot;BEGIN&quot;);
PQclear(res);
sprintf(remote_spot_check,&quot;DECLARE find_same_spot CURSOR FOR select count(*) from public.pggame_spots where y=%d and x=%d&quot;,y-1,x-15);
res=PQexec(other_conn,remote_spot_check);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
        {
                fprintf(stderr, &quot;Erorr %s&quot;, PQerrorMessage(other_conn));
                PQclear(res);
        }
PQclear(res);
res = PQexec(other_conn, &quot;FETCH ALL in find_same_spot&quot;);
cnt=atoi(PQgetvalue(res,0,0));
PQclear(res);
res=PQexec(other_conn,&quot;END&quot;);
if(cnt==0)
{
echo();
mvprintw(y,x,&quot;%s&quot;,symbol);
sprintf(y1,&quot;%d&quot;,y-1);
sprintf(x1,&quot;%d&quot;,x-15);
paramValues[0]=y1;
paramValues[1]=x1;
res=PQexecParams(your_conn,&quot;INSERT INTO public.pggame_spots(y,x) values($1,$2)&quot;,2,NULL,paramValues,NULL,NULL,1);
                if (PQresultStatus(res) != PGRES_COMMAND_OK)
                {
                fprintf(log, &quot;INSERT failed: %s&quot;, PQerrorMessage(your_conn));
                PQclear(res);
                }
                PQclear(res);
noecho();
refresh();
}
}

sprintf(y1,&quot;%d&quot;,y);
sprintf(x1,&quot;%d&quot;,x);
paramValues[0]=y1;
paramValues[1]=x1;
res=PQexecParams(your_conn,&quot;INSERT INTO public.pggame_positions(y,x) values($1,$2)&quot;,2,NULL,paramValues,NULL,NULL,1);
   if (PQresultStatus(res) != PGRES_COMMAND_OK)
                {
                fprintf(log, &quot;INSERT failed: %s&quot;, PQerrorMessage(your_conn));
                PQclear(res);
                }
                PQclear(res);

res=PQexec(your_conn,&quot;BEGIN&quot;);
PQclear(res);
res=PQexec(your_conn,&quot;DECLARE find_win CURSOR FOR select count(*) from public.pggame_status where status=true&quot;);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
        {
                fprintf(stderr, &quot;Erorr %s&quot;, PQerrorMessage(your_conn));
                PQclear(res);
        }
PQclear(res);
res = PQexec(your_conn, &quot;FETCH ALL in find_win&quot;);
cnt=atoi(PQgetvalue(res,0,0));
PQclear(res);
res=PQexec(your_conn,&quot;END&quot;);
if(cnt&amp;gt;=1)
{
mvprintw(15,40,&quot;***** CONGRATULATIONS  !! ***** You WIN The Game .... Press Any Key To Exit ...&quot;);
refresh();
getch();
getch();
PQfinish(your_conn);
PQfinish(other_conn);
endwin();
return 0;
}
}
getch();
PQfinish(your_conn);
PQfinish(other_conn);
endwin();
return 0;
}
&lt;!--140--&gt;&lt;/pre&gt;
&lt;pre class=&quot;prettyprint lang-c&quot;&gt;&lt;/pre&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;SQL for Postgres&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;-=-=-=-=-=-=-=-=&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-SQL&quot;&gt;DROP TABLE public.pggame_positions CASCADE;
DROP TABLE public.pggame_spots CASCADE;
DROP TABLE public.pggame_status CASCADE;
DROP TABLE public.pggame_control CASCADE;
DROP VIEW coord_sum;
CREATE TABLE public.pggame_spots(y int,x int);
CREATE TABLE public.pggame_positions(y int,x int);
create view coord_sum as select e1.y+e1.x as cosum from pggame_spots e,pggame_spots e1 where (e.y,e.x) in (select yy,xx from (select e.y as yy,e1.y as y1,e.y-e1.y diffy,e.x as xx,e1.x as x1,e.x-e1.x diffx from pggame_spots e,pggame_spots e1 where e.y-e1.y between -4 and 4 and e.x-e1.x between -8 and 8) as foo group by yy,xx having array_agg(diffy)@&amp;gt;ARRAY[0,1,2,3,4] and (array_agg(diffx)@&amp;gt;ARRAY[0,-2,-4,-6,-8] or array_agg(diffx)@&amp;gt;ARRAY[0,2,4,6,8]));
CREATE OR REPLACE FUNCTION PUBLIC.PGGAME_INSERT_TO_UPDATE() RETURNS TRIGGER AS $$ DECLARE  CNT INT; BEGIN SELECT COUNT(*) INTO CNT FROM pggame_positions; IF(CNT=0) THEN RETURN NEW; ELSE UPDATE pggame_positions SET y=new.y,x=new.x; END IF; RETURN NULL; END; $$ LANGUAGE PLPGSQL;
CREATE TRIGGER PGGAME_INSERT_TO_UPDATE_TRIGG BEFORE INSERT ON public.pggame_positions FOR EACH ROW EXECUTE PROCEDURE public.PGGAME_INSERT_TO_UPDATE();
CREATE TABLE PUBLIC.PGGAME_CONTROL(TAKEN BOOLEAN,SPOT BOOLEAN);
INSERT INTO PUBLIC.PGGAME_CONTROL VALUES(FALSE,FALSE);
create table public.pggame_status(name varchar,symbol char(1),comments varchar,status boolean);
CREATE OR REPLACE FUNCTION PUBLIC.PGGAME_SPOTS_DUP_PREVENT() RETURNS TRIGGER AS $$ DECLARE CNT INT;BEGIN SELECT COUNT(*) INTO CNT FROM public.pggame_spots where y=new.y and x=new.x; 
IF(CNT&amp;gt;=1) THEN RETURN NULL;
ELSE 
UPDATE PUBLIC.PGGAME_CONTROL SET SPOT=TRUE WHERE TAKEN=FALSE;
RETURN NEW;
END IF;
END;
$$ 
LANGUAGE PLPGSQL;
CREATE TRIGGER PGGAME_SPOTS_DUP_PREVENT_TRIGG BEFORE INSERT ON public.pggame_spots FOR EACH ROW EXECUTE PROCEDURE public.PGGAME_SPOTS_DUP_PREVENT();
CREATE OR REPLACE FUNCTION PUBLIC.PGGAME_STATUS_CHECK() RETURNS TRIGGER AS $$ 
DECLARE 
CNT INT;
BEGIN 
select count(x) into cnt from  pggame_spots e where y=new.y and 5=(select count(*) from pggame_spots e1,(select generate_series(0,8,2) as seq) as e2 where e.x=e1.x+e2.seq and e1.y=new.y);
IF(CNT&amp;gt;=1) THEN
UPDATE PUBLIC.PGGAME_STATUS SET COMMENTS=&#39;WIN THE GAME&#39;,STATUS=TRUE WHERE NAME IS NOT NULL;
ELSE
select count(Y) into cnt from  pggame_spots e where X=new.X and 5=(select count(*) from pggame_spots e1,(select generate_series(0,4,1) as seq) as e2 where e.y=e1.Y+e2.seq and e1.x=NEW.x);
IF(CNT&amp;gt;=1) THEN
UPDATE PUBLIC.PGGAME_STATUS SET COMMENTS=&#39;WIN THE GAME&#39;,STATUS=TRUE WHERE NAME IS NOT NULL;
ELSE
select count(*) into cnt from pggame_spots e where 5=(select count(*) from (select e.y+generate_series(0,4,1),e.x-generate_series(0,8,2) from pggame_spots e1
intersect
select * from pggame_spots )as sub);
IF(cnt&amp;gt;=1) THEN
UPDATE PUBLIC.PGGAME_STATUS SET COMMENTS=&#39;WIN THE GAME&#39;,STATUS=TRUE WHERE NAME IS NOT NULL;
else
select count(*) into cnt from pggame_spots e where 5=(select count(*) from (select e.y+generate_series(0,4,1),e.x+generate_series(0,8,2) from pggame_spots e1
intersect
select * from pggame_spots )as sub);
IF(cnt&amp;gt;=1) THEN
UPDATE PUBLIC.PGGAME_STATUS SET COMMENTS=&#39;WIN THE GAME&#39;,STATUS=TRUE WHERE NAME IS NOT NULL;
end if;
END IF;
END IF;
END IF;
RETURN NULL;
END;
$$ 
LANGUAGE PLPGSQL;
CREATE TRIGGER PGGAME_STATUS_CHECK_TRIGG AFTER INSERT ON public.pggame_spots FOR EACH ROW EXECUTE PROCEDURE public.PGGAME_STATUS_CHECK();

&lt;/pre&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Steps to run the game&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;-=-=-=-=-=-=-=-=--=-=&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
Step 1:-

Execute above SQL in your instance and in your opponent instance.&lt;br /&gt;
&lt;br /&gt;
Step 2:-

Require second player’s details in your pg_hba.conf

Create a file “/tmp/.cred”&lt;br /&gt;
&lt;br /&gt;
192.168.1.2:5432:postgres:postgres:postgres =&amp;gt; Your details.
192.168.1.3:5433:postgres:postgres:postgres =&amp;gt; Your opponent details.&lt;br /&gt;
Syntax:- &lt;hostaddr&gt;:&lt;port&gt;:&lt;dbname&gt;:&lt;user&gt;:&lt;password&gt;

Caution: - Don’t provide any dbname/user/password which is having “:” symbol.&amp;nbsp;&lt;/password&gt;&lt;/user&gt;&lt;/dbname&gt;&lt;/port&gt;&lt;/hostaddr&gt;&lt;br /&gt;
&lt;hostaddr&gt;&lt;port&gt;&lt;dbname&gt;&lt;user&gt;&lt;password&gt;&lt;br /&gt;&lt;/password&gt;&lt;/user&gt;&lt;/dbname&gt;&lt;/port&gt;&lt;/hostaddr&gt;
&lt;hostaddr&gt;&lt;port&gt;&lt;dbname&gt;&lt;user&gt;&lt;password&gt;Step 3:-

If you have the PGHOME=/opt/PostgreSQL/9.0 then game.c will work fine. If you don’t have, then please change the header file “/opt/PostgreSQL/9.0/include/libpq-fe.h” in game.c accordingly.&lt;/password&gt;&lt;/user&gt;&lt;/dbname&gt;&lt;/port&gt;&lt;/hostaddr&gt;&lt;br /&gt;
&lt;hostaddr&gt;&lt;port&gt;&lt;dbname&gt;&lt;user&gt;&lt;password&gt;&lt;br /&gt;&lt;/password&gt;&lt;/user&gt;&lt;/dbname&gt;&lt;/port&gt;&lt;/hostaddr&gt;
&lt;hostaddr&gt;&lt;port&gt;&lt;dbname&gt;&lt;user&gt;&lt;password&gt;Step 4:-

&lt;/password&gt;&lt;/user&gt;&lt;/dbname&gt;&lt;/port&gt;&lt;/hostaddr&gt;&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-bash&quot;&gt;export LD_LIBRARY_PATH according to your 9.0 instance.
Ex:-
export LD_LIBRARY_PATH=/opt/PostgreSQL/9.0/lib
&lt;/pre&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
Step 5:-

Complie game.c

Ex:-

&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-bash&quot;&gt;gcc –o game game.c –L/opt/PostgreSQL/9.0/lib –lpq –lncurses
&lt;/pre&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
Step 6:-

Run the game
Ex:-
./game
Enter Your Name -&amp;gt; Dinesh
Enter Your Symbol -&amp;gt; D [Any character]&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Instructions&lt;br /&gt;
-=-=-=-=-=-=&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
1. Use a,s,d,w for movements and j for spot the symbol.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
a =&amp;gt; Left&lt;/div&gt;
&lt;div&gt;
s =&amp;gt; Down&lt;/div&gt;
&lt;div&gt;
d =&amp;gt; Right&lt;/div&gt;
&lt;div&gt;
w =&amp;gt; Up&lt;/div&gt;
&lt;div&gt;
j =&amp;gt; For spot the symbol, and then one of the movement key.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Game Rules&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;-=-=-=-=-=&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
If you can frame the linear series of the length 5 then you are the winner. We can frame the series as horizontal/vertical/diagonal.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;Ex:-
Symbol is “*”&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
* * * * * =&amp;gt;  Winner&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
*&lt;/div&gt;
&lt;div&gt;
*&lt;/div&gt;
&lt;div&gt;
*&lt;/div&gt;
&lt;div&gt;
*&lt;/div&gt;
&lt;div&gt;
* =&amp;gt; Winner&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
*&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;*&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;*&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;*&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; * =&amp;gt;  Winner&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;*&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;*&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;*&lt;/div&gt;
&lt;div&gt;
* =&amp;gt; Winner&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Winner needs to start the new game.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Sample screen shots&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;-=-=-=-=-=-=-=-=-=-=&lt;/b&gt;&lt;/span&gt;&lt;/div&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/AVvXsEgL6uOo20ax2mAXEDWOTVvxUlIntijkWu6b24IN9WviSh9iwCLA0JuA-OLWm4qD8ElfJ4_-1Pz_iIMdH5jDYlHMJImp_n5QJTgCQlzqDguV7_UaEoYkDOXPcEhJvQciw6nDvBYDOFpVOcY/s1600/Screen+Shot+2013-12-26+at+4.06.30+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgL6uOo20ax2mAXEDWOTVvxUlIntijkWu6b24IN9WviSh9iwCLA0JuA-OLWm4qD8ElfJ4_-1Pz_iIMdH5jDYlHMJImp_n5QJTgCQlzqDguV7_UaEoYkDOXPcEhJvQciw6nDvBYDOFpVOcY/s320/Screen+Shot+2013-12-26+at+4.06.30+PM.png&quot; height=&quot;168&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&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/AVvXsEhbDAi3eS8kRWGW3NZ5Hp78FMCY741FI3wf3lHYDoY5VTDlV24LO_J7eFaslLlxf9a0Qzj-gz7H5u9uLTI_FxDcmbmB0HCj3IiJFUl26wO5FXnqbqiVjYqxUXudRvbVoNgwz_hyrvOhkvA/s1600/Screen+Shot+2013-12-26+at+4.06.47+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbDAi3eS8kRWGW3NZ5Hp78FMCY741FI3wf3lHYDoY5VTDlV24LO_J7eFaslLlxf9a0Qzj-gz7H5u9uLTI_FxDcmbmB0HCj3IiJFUl26wO5FXnqbqiVjYqxUXudRvbVoNgwz_hyrvOhkvA/s320/Screen+Shot+2013-12-26+at+4.06.47+PM.png&quot; height=&quot;167&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Dinesh Kumar&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/4756285845171484676/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2013/12/game-with-postgresql.html#comment-form' title='15 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/4756285845171484676'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/4756285845171484676'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2013/12/game-with-postgresql.html' title='Game with postgreSQL'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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/AVvXsEgL6uOo20ax2mAXEDWOTVvxUlIntijkWu6b24IN9WviSh9iwCLA0JuA-OLWm4qD8ElfJ4_-1Pz_iIMdH5jDYlHMJImp_n5QJTgCQlzqDguV7_UaEoYkDOXPcEhJvQciw6nDvBYDOFpVOcY/s72-c/Screen+Shot+2013-12-26+at+4.06.30+PM.png" height="72" width="72"/><thr:total>15</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2844187126830320432.post-5716842145577630293</id><published>2013-11-21T01:15:00.001+05:30</published><updated>2013-12-27T12:37:53.943+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Input from PostgreSQL"/><category scheme="http://www.blogger.com/atom/ns#" term="Interactive PostgreSQL"/><category scheme="http://www.blogger.com/atom/ns#" term="Interactive psql"/><category scheme="http://www.blogger.com/atom/ns#" term="Interactive SQL in PostgreSQL"/><category scheme="http://www.blogger.com/atom/ns#" term="PostgreSQL Interactive"/><title type='text'>Interactive PostgreSQL Script</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Do you want an input from end user, while running PostgreSQL script.&lt;br /&gt;
&lt;br /&gt;
No Problem, here is the one of the solution for you.&lt;br /&gt;
&lt;br /&gt;
In the following example, i am taking the confirmation from an end user, before dropping an existing database called &quot;sample&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;-- When any exception raised from this script, the complete script execution is going to fail.

-- We will be raising a custom exception, when the Drop DB != &#39;y|Y&#39;;
--
\set ON_ERROR_STOP on

-- Take input from the user.
--
\prompt &#39;Are you sure to drop &#39; Do_You_Want_To_Drop_Db

-- Get the user input.
--
\set Do_Drop_Db &#39;\&#39;&#39; :Do_You_Want_To_Drop_Db &#39;\&#39;&#39;

-- Creating a temp table to store the value of the user confirmation.
-- This will be dropped when the session got closed.
--
CREATE TEMP TABLE Drop_Db AS SELECT :Do_Drop_Db::text AS confirm;

DO
$$
BEGIN
IF EXISTS(SELECT * FROM Drop_Db WHERE confirm NOT IN(&#39;y&#39;, &#39;Y&#39;)) THEN
RAISE EXCEPTION &#39;Database won&#39;&#39;t drop. Hence closing this session&#39;;
ELSE
RAISE NOTICE &#39;Database will be droped. Please make sure the connection of this databases get closed.&#39;;
END IF;
END
$$;

DROP DATABASE sample;



&lt;/pre&gt;
Testing the Script

&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;bash-4.1$ ../bin/psql -U postgres -f /tmp/Interactive_Sql.Sql postgres
Are you sure to drop N
SELECT 1
psql:/tmp/Interactive_Sql.Sql:28: ERROR: &amp;nbsp;Database won&#39;t drop. Hence closing this session
&lt;/pre&gt;
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;bash-4.1$ ../bin/psql -U postgres -f /tmp/Interactive_Sql.Sql postgres
Are you sure to drop Y
SELECT 1
psql:/tmp/Interactive_Sql.Sql:28: NOTICE: &amp;nbsp;Database will be droped. Please make sure the connection of this databases get closed.
DO
DROP DATABASE
&lt;/pre&gt;
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;
&lt;/pre&gt;
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;దినేష్ కుమార్ &lt;/pre&gt;
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;Dinesh Kumar&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/5716842145577630293/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2013/11/interactive-postgresql-script.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/5716842145577630293'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/5716842145577630293'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2013/11/interactive-postgresql-script.html' title='Interactive PostgreSQL Script'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2844187126830320432.post-4687735164828862282</id><published>2013-02-13T17:41:00.004+05:30</published><updated>2013-11-18T15:45:03.874+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="ecpg"/><category scheme="http://www.blogger.com/atom/ns#" term="ecpg example in postgres"/><category scheme="http://www.blogger.com/atom/ns#" term="ecpg in postgresql"/><category scheme="http://www.blogger.com/atom/ns#" term="sample ecpg example"/><title type='text'>Sample ECPG Script</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
Hi&lt;br /&gt;
&lt;br /&gt;
Below is the sample ECPG test case what i have prepared.&lt;br /&gt;
&lt;br /&gt;
Sample ECPG Scripts&lt;br /&gt;
================&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-c&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;-bash-4.1$ more foo2.h&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;typedef struct&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;foo123 a[8];&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;} bar;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;-bash-4.1$ more foo1.h&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;typedef struct&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;int x;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;}foo123;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;-bash-4.1$ more foo.pgc&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;EXEC SQL INCLUDE &quot;foo1.h&quot;;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;EXEC SQL INCLUDE &quot;foo2.h&quot;;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;int main()&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; EXEC SQL BEGIN DECLARE SECTION;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; char* dbname = &quot;edb&quot;;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; char* db &amp;nbsp; &amp;nbsp; = &quot;edb@localhost:5444&quot;;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; char* user &amp;nbsp; = &quot;enterprisedb&quot;;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; char* passwd = &quot;adminedb&quot;;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; EXEC SQL END DECLARE SECTION;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; bar records;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; EXEC SQL WHENEVER SQLERROR &amp;nbsp; &amp;nbsp; &amp;nbsp;GOTO sql_error;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; EXEC SQL CONNECT :user IDENTIFIED BY :passwd AT :dbname USING :db;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; EXEC SQL AT :dbname DECLARE cur_TBL CURSOR FOR&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SELECT COUNT(*) AS rec_count&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FROM EMP&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; EXEC SQL AT :dbname &amp;nbsp; &amp;nbsp;OPEN &amp;nbsp;cur_TBL;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; EXEC SQL AT :dbname &amp;nbsp; &amp;nbsp;FETCH cur_TBL INTO :records.a[0].x;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; EXEC SQL AT :dbname &amp;nbsp; &amp;nbsp;CLOSE cur_TBL;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; EXEC SQL DISCONNECT CURRENT;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; printf(&quot;OK\n&quot;);&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; printf(&quot;RECORD COUNT = %d\n&quot;,records.a[0].x);&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; return 0;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;sql_error:&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp;printf(&quot;ERROR\n&quot;);&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp;return 1;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;Make File&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;=========&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;-bash-4.1$&amp;nbsp;more Makefile&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;all:&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; ecpg -C PROC foo.pgc&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; cc -o &amp;nbsp;foo foo.c -I /opt/PostgresPlus/9.1AS/include -L /opt/PostgresPlus/9.1AS/lib -lecpg&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;Execution&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;=========&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;-bash-4.1$ ./foo&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;OK&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;RECORD COUNT = 14&lt;/span&gt;&lt;/div&gt;
&lt;/pre&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
దినేష్ కుమార్&lt;br /&gt;
Dinesh Kumar
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/4687735164828862282/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2013/02/sample-ecpg-script.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/4687735164828862282'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/4687735164828862282'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2013/02/sample-ecpg-script.html' title='Sample ECPG Script'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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-2844187126830320432.post-8990747926029910697</id><published>2012-11-11T13:25:00.000+05:30</published><updated>2013-11-18T14:25:18.822+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="How to send email from libcurl"/><category scheme="http://www.blogger.com/atom/ns#" term="How to send gmail from libcurl"/><category scheme="http://www.blogger.com/atom/ns#" term="SMTP Libcurl"/><title type='text'>SMTP Libcurl</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hi ,&lt;br /&gt;
&lt;br /&gt;
Libcurl is a utility tool which we can also send e-mails using SMTP library. Below is a sample program which helps you to do the same from Linux-C Language.&lt;br /&gt;
&lt;br /&gt;
Below is the program&lt;br /&gt;
================&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-c&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;#include &amp;lt;string.h&amp;gt;&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;#include &amp;lt;curl/curl.h&amp;gt;&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;int main(void)&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;{&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; CURL *curl;&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; CURLcode res;&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; FILE *FP;&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; struct curl_slist *recipients = NULL;&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; static const char *from = &quot;********@gmail.com&quot;;&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; static const char *to = &quot;********@gmail.com&quot;;&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; FP=fopen(&quot;/tmp/Email&quot;,&quot;r&quot;);&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; curl = curl_easy_init();&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; if(curl) {&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; curl_easy_setopt(curl, CURLOPT_URL, &quot;smtp://smtp.gmail.com:587&quot;);&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; curl_easy_setopt(curl, CURLOPT_USERNAME, &quot;From_Email_User@gmail.com&quot;);&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; curl_easy_setopt(curl, CURLOPT_PASSWORD, &quot;*********&quot;);&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from);&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; recipients = curl_slist_append(recipients, to);&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; curl_easy_setopt(curl, CURLOPT_READDATA, FP);&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; res = curl_easy_perform(curl);&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; if(res != CURLE_OK)&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; fprintf(stderr, &quot;curl_easy_perform() failed: %s\n&quot;,curl_easy_strerror(res));&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; curl_slist_free_all(recipients);&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; curl_easy_cleanup(curl);&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; }&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; return 0;&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;

&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;/pre&gt;
File &quot;/tmp/Email&quot;&lt;br /&gt;
&lt;div&gt;
===============&lt;/div&gt;
&lt;pre class=&quot;prettyprint lang-sh&quot;&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[root@localhost ~]# more /tmp/Email&amp;nbsp;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Date: Mon, 29 Nov 2010 21:54:29 +1100,&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;To: ***************@gmail,&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;From: **********@gmail.com,&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Subject: Sample message,&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Content-Type: text/html; charset=&quot;us-ascii&quot;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Hi ,&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;How do you do.&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;lt;b&amp;gt; Any html code &amp;nbsp;&amp;lt;/b&amp;gt;&lt;/span&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;div&gt;
How to Run&lt;/div&gt;
&lt;div&gt;
===========&lt;/div&gt;
&lt;pre class=&quot;prettyprint lang-sh&quot;&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[root@localhost ~]# gcc -o test test.c -lcurl;./test&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;* Connection #0 to host smtp.gmail.com left intact&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;gt; QUIT&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;lt; 221 2.0.0 closing connection j9sm2235533pav.15&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;* Closing connection #0&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[root@localhost ~]#&amp;nbsp;&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
దినేష్ కుమార్&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
Dinesh Kumar&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/8990747926029910697/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2012/11/smtp-libcurl.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/8990747926029910697'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/8990747926029910697'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2012/11/smtp-libcurl.html' title='SMTP Libcurl'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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-2844187126830320432.post-8118567370233489439</id><published>2012-11-06T20:25:00.003+05:30</published><updated>2013-11-18T14:31:37.955+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Londiste"/><category scheme="http://www.blogger.com/atom/ns#" term="Londiste replication in postgresql"/><category scheme="http://www.blogger.com/atom/ns#" term="PGQ"/><category scheme="http://www.blogger.com/atom/ns#" term="PGQ in postgresql"/><category scheme="http://www.blogger.com/atom/ns#" term="Skytools"/><category scheme="http://www.blogger.com/atom/ns#" term="Skytools in PostgreSQL"/><title type='text'>Skytools - Londiste Replication</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
PGQ-Londiste Replication&lt;br /&gt;
===================&lt;br /&gt;
We all know that the Skytools are popular PostgreSQL Replication tools which have been developed in C/Python and PL/PGSQL. Londiste is the replication which has been implemented on top of PGQ tool which is a snapshot based queuing mechanism. Londiste replication is a Consumer of PGQ which takes the all modifications from PGQ.&lt;br /&gt;
&lt;br /&gt;
How to setup PGQ and Londiste Replication&lt;br /&gt;
---------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
PGQ&lt;br /&gt;
------&lt;br /&gt;
PGQ is a queue mechanism which gathers all the transactions/modifications from the provider and keep them ready to consumers{Londiste Replication Demon}.&lt;br /&gt;
&lt;br /&gt;
Step 1&lt;br /&gt;
----------&lt;br /&gt;
Download the Skytool from the below link.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-sh&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;http://pgfoundry.org/frs/download.php/3232/skytools-2.1.13.tar.gz&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;tar -zxvf skytools-2.1.13.tar.gz&lt;/span&gt;

&lt;/pre&gt;
&lt;br /&gt;
Step 2&lt;br /&gt;
---------&lt;br /&gt;
Configure make and make install.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-sh&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[root@localhost skytools-2.1.13]# ./configure &amp;nbsp;--prefix=/opt/PostgreSQL/9.2/Sky --with-pgconfig=/opt/PostgreSQL/9.2/bin/pg_config&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[root@localhost skytools-2.1.13]# make&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[root@localhost skytools-2.1.13]# make install&lt;/span&gt;



&lt;/pre&gt;
Step 3&lt;br /&gt;
------&lt;br /&gt;
PYTHONPATH&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-sh&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;export PYTHONPATH=/opt/PostgreSQL/9.2/Sky/lib64/python2.6/site-packages/&lt;/span&gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
OR&lt;br /&gt;
&lt;br /&gt;
Copy all the contents of &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&quot;/opt/PostgreSQL/9.2/Sky/lib64/python2.6/site-packages/&quot;&lt;/span&gt; to &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&quot;/usr/lib64/python2.6/site-packages/&quot;&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
Step 4&lt;br /&gt;
------&lt;br /&gt;
Create ticker.ini file which is responsible to create the ticks{Batches}.&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-sh&quot;&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;-bash-4.1$ more Sky/etc/ticker.ini&amp;nbsp;&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[pgqadm]&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;job_name = myticker_name&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;db = dbname = &amp;nbsp;producer port = 5432 host = localhost&amp;nbsp;&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;maint_delay = 1&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;loop_delay = 0.1&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;logfile = /tmp/%(job_name)s.log&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;pidfile = /tmp/%(job_name)s.pid&lt;/span&gt;

&lt;/pre&gt;
&lt;br /&gt;
Step 5&lt;br /&gt;
------&lt;br /&gt;
Starting PGQ ticker Demon.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-sh&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;-bash-4.1$ pwd&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;/opt/PostgreSQL/9.2/Sky/bin&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;-bash-4.1$ ./pgqadm.py ../etc/ticker.ini install&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;2012-11-06 18:39:45,973 9599 INFO plpgsql is installed&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;2012-11-06 18:39:45,974 9599 INFO txid_current_snapshot is installed&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;2012-11-06 18:39:45,975 9599 INFO Installing pgq&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;2012-11-06 18:39:46,010 9599 INFO &amp;nbsp; Reading from /opt/PostgreSQL/9.2/Sky/share/skytools/pgq.sql&lt;/span&gt;

&lt;/pre&gt;
&lt;br /&gt;
The above step creates all it&#39;s required PGQ catalog in the database producer.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;-bash-4.1$ ./pgqadm.py ../etc/ticker.ini ticker -d&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Step 6&lt;br /&gt;
------&lt;br /&gt;
Create Provider_Subscriber details in a file as below.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-sh&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;-bash-4.1$ more Sky/etc/Producer_Consumer.ini&amp;nbsp;&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[londiste]&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;job_name = Londiste_Job&amp;nbsp;&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;provider_db = dbname=producer port=5432 host=127.0.0.1&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;subscriber_db = dbname=consumer port=5432 host=127.0.0.1&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;pgq_queue_name = testing&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;logfile = /tmp/%(job_name)s.log&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;pidfile = /tmp/%(job_name)s.pid&lt;/span&gt;

&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
Step 7&lt;br /&gt;
------&lt;br /&gt;
Install the Londiste catalogs into Provider database.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-sh&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;-bash-4.1$ ./londiste.py ../etc/Producer_Consumer.ini provider install&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;2012-11-06 18:41:40,761 9726 INFO plpgsql is installed&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;2012-11-06 18:41:40,772 9726 INFO txid_current_snapshot is installed&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;2012-11-06 18:41:40,772 9726 INFO pgq is installed&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;2012-11-06 18:41:40,773 9726 INFO Installing londiste&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;2012-11-06 18:41:40,773 9726 INFO &amp;nbsp; Reading from /opt/PostgreSQL/9.2/Sky/share/skytools/londiste.sql&lt;/span&gt;

&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
Install the Londiste catalogs into Subscriber database.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-sh&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;-bash-4.1$ ./londiste.py ../etc/Producer_Consumer.ini subscriber install&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;2012-11-06 18:41:53,003 9742 INFO plpgsql is installed&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;2012-11-06 18:41:53,003 9742 INFO Installing londiste&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;2012-11-06 18:41:53,004 9742 INFO &amp;nbsp; Reading from /opt/PostgreSQL/9.2/Sky/share/skytools/londiste.sql&lt;/span&gt;

&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
Step 8&lt;br /&gt;
------&lt;br /&gt;
Start the Londiste Replication Demon.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-sh&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;-bash-4.1$ ./londiste.py ../etc/Producer_Consumer.ini replay -d&lt;/span&gt;

&lt;/pre&gt;
&lt;br /&gt;
Step 9&lt;br /&gt;
------&lt;br /&gt;
Create a sample PRIMARY KEY table in Provider and Receiver&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;CREATE TABLE TEST(T INT PRIMARY KEY);&lt;/span&gt;



&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;producer=# \dt&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; List of relations&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;Schema | Name | Type &amp;nbsp;| &amp;nbsp;Owner &amp;nbsp;&amp;nbsp;&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;--------+------+-------+----------&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;public | test | table | postgres&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;(1 row)&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;producer=# insert into test values(generate_series(1,1000));&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;INSERT 0 1000&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;consumer=# \dt&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; List of relations&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;Schema | Name | Type &amp;nbsp;| &amp;nbsp;Owner &amp;nbsp;&amp;nbsp;&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;--------+------+-------+----------&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;public | test | table | postgres&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;(1 row)&lt;/span&gt;

&lt;/pre&gt;
&lt;br /&gt;
Step 10&lt;br /&gt;
----------&lt;br /&gt;
Add this table to Londiste Replication.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-sh&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;-bash-4.1$ ./londiste.py ../etc/Producer_Consumer.ini provider add public.test&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;2012-11-06 18:44:37,767 9914 INFO Adding public.test&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;-bash-4.1$ ./londiste.py ../etc/Producer_Consumer.ini subscriber add public.test&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;2012-11-06 18:44:44,554 9927 INFO Checking public.test&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;2012-11-06 18:44:44,561 9927 INFO Adding public.test&lt;/span&gt;

&lt;/pre&gt;
&lt;br /&gt;
Step 11&lt;br /&gt;
-----------&lt;br /&gt;
Check the replication sync..&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-sh&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;producer-# SELECT * FROM pgq.get_consumer_info();&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;queue_name | consumer_name | &amp;nbsp; &amp;nbsp; &amp;nbsp; lag &amp;nbsp; &amp;nbsp; &amp;nbsp; | &amp;nbsp; &amp;nbsp;last_seen &amp;nbsp; &amp;nbsp;&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;------------+---------------+-----------------+-----------------&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;testing &amp;nbsp; &amp;nbsp;| Londiste_Job &amp;nbsp;| 00:00:27.837503 | 00:00:27.128354&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;(1 rows)&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;producer=# insert into test values(generate_series(-100,-10));&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;INSERT 0 91&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;producer=# \c consumer&amp;nbsp;&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;You are now connected to database &quot;consumer&quot; as user &quot;postgres&quot;.&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;consumer=# select count(*) from test;&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;count&amp;nbsp;&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;-------&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; 1091&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;(1 row)&lt;/span&gt;

&lt;/pre&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
దినేష్ కుమార్&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Dinesh Kumar&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/8118567370233489439/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2012/11/skytools-londiste-replication.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/8118567370233489439'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/8118567370233489439'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2012/11/skytools-londiste-replication.html' title='Skytools - Londiste Replication'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2844187126830320432.post-4478102522262746981</id><published>2012-11-05T18:59:00.000+05:30</published><updated>2013-12-10T10:12:53.598+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="fdw in postgresql"/><category scheme="http://www.blogger.com/atom/ns#" term="foreign data wrapers"/><category scheme="http://www.blogger.com/atom/ns#" term="foreign servers"/><category scheme="http://www.blogger.com/atom/ns#" term="foreign tables"/><category scheme="http://www.blogger.com/atom/ns#" term="foreign tables in postgresql."/><title type='text'>FOREIGN TABLES</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
FOREIGN TABLES/DATA WRAPPERS&lt;br /&gt;
===============================&lt;br /&gt;
&lt;br /&gt;
Foreign data wrapper is a library which understand the heterogeneous database information. For example, PostgreSQL does not understand the MYSQL data structure/information since both engines have different mechanism. If we want to get any heterogeneous database information then we need to configure the respective fdw(Foreign Data Wrapper) into the PostgreSQL Library location.&lt;br /&gt;
&lt;br /&gt;
Please find the below link, which gives you all the available Foreign Data Wrappers.&lt;br /&gt;
http://wiki.postgresql.org/wiki/Foreign_data_wrappers&lt;br /&gt;
&lt;br /&gt;
Here we have chosen MYSQL table as a source to PostgreSQL. Below are the steps.&lt;br /&gt;
&lt;br /&gt;
1) Install mysql and mysql-devel using yum .&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;pre class=&quot;prettyprint lang-*&quot;&gt;yum install mysql*&lt;/pre&gt;&lt;/span&gt;
2) Install PostgreSQL 9.1 through EnterpriseDB graphical installer.

3) Get the MYSQL FDW from the below link.
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;pre class=&quot;prettyprint lang-*&quot;&gt;https://github.com/dpage/mysql_fdw/archive/master.tar.gz&lt;/pre&gt;&lt;/span&gt;

4) set the &quot;PATH&quot; as shown below.
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;pre class=&quot;prettyprint lang-*&quot;&gt;export PATH=&amp;lt;PostgreSQL 9.1 Bin&amp;gt;:&amp;lt;Mysql Bin&amp;gt;:$PATH;&lt;/pre&gt;&lt;/span&gt;

Ex:-
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;pre class=&quot;prettyprint lang-*&quot;&gt;[root@localhost mysql_fdw-master]# echo $PATH&amp;nbsp;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;/opt/PostgreSQL/9.1/bin/:/usr/bin/mysql:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin&lt;/pre&gt;&lt;/span&gt;

5) Make &amp;amp; Make Install
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;pre class=&quot;prettyprint lang-*&quot;&gt;[root@localhost mysql_fdw-master]# make USE_PGXS=1&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[root@localhost mysql_fdw-master]# make USE_PGXS=1 install&lt;/pre&gt;&lt;/span&gt;

6) Create an Extension &amp;amp; Server as below.
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;postgres=# create EXTENSION mysql_fdw ;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;CREATE EXTENSION&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;postgres=# CREATE SERVER mysql_svr&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;FOREIGN DATA WRAPPER mysql_fdw&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;OPTIONS (address &#39;127.0.0.1&#39;, port &#39;3306&#39;); --MySql Port Default 3306&lt;/span&gt;
&lt;/pre&gt;

7) Create USER Mapping from PUBLIC users to &quot;MySql Root&quot;.
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;CREATE USER MAPPING FOR PUBLIC&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;SERVER mysql_svr&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;OPTIONS (username &#39;root&#39;, password &#39;root&#39;);&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;CREATE USER MAPPING&lt;/span&gt;
&lt;/pre&gt;

8) Create Foreign Table as below.
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;postgres=# CREATE FOREIGN TABLE TEST(T INT) SERVER mysql_svr OPTIONS(TABLE &#39;DINESH.XYZ&#39;); --Dinesh is a database &amp;amp; XYZ is a table.&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;CREATE FOREIGN TABLE&lt;/span&gt;&lt;br /&gt;
&lt;/pre&gt;

9) From MYSQL
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;mysql&amp;gt; \u DINESH&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Database changed&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;mysql&amp;gt; SELECT * FROM XYZ;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;+------+&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;| T &amp;nbsp; &amp;nbsp;|&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;+------+&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;| &amp;nbsp; &amp;nbsp;1 |&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;| &amp;nbsp; &amp;nbsp;2 |&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;| &amp;nbsp; &amp;nbsp;3 |&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;+------+&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;3 rows in set (0.00 sec)&lt;/span&gt;
&lt;/pre&gt;

10) From PostgreSQL
&lt;pre class=&quot;prettyprint lang-*&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;postgres=# select * from test;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;t&amp;nbsp;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;---&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;1&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;2&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;3&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;(3 rows)&lt;/span&gt;

&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;postgres=# explain analyze select * from test;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;QUERY PLAN &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; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;----------------------------------------------------------------------------------------------------&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;Foreign Scan on test &amp;nbsp;(cost=10.00..13.00 rows=3 width=4) (actual time=0.211..0.212 rows=3 loops=1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;Local server startup cost: 10&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;MySQL query: SELECT * FROM DINESH.XYZ&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;Total runtime: 0.675 ms&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;(4 rows)&lt;/span&gt;&lt;br /&gt;
&lt;/pre&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;దినేష్ కుమార్&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Dinesh Kumar&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/4478102522262746981/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2012/11/foreign-tables.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/4478102522262746981'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/4478102522262746981'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2012/11/foreign-tables.html' title='FOREIGN TABLES'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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-2844187126830320432.post-5356142976780182067</id><published>2012-10-16T18:52:00.002+05:30</published><updated>2013-11-18T15:30:50.693+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="pg_Agent windows pg_dump job"/><category scheme="http://www.blogger.com/atom/ns#" term="pg_dump batch script"/><category scheme="http://www.blogger.com/atom/ns#" term="pg_dump in windows"/><category scheme="http://www.blogger.com/atom/ns#" term="postgresql pg_dump windows"/><category scheme="http://www.blogger.com/atom/ns#" term="windows pg_dump"/><title type='text'>Windows Pg_Dump Script</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hi ,&lt;br /&gt;
&lt;br /&gt;
I recently developed a pg_dump windows based script, which can help us to schedule the pg_dump through pg_Agent or through windows scheduler.&lt;br /&gt;
&lt;br /&gt;
This script also having the backup retention policy and in any case it retain the last two consistant backups. i.e, if the current backup is successful, then it will remove the 2nd last backup from the backup location .&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-batch linenums&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;@ECHO OFF&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;REM pgAgent Windows Pg_Dump Script&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;set BIN=&quot;C:\Program Files\PostgreSQL\9.1\bin&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;set BACKUPLOC=&quot;C:\Dump&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;set LOGLOC=&quot;C:\Dump&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;set DATABASES=%4&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;set USER=%3&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;set PORT=%2&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;set DT=%date%&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;set HOST=%1&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;REM DUMP MODE {CUSTOM,TAR,PLAIN}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;set DUMP_MODE=CUSTOM&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;set RETAIN_LAST_BACKUPS=2&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;%BIN%\psql -Atq -h %HOST% -U %USER% -p %PORT% -c &quot;select translate(replace(&#39;%DT%&#39;,&#39;/&#39;,&#39;_&#39;),&#39; &#39;,&#39;_&#39;);&quot; postgres &amp;gt;_TMP&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;set /p DT=&amp;lt;_TMP&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;REM Creating Scheduled Backup&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;%BIN%\psql -Atq -h %HOST% -U %USER% -p %PORT% -c &quot;select replace(&#39;%DATABASES%&#39;,&#39;&quot;&quot;&#39;,&#39;&#39;);&quot; postgres &amp;gt; _TMP&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;set /p DATABASES=&amp;lt;_TMP&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;FOR %%D IN ( %DATABASES% ) DO (&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;%BIN%\psql -Atq -h %HOST% -U %USER% -p %PORT% -c &quot;select &#39;Pg Dump Start For DB %%D Time :: &#39; || now();&quot; postgres &amp;gt;&amp;gt; %LOGLOC%\pgDump_%DT%.log&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;if %DUMP_MODE% EQU CUSTOM ( %BIN%\pg_dump -f %BACKUPLOC%\%HOST%_%%D_%PORT%_pgDump_%DT%.dmp -Fc -b -c -h %HOST% -U %USER% -p %PORT% %%D 2&amp;gt;_Error ) else ( if %DUMP_MODE% EQU TAR ( %BIN%\pg_dump -f %BACKUPLOC%\%HOST%_%%D_%PORT%_pgDump_%DT%.dmp -Ft -b -c -h %HOST% -U %USER% -p %PORT% %%D ) else ( if %DUMP_MODE% EQU PLAIN ( %BIN%\pg_dump -f %BACKUPLOC%\%HOST%_%%D_%PORT%_pgDump_%DT%.dmp -Fp -b -c -h %HOST% -U %USER% -p %PORT% %%D ) else ( exit ) ) ) &amp;gt;&amp;gt; %LOGLOC%\pgDump-%DT%.log&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;FOR %%E IN ( _Error ) DO IF %%~zE EQU 0 ( &amp;nbsp;FOR /f &quot;tokens=*&quot; %%F IN ( &#39; dir &amp;nbsp;/a /b /O-D %BACKUPLOC%\%HOST%_%%D_%PORT%_pgDump*.dmp^|more +%RETAIN_LAST_BACKUPS% &#39;) DO ( echo %%F &amp;gt;&amp;gt;_Files_To_Delete &amp;nbsp;) &amp;nbsp;) else (&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;echo Error Occured, Hence Keeping The Last Backups As It Is And Removing This Error Caused Dump ..&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;del /Q %BACKUPLOC%\%HOST%_%%D_%PORT%_pgDump_%DT%.dmp&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;%BIN%\psql -Atq -h %HOST% -U %USER% -p %PORT% -c &quot;select &#39;Pg Dump End For DB %%D Time :: &#39;||now();&quot; postgres &amp;gt;&amp;gt; %LOGLOC%\pgDump-%DT%.log&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;REM Doing Retention Policy..&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;FOR /f &quot;tokens=*&quot; %%R IN ( &#39;type _Files_To_Delete&#39; ) DO ( &amp;nbsp;DEL /Q %BACKUPLOC%\%%R &amp;nbsp;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;DEL /Q _Files_To_Delete&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;/pre&gt;
How to run&lt;br /&gt;
========&lt;br /&gt;
&lt;pre class=&quot;prettyprint linenums&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;Script_Name &amp;lt;host&amp;gt; &amp;lt;Port&amp;gt; &amp;lt;User&amp;gt; &quot;&amp;lt;DB1&amp;gt;,&amp;lt;DB2&amp;gt;,&amp;lt;DB3&amp;gt;,...&quot;&lt;/span&gt;
&lt;/pre&gt;
దినేష్ కుమార్&lt;br /&gt;
Dinesh Kumar&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/5356142976780182067/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2012/10/windows-pgdump-script.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/5356142976780182067'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/5356142976780182067'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2012/10/windows-pgdump-script.html' title='Windows Pg_Dump Script'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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-2844187126830320432.post-9031207059582988083</id><published>2012-08-29T19:37:00.003+05:30</published><updated>2012-08-29T21:58:49.257+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Email from PostgreSQL"/><category scheme="http://www.blogger.com/atom/ns#" term="Email in PostgreSQL"/><category scheme="http://www.blogger.com/atom/ns#" term="How to send E-Mail From PostgreSQL"/><category scheme="http://www.blogger.com/atom/ns#" term="Mail from PostgrSQL"/><category scheme="http://www.blogger.com/atom/ns#" term="Mail in PostgreSQL"/><title type='text'>How To Send E-Mail From PostgreSQL</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
Hi ,&lt;br /&gt;
&lt;br /&gt;
If you want to send E-Mails from PostgreSQL, then use the below Python 3.2 Script as below. I have used ActivePython 3.2 with PostgreSQL 9.1 for sending E-Mails from PostgreSQL.&lt;br /&gt;
&lt;br /&gt;
If you want to configure the Python 3.2 with PostgreSQL 9.1 then, please refer the below steps.&lt;br /&gt;
&lt;br /&gt;
http://manojadinesh.blogspot.in/2012/06/fatal-python-error-pyinitialize-unable.html&lt;br /&gt;
&lt;br /&gt;
Once, your Python 3.2 successful then follow the below steps to send an e-mail.&lt;br /&gt;
&lt;br /&gt;
Step 1&lt;br /&gt;
=====&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;postgres=# CREATE OR REPLACE FUNCTION public.send_email(_from Text,_password Text,smtp Text,port INT,receiver text, subject text, send_message text) RETURNS TEXT &amp;nbsp;LANGUAGE plpython3u&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;AS $function$&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;import smtplib&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;sender = _from&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;receivers = receiver&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;message = (&quot;From: %s\nTo: %s\nSubject: %s\n\n %s&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;% (_from,receiver,subject,send_message))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;try:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; smtpObj = smtplib.SMTP(smtp,port)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; smtpObj.starttls()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; smtpObj.login(_from, _password)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; smtpObj.sendmail(sender, receivers,message)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; print (&#39;Successfully sent email&#39;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;except SMTPException:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; print (&#39;Error: unable to send email&#39;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;return message&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;$function$&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;CREATE FUNCTION&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
Step 2&lt;/div&gt;
&lt;div&gt;
=====&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;postgres=# select send_email(&#39;dineshkumar02@gmail.com&#39;,&#39;XXPasswordXX&#39;,&#39;smtp.gmail.com&#39;,587,&#39;dinesh.kumar@mydomain.com&#39;,&#39;Sending E-Mail From PostgreSQL&#39;,&#39;Hi,\n How do you do ..&#39;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;send_email &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;-----------------------------------------&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;From: dineshkumar02@gmail.com &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;To: dinesh.kumar@mydomain.com &amp;nbsp; &amp;nbsp; &amp;nbsp;+&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;Subject: Sending E-Mail From PostgreSQL&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;(1 row)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Please check your Inbox after this function execution ..&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
దినేష్ కుమార్&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
Dinesh Kumar&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/9031207059582988083/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2012/08/how-to-send-e-mail-from-postgresql_29.html#comment-form' title='25 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/9031207059582988083'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/9031207059582988083'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2012/08/how-to-send-e-mail-from-postgresql_29.html' title='How To Send E-Mail From PostgreSQL'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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>25</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2844187126830320432.post-4402901959037054608</id><published>2012-08-24T13:27:00.001+05:30</published><updated>2012-08-24T13:27:22.633+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="OS commands from PostgreSQL"/><category scheme="http://www.blogger.com/atom/ns#" term="Os commands in PostgreSQL"/><category scheme="http://www.blogger.com/atom/ns#" term="OS results from PostgreSQL"/><category scheme="http://www.blogger.com/atom/ns#" term="PL/C in PostgreSQL"/><title type='text'>OS Results From PostgreSQL</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;
&lt;/div&gt;
Hi ,&lt;br /&gt;

&lt;div style=&quot;font-family: Times; font-size: 16px; min-height: 19px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
As of now, we are using &quot;\i&quot; or using &quot;PL/SH&quot; script for getting the OS command results from PostgreSQL. However, below is the one more option where we can get the required info.&lt;br /&gt;

&lt;br /&gt;

&lt;div style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;
&lt;span style=&quot;font-family: Arial;&quot;&gt;Step 1&lt;br /&gt;
======&lt;br /&gt;
&lt;/span&gt;#include &quot;postgres.h&quot;&lt;br /&gt;
#include &quot;fmgr.h&quot;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#ifdef PG_MODULE_MAGIC&lt;br /&gt;
PG_MODULE_MAGIC;&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
PG_FUNCTION_INFO_V1(shell_exec);&lt;br /&gt;
Datum&lt;br /&gt;
shell_exec(PG_FUNCTION_ARGS)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; text&amp;nbsp; *arg1 = PG_GETARG_TEXT_P(0);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; char&amp;nbsp; *Command=VARDATA(arg1);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; int32 result=system(Command);&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; PG_RETURN_TEXT_P(result);&lt;br /&gt;
}&lt;br /&gt;
&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;br /&gt;
Step 2&lt;br /&gt;
=======&lt;br /&gt;
&lt;/span&gt;-bash-3.2$ more Makefile&lt;br /&gt;
PG_CONFIG = /opt/PostgresPlus/9.0AS/bin/pg_config&lt;br /&gt;
MODULES =&amp;nbsp;shell_exec&lt;br /&gt;
PGXS := $(shell $(PG_CONFIG) --pgxs)&lt;br /&gt;
include $(PGXS)&lt;br /&gt;
&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;br /&gt;
Step 3&lt;br /&gt;
======&lt;br /&gt;
&lt;/span&gt;make and .so file to $PGHOME/lib&amp;nbsp; or $PGHOME/lib/postgres/&lt;br /&gt;
&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;br /&gt;
Step 4&lt;br /&gt;
======&lt;br /&gt;
&lt;/span&gt;postgres=# CREATE OR REPLACE FUNCTION&amp;nbsp;shell_exec(text) RETURNS int&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AS &#39;shell_exec.so&#39;, &#39;shell_exec&#39;&amp;nbsp;&amp;nbsp;&lt;br /&gt;
LANGUAGE C STRICT;&lt;br /&gt;
CREATE FUNCTION&lt;br /&gt;
&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;br /&gt;
Step 5&lt;br /&gt;
======&lt;br /&gt;
&lt;/span&gt;postgres=# select&amp;nbsp;shell_exec(&#39;vmstat 1 &amp;gt;/opt/PostgreSQL/9.0/data/output&#39;);&lt;br /&gt;
^CCancel request sent&lt;br /&gt;
postgres=# select pg_read_file(&#39;/opt/PostgreSQL/9.0/data/output&#39;,1,1000000);&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;&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; pg_read_file&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;&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;&lt;br /&gt;
------------------------------------------------------------------------------------------&lt;br /&gt;
&amp;nbsp;rocs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +&lt;br /&gt;
&amp;nbsp; r&amp;nbsp; b&amp;nbsp;&amp;nbsp; swpd&amp;nbsp;&amp;nbsp; free&amp;nbsp;&amp;nbsp; buff&amp;nbsp; cache&amp;nbsp;&amp;nbsp; si&amp;nbsp;&amp;nbsp; so&amp;nbsp;&amp;nbsp;&amp;nbsp; bi&amp;nbsp;&amp;nbsp;&amp;nbsp; bo&amp;nbsp;&amp;nbsp; in&amp;nbsp;&amp;nbsp; cs us sy id wa st&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +&lt;br /&gt;
&amp;nbsp; 0&amp;nbsp; 0 2653376 654888&amp;nbsp; 31832 248464&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&amp;nbsp;&amp;nbsp; 14&amp;nbsp;&amp;nbsp;&amp;nbsp; 28&amp;nbsp;&amp;nbsp; 220&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&amp;nbsp;&amp;nbsp; 12&amp;nbsp; 4&amp;nbsp; 5 89&amp;nbsp; 1&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +&lt;br /&gt;
&amp;nbsp; 0&amp;nbsp; 0 2653376 654988&amp;nbsp; 31832 248468&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 40&amp;nbsp; 693 1310&amp;nbsp; 0&amp;nbsp; 1 99&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +&lt;br /&gt;
&amp;nbsp; 1&amp;nbsp; 0 2653376 654856&amp;nbsp; 31840 248468&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 116&amp;nbsp; 704 1348&amp;nbsp; 0&amp;nbsp; 1 99&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +&lt;br /&gt;
&amp;nbsp; 0&amp;nbsp; 0 2653376 654608&amp;nbsp; 31840 248472&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp; 664 1494&amp;nbsp; 0&amp;nbsp; 1 100&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +&lt;br /&gt;
&amp;nbsp; 0&amp;nbsp; 0 2653376 654740&amp;nbsp; 31840 248472&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp; 631 1522&amp;nbsp; 0&amp;nbsp; 1 99&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +&lt;br /&gt;
&amp;nbsp; 0&amp;nbsp; 0 2653376 654732&amp;nbsp; 31840 248476&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp; 674 1519&amp;nbsp; 0&amp;nbsp; 1 99&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +&lt;br /&gt;
&amp;nbsp; 0&amp;nbsp; 0 2653376 654756&amp;nbsp; 31840 248476&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 156&amp;nbsp; 616 1541&amp;nbsp; 0&amp;nbsp; 1 100&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +&lt;br /&gt;
&amp;nbsp; 0&amp;nbsp; 0 2653376 654748&amp;nbsp; 31848 248480&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 72&amp;nbsp; 620 1331&amp;nbsp; 0&amp;nbsp; 1 99&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +&lt;br /&gt;
&amp;nbsp; 0&amp;nbsp; 0 2653376 654748&amp;nbsp; 31848 248480&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp; 599 1299&amp;nbsp; 0&amp;nbsp; 0 99&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +&lt;br /&gt;
&amp;nbsp; 0&amp;nbsp; 0 2653376 654740&amp;nbsp; 31848 248484&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp; 630 1292&amp;nbsp; 0&amp;nbsp; 1 99&amp;nbsp; 0&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +&lt;br /&gt;
&amp;nbsp; 0&amp;nbsp; 0 2653376 654972&amp;nbsp; 31848 248484&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 32&amp;nbsp; 664 1358&amp;nbsp; 0&amp;nbsp; 1 99&amp;nbsp; 0&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;
0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +&lt;/div&gt;
&lt;div style=&quot;font-family: Times; font-size: 16px; min-height: 19px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Telugu Sangam MN&#39;;&quot;&gt;
దినేష్&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;కుమార్&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;
Dinesh Kumar&lt;/div&gt;
&lt;br /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://manojadinesh.blogspot.com/feeds/4402901959037054608/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://manojadinesh.blogspot.com/2012/08/os-results-from-postgresql_24.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/4402901959037054608'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2844187126830320432/posts/default/4402901959037054608'/><link rel='alternate' type='text/html' href='http://manojadinesh.blogspot.com/2012/08/os-results-from-postgresql_24.html' title='OS Results From PostgreSQL'/><author><name>Dinesh Kumar</name><uri>http://www.blogger.com/profile/02806765231092689430</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></feed>