问题描述:

As title suggests,

Current tutorials i have found thus far use embedded SLON commands in Shell Script files to setup the required configuration for Slony-I master to slave replication.

For example: Slony-I Setup Tutorial

I was wondering if it was possible to embedd the SLON setup commands and have them called within another language Eg C/C++/Python working within a linux environment?

网友答案:

SLONIK scripts generally work by writing through STDOUT to the slonik binary. Any language should have the ability to replicate this style, but there's little difference than using the shell script method and in my experience it tends to occlude what is being done. You are still, after all, writing to the STDOUT and sending that information to the slonik binary.

I have in the past written perl modules to assist with this but they felt very kludgey and I've only employed them when needing to dynamically modify replication setups. I find it is rare that something like this is required and for the vast majority of slony work a shell script is much simpler to manage.

To sum up: Yes you can, but it is probably only making things more complex.

An example of how you could do it in python would be:

p = subprocess.Popen('/usr/bin/slonik',stdout=subprocess.PIPE,stdin=subprocess.PIPE)
p.stdin.write('<slon commands here>')
p.stdin.close()
相关阅读:
Top