Skip to main content

Posts

Showing posts from 2013

Pgpool Configuration & Failback

I would like to share the pgpool configuration, and it's failback mechanism in this post. Hope it will be helpful to you in creating pgpool and it's failback setup. Pgpool Installation & Configuration 1. Download the pgpool from below link(Latest version is 3.2.1).     http://www.pgpool.net/mediawiki/index.php/Downloads 
2. Untart the pgpool-II-3.2.1.tar.gz and goto pgpool-II-3.2.1 directory. 3. Install the pgpool by executing the below commands:   ./configure ­­prefix=/opt/PostgreSQL92/ ­­--with­-pgsql­-includedir=/opt/PostgreSQL92/include/ --with­-pgsql­-libdir=/opt/PostgreSQL92/lib/ make make install 4. You can see the pgpool files in /opt/PostgreSQL92/bin location. /opt/PostgreSQL92/bin $ ls clusterdb   droplang  pcp_attach_node  pcp_proc_count pcp_systemdb_info  pg_controldata  pgpool pg_test_fsync pltcl_loadmod  reindexdb createdb    dropuser  pcp_detach_node  pcp_proc_info createla...

Regex to parse PostgreSQL CSV log files.

It took sometime to me to understand the powerful concept, i.e, REGEX. Below is the REGEX expression to parse the CSV log files, which have been generated by PostgreSQL. Regex is :- -=-=-=-=-= "^((([^, \"\n\r ]*)|( \" ([^ \" ]|( \"\" ))* \" )),){22}( \" ([^ \" ]|( \"\" ))* \" [ \r\n ]+)" Use any regex tools like RegexBuddy, which will give you detailed information about this regular expression. Dinesh Kumar

Game with postgreSQL

I developed this game a bit long ago, and would like to share with the world. 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't looked into any of the line in this code. {Very bad habbit, i need to over come this.} I hope you enjoy it, and correct if any problems occurs. This game is for only 2 players, which will give you the realtime game feel with your opponent. First find the code, and then instructions. C Program -=-=-=-=-=- #include "stdio.h" #include "ncurses.h" #include "/opt/PostgreSQL/9.0/include/libpq-fe.h" #include "stdlib.h" #include "string.h" 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("/tmp/.cred","...

Interactive PostgreSQL Script

Do you want an input from end user, while running PostgreSQL script. No Problem, here is the one of the solution for you. In the following example, i am taking the confirmation from an end user, before dropping an existing database called "sample". -- 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 != 'y|Y'; -- \set ON_ERROR_STOP on -- Take input from the user. -- \prompt 'Are you sure to drop ' Do_You_Want_To_Drop_Db -- Get the user input. -- \set Do_Drop_Db '\'' :Do_You_Want_To_Drop_Db '\'' -- 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('y', 'Y')) THEN RAISE EXCEPTION 'Database won''t dr...

Sample ECPG Script

Hi Below is the sample ECPG test case what i have prepared. Sample ECPG Scripts ================ -bash-4.1$ more foo2.h typedef struct { foo123 a[8]; } bar; -bash-4.1$ more foo1.h typedef struct { int x; }foo123; -bash-4.1$ more foo.pgc EXEC SQL INCLUDE "foo1.h"; EXEC SQL INCLUDE "foo2.h"; int main() {     EXEC SQL BEGIN DECLARE SECTION;         char* dbname = "edb";         char* db     = "edb@localhost:5444";         char* user   = "enterprisedb";         char* passwd = "adminedb";     EXEC SQL END DECLARE SECTION;     bar records;     EXEC SQL WHENEVER SQLERROR      GOTO sql_error;     EXEC SQL CONNECT :user IDENTIFIED BY :passwd AT :dbname USING :db;         EXEC SQL AT :dbname DECLARE cur_TBL CURSOR FOR                 SELECT CO...