Skip to main content

Posts

Showing posts from April, 2014

N-Node Mutlimaster Replication With Bucardo...!

Our team recently got  a problem, which is to solve the N-Node multi master replication in PostgreSQL. We all know that, there are some other db engines like Postgres-XC which works in this way. But, we don't have any tool available in PostgreSQL, except Bucardo. Bucardo is the nice solution for 2-Nodes. Is there a way we can exceed this limitation from 2 to N..? 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.} Please follow the below steps to set up the 1 - 1 multi master replication. 1. Follow the below steps to get all the pre-requisites for the Bucardo. 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 here . tar xvfz Bucardo-4.4.8.tar.gz cd Bucardo-4.4.8 perl Makefile.PL make sudo make install 2. We need to create plperl extension in db. For t

Normal User As Super User

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't get the result what we get as a superuser. This is really a good security between super user and normal user. What we need to do, if we want to collect these metrics as normal user. I think the possible solution is "Write a wrapper function with security definer as like below" and grant/revoke the required privileges to the user/public. CREATE OR REPLACE FUNCTION pg_stat_activity( RETURNS SETOF pg_catalog.pg_stat_activity AS $$ BEGIN RETURN QUERY(SELECT * FROM pg_catalog.pg_stat_activity); END $$ LANGUAGE PLPGSQL SECURITY DEFINER; REVOKE ALL ON FUNCTION pg_stat_activity() FROM public; CREATE VIEW pg_stat_activity AS SELECT * FROM pg_stat_activity(); REVOKE ALL ON pg_stat_activity FROM public;

Cartoon in pg.

I hope this gives you a bit FUN with pg SQL. select * from (select array_to_string(array_agg(CASE WHEN (power((xx.x-25),2)/130+power((yy.y-25),2)/130)=1 THEN '$' WHEN (sqrt(power(xx.x-20,2)+power(yy.y-20,2)))<2 THEN '#' WHEN (sqrt(power(xx.x-20,2)+power(yy.y-30,2)))<2 THEN '#' WHEN (sqrt(power(xx.x-29,2)+power(yy.y-25,2)))<4 THEN '#' WHEN (power((xx.x-10),2)/40+power((yy.y-10),2)/40)=1 THEN '$' WHEN (power((xx.x-10),2)/40+power((yy.y-40),2)/40=1) THEN '$' ELSE ' ' END),' ') 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; Oracle Mode 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)/