External Replication - Mailing list pgsql-hackers

From md@rpzdesign.com
Subject External Replication
Date
Msg-id 505CAE0A.6070507@rpzdesign.com
Whole thread Raw
In response to Re: DB & Schema  (Heikki Linnakangas <hlinnakangas@vmware.com>)
Responses Re: External Replication  (Andres Freund <andres@2ndquadrant.com>)
List pgsql-hackers
Heikki:

Thanks for the response.  I am writing an external replication engine
and putting hooks into postgres to send "signals" via a unix socket to 
the outside world.

All of the logic and implementation will occur OUTSIDE the postgres 
codebase and
will not interfere with any WAL based replication schemes.

The usual "Trigger" level asynch replication does on not suffice since 
it does not handle
new databases, new schemas, new tables, new indexes, alter everything, 
new functions, etc.

So I started putting into utility.c->xxx_ProcessUtility(..., stmt* 
parsetree,....) so that discrete

Does anybody have other ideas where to better locate the "Hooks" for 
external replication/signaling
than utility.c?

One drawback is that I have to patch directly into those areas where new 
relation IDs are created
so I can pass them outside of the process to the replication engine.  
Process Utility does a really bad job of retaining
its work as it processes the statements, so I have to patch code where 
the relation IDS are created.  Those new IDS are never retained
when leaving ProcessUtility, its work is done.

Is there a way to put a "Trigger" on pg_class, pg_database, pg_namespace 
instead of patching the statically
compiled binary to simulate the triggers?

Cheers,

marco


On 9/21/2012 10:15 AM, Heikki Linnakangas wrote:
> On 21.09.2012 17:58, md@rpzdesign.com wrote:
>> During the execution of ProcessUtility() function in
>> /src/backend/xxx/utility.c,
>>
>> the CreateStmt node type is processed to create a table.
>>
>> Is there a global function in the context of the backend process that
>> will deliver what the current database and schema names?
>
> There's a global variable MyDatabaseId for the database the backend is 
> connected to. It doesn't change after login.
>
> There's no such thing as a "current schema", but I think you'll want 
> to take a look at src/backend/catalog/namespace.c, which handles the 
> search_path. There's a variable activeCreationNamespace there; look at 
> the functions in namespace.c to see how it works.
>
> - Heikki
>
>




pgsql-hackers by date:

Previous
From: "David E. Wheeler"
Date:
Subject: Re: CREATE SCHEMA IF NOT EXISTS
Next
From: Andres Freund
Date:
Subject: Re: External Replication