<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>treibsand.com &#187; Replikation</title>
	<atom:link href="http://www.treibsand.com/tag/replikation/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.treibsand.com</link>
	<description></description>
	<lastBuildDate>Tue, 27 Dec 2011 12:46:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>PostgreSQL Replikation</title>
		<link>http://www.treibsand.com/2009/06/16/postgresql-replikation/</link>
		<comments>http://www.treibsand.com/2009/06/16/postgresql-replikation/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 09:59:30 +0000</pubDate>
		<dc:creator>Toast</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[Datenbank]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Replikation]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.treibsand.com/?p=312</guid>
		<description><![CDATA[Replikation bei Datenbanken ist ein ziemlich umfangreiches Thema. PostgreSQL bietet in der Distribution leider keine mitgelieferte Möglichkeit Datenbanken in einem Master-Slave Setup zu replizieren. Da ist man auf Tools wie Slony-I oder die Skytools angewiesen. Da Slony-I sehr umfangreich und nicht gerade einfach zu konfigurieren ist, habe ich mir die Skytools bzw. londiste näher angeschaut, [...]]]></description>
			<content:encoded><![CDATA[<p>Replikation bei Datenbanken ist ein ziemlich umfangreiches Thema. PostgreSQL bietet in der Distribution leider keine mitgelieferte Möglichkeit Datenbanken in einem Master-Slave Setup zu replizieren. Da ist man auf Tools wie <a href="http://www.slony.info/">Slony-I</a> oder die <a href="https://developer.skype.com/SkypeGarage/DbProjects/SkyTools">Skytools</a> angewiesen. Da Slony-I sehr umfangreich und nicht gerade einfach zu konfigurieren ist, habe ich mir die Skytools bzw. londiste näher angeschaut, und muss sagen, dass es wirklich hervorragend funktioniert.</p>
<p><span id="more-312"></span><br />
Die Skytools sind von Skype, und können auf der <a href="http://pgfoundry.org/">PgFoundry</a> Seite gefunden werden.  Als Beispiel nehmen wir eine einfache Datenbank mit nur einer Tabelle&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">SEQUENCE</span> test_seq <span style="color: #993333; font-weight: bold;">START</span> <span style="color: #993333; font-weight: bold;">WITH</span> <span style="color: #cc66cc;">1</span>;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> test <span style="color: #66cc66;">&#40;</span>
  id int4 <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span> 
  txt text
<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Jetzt brauchen wir noch ein paar Datensätze&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> test <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">NEXTVAL</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'test_seq'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'bla'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> test <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">NEXTVAL</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'test_seq'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'blub'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> test <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">NEXTVAL</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'test_seq'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'test text'</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Nachdem alle Tabelle angelegt ist, sollte die Datenbank auf dem Slave Server erstellt werden. Danach können die Inhalte mit einem Dump initial übernommen werden&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ pg_dump <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-s</span> <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #000000; font-weight: bold;">|</span> psql <span style="color: #660033;">-h</span> <span style="color: #000000; font-weight: bold;">&lt;</span>IP-VON-SLAVE<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #660033;">-U</span> postgres <span style="color: #7a0874; font-weight: bold;">test</span></pre></div></div>

<p>Damit londiste laufen kann, brauchen wir einen Ticker, dieser muss auf dem Master-Server laufen. Die Konfiguration kann wie folgt aussehen (hier die Datei /etc/ticker.ini):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>pgqadm<span style="color: #7a0874; font-weight: bold;">&#93;</span>
job_name = ticker
db = <span style="color: #007800;">dbname</span>=<span style="color: #7a0874; font-weight: bold;">test</span> 
maint_delay_min = <span style="color: #000000;">1</span>
loop_delay = <span style="color: #000000;">0.5</span>
logfile = <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>log.<span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>job_name<span style="color: #7a0874; font-weight: bold;">&#41;</span>s
pidfile = <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>pid.<span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>job_name<span style="color: #7a0874; font-weight: bold;">&#41;</span>s
use_skylog = <span style="color: #000000;">0</span>
connection_lifetime = <span style="color: #000000;">21</span>
queue_refresh_period = <span style="color: #000000;">10</span></pre></div></div>

<p>Danach kann der Ticker gestartet werden&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ pgqadm.py <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ticker.ini ticker</pre></div></div>

<p>Als nächstes brauchen wir noch für londiste ebenfalls eine Konfigurationsdatei (hier /etc/londiste.ini):</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #66cc66;">&#91;</span>londiste<span style="color: #66cc66;">&#93;</span>
job_name <span style="color: #66cc66;">=</span> test_to_subcriber
provider_db <span style="color: #66cc66;">=</span> dbname<span style="color: #66cc66;">=</span>test port<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">5432</span> host<span style="color: #66cc66;">=&lt;</span>IP<span style="color: #66cc66;">-</span>VON<span style="color: #66cc66;">-</span>MASTER<span style="color: #66cc66;">&gt;</span>
subscriber_db <span style="color: #66cc66;">=</span> dbname<span style="color: #66cc66;">=</span>test port<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">5432</span> host<span style="color: #66cc66;">=&lt;</span>IP<span style="color: #66cc66;">-</span>VON<span style="color: #66cc66;">-</span>SLAVE<span style="color: #66cc66;">&gt;</span>
pgq_queue_name <span style="color: #66cc66;">=</span> londiste<span style="color: #66cc66;">.</span>replika
logfile <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">/</span>tmp<span style="color: #66cc66;">/</span>%<span style="color: #66cc66;">&#40;</span>job_name<span style="color: #66cc66;">&#41;</span>s<span style="color: #66cc66;">.</span>log
pidfile <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">/</span>tmp<span style="color: #66cc66;">/</span>%<span style="color: #66cc66;">&#40;</span>job_name<span style="color: #66cc66;">&#41;</span>s<span style="color: #66cc66;">.</span>pid</pre></div></div>

<p>Die londiste Konfigurationsdatei muss auf beiden Server sein, damit die Replikation funktioniert. Auf dem Slave-System kann londiste nun installiert werden</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ londiste.py <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>londiste.ini provider <span style="color: #c20cb9; font-weight: bold;">install</span>
$ londiste.py <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>londiste.ini subscriber <span style="color: #c20cb9; font-weight: bold;">install</span>
$ londiste.py <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>londiste.ini provider add <span style="color: #7a0874; font-weight: bold;">test</span>
$ londiste.py <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>londiste.ini subscriber add <span style="color: #7a0874; font-weight: bold;">test</span>
$ londiste.py <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>londiste.ini replay</pre></div></div>

<p>Londiste läuft nun im Hintergrund als Daemon und sollte alle neuen Daten sofort auf den Slave replizieren.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.treibsand.com/2009/06/16/postgresql-replikation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

