<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="http://julien.danjou.info/blog/index.php/feed/rss2/xslt" ?><rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
  <title>jd:/dev/blog - Tag - postgresql</title>
  <link>http://julien.danjou.info/blog/index.php/</link>
  <atom:link href="http://julien.danjou.info/blog/index.php/feed/tag/postgresql/rss2" rel="self" type="application/rss+xml"/>
  <description>Julien Danjou's blog</description>
  <language>fr</language>
  <pubDate>Fri, 14 Nov 2008 16:30:23 +0100</pubDate>
  <copyright>All Right Reserved</copyright>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Dotclear</generator>
  
    
  <item>
    <title>Upgrading MediaWiki from PostgreSQL 8.2 to 8.3</title>
    <link>http://julien.danjou.info/blog/index.php/post/2008/05/19/Upgrading-mediawiki-from-PostgreSQL-82-to-83</link>
    <guid isPermaLink="false">urn:md5:942453a00bcbbc6432246af459c04584</guid>
    <pubDate>Mon, 19 May 2008 11:56:00 +0200</pubDate>
    <dc:creator>jd</dc:creator>
        <category>Free Software</category>
        <category>mediawiki</category><category>postgresql</category>    
    <description>    &lt;p&gt;With my server migration I switched from &lt;a href=&quot;http://www.postgresql.org&quot;&gt;PostgreSQL&lt;/a&gt; 8.2 to 8.3. However, I've installed &lt;a href=&quot;http://www.mediawiki.org&quot;&gt;MediaWiki&lt;/a&gt; for the &lt;a href=&quot;http://awesome.naquadah.org/wiki/&quot;&gt;awesome wiki&lt;/a&gt; on 8.2, but dumping from 8.2 and restoring to 8.3 just failed because of the tsearch2 extension, which is now part of PostgreSQL 8.3.&lt;/p&gt;


&lt;p&gt;With the help of my friend &lt;a href=&quot;http://pgsql.tapoueh.org/&quot;&gt;Dimitri&lt;/a&gt;, the &lt;a href=&quot;http://pgfoundry.org/projects/pgloader/&quot;&gt;pgloader&lt;/a&gt; author, I managed to migrate the database from PostgreSQL 8.2 to 8.3. Here is how I did.&lt;/p&gt;


&lt;p&gt;This was done with MediaWiki 1.12, and I doubt that &lt;a href=&quot;http://people.planetpostgresql.org/greg/index.php?/archives/123-MediaWiki-is-Postgres-8.3-compatible.html&quot;&gt;older version supports PostgreSQL 8.3&lt;/a&gt;.&lt;/p&gt;


&lt;h2&gt;Dump the database schema&lt;/h2&gt;


&lt;p&gt;First, you need to dump the database schema, and then, the database data. We need to do it in two steps because we need to change the schema a bit. I assume that MediaWiki is installed in the &lt;em&gt;mediawiki&lt;/em&gt; schema:&lt;/p&gt;

&lt;pre&gt;
% pg_dump -s -n mediawiki wikidb &amp;gt; wikidb-schema.sql
&lt;/pre&gt;


&lt;h2&gt;Convert the schema&lt;/h2&gt;

&lt;p&gt;Then, edit your &lt;em&gt;wikidb-schema.sql&lt;/em&gt;. When you installed &lt;em&gt;tsearch2&lt;/em&gt;, you probably did it in the &lt;em&gt;public&lt;/em&gt; schema like I did. So it created two or three data types used by MediaWiki wich are named &lt;em&gt;public.datatype&lt;/em&gt;. These &lt;em&gt;tsearch2&lt;/em&gt; datatypes are now part of PostgreSQL, so they're in the &lt;em&gt;pg_catalog&lt;/em&gt; schema. You just need to replace a few lines with &lt;em&gt;public.datatype&lt;/em&gt; with &lt;em&gt;pg_catalog.datatype&lt;/em&gt;. For example &lt;em&gt;public.tsvector&lt;/em&gt; is now &lt;em&gt;pg_catalog.tsvector&lt;/em&gt;. For your information &lt;em&gt;gin_tsvector_ops&lt;/em&gt; is now &lt;em&gt;pg_catalog.tsvector_ops&lt;/em&gt;.&lt;/p&gt;


&lt;p&gt;Finished? Good, but that's not all. You need to split up the file in two parts: one with the tables creation, and another one with the constraints creation. Why? Because otherwise the data insertion will fail because of these constraints. That's not so hard, just split your files in &lt;em&gt;wikidb-schema.sql&lt;/em&gt; with all &lt;em&gt;CREATE TABLE&lt;/em&gt; and so one, and then you see that the SQL file begins to do some &lt;em&gt;ADD CONSTRAINTS&lt;/em&gt;, just put this in another file, named &lt;em&gt;wikidb-constraints-schema.sql&lt;/em&gt;. You'll also need to set the namespace before executing command in your second file, so do not forget to add a &lt;em&gt;SET search_path = mediawiki, pg_catalog;&lt;/em&gt; line at the beginning.&lt;/p&gt;


&lt;h2&gt;Dump the database data&lt;/h2&gt;


&lt;p&gt;That's easy:&lt;/p&gt;

&lt;pre&gt;
% pg_dump -a -n mediawiki wikidb &amp;gt; wikidb-data.sql
&lt;/pre&gt;


&lt;h2&gt;Create your new database&lt;/h2&gt;


&lt;p&gt;That's easy too:&lt;/p&gt;

&lt;pre&gt;
% createuser -S -D -R -P -E wikiuser #(then enter the password)
% createdb -O wikiuser wikidb
% createlang plpgsql wikidb
&lt;/pre&gt;


&lt;h2&gt;Restore the database&lt;/h2&gt;


&lt;p&gt;That's even easier, but you need to respect this order, otherwise it will fail:&lt;/p&gt;

&lt;pre&gt;
# Restore schema first
% psql wikidb &amp;lt; wikidb-schema.sql
# Then restore dat
% psql wikidb &amp;lt; wikidb-data.sql
# Then restore constraints
% psql wikidb &amp;lt; wikidb-constraints-schema.sql
&lt;/pre&gt;


&lt;h2&gt;Run update.php&lt;/h2&gt;

&lt;p&gt;Just go the the maintenance directory. Then you can try to run &lt;em&gt;update.php&lt;/em&gt;, but it'll fail.&lt;/p&gt;

&lt;pre&gt;
% php update.php
[...]
Could not open &amp;quot;/var/www/awesome.naquadah.org/wiki/maintenance/postgres/archives/patch-tsearch2funcs.sql&amp;quot;.
&lt;/pre&gt;


&lt;p&gt;Well it seems that MediaWiki people just forgot this file in the 1.12 archive.. You can grab it on the SVN repository &lt;a href=&quot;http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/maintenance/postgres/archives/patch-tsearch2funcs.sql?view=log&quot;&gt;here&lt;/a&gt;. When you've put it in the good directory, really run:&lt;/p&gt;

&lt;pre&gt;
% php update.php
[...]
&lt;/pre&gt;


&lt;p&gt;You should see no error. And now it works.&lt;/p&gt;


&lt;h2&gt;Give us some kudos&lt;/h2&gt;


&lt;p&gt;This is the last and hardest part of this tutorial. Since everything works, you should give kudos to Dimitri and me. &lt;img src=&quot;/blog//themes/geeek.org/smilies/smile.png&quot; alt=&quot;:-)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;</description>
    
    
    
      </item>
    
  <item>
    <title>Boarding the Prometheus</title>
    <link>http://julien.danjou.info/blog/index.php/post/2008/05/16/Boarding-the-Prometheus</link>
    <guid isPermaLink="false">urn:md5:577fb957ed1ccf6af5cf26621292f593</guid>
    <pubDate>Sun, 18 May 2008 10:26:00 +0200</pubDate>
    <dc:creator>jd</dc:creator>
        <category>Naquadah Network</category>
        <category>amavisd-new</category><category>clamav</category><category>courier</category><category>dovecot</category><category>dspam</category><category>email</category><category>exim</category><category>mysql</category><category>naquadah</category><category>postfix</category><category>postfixadmin</category><category>postgresql</category><category>procmail</category><category>sieve</category><category>spamassassin</category>    
    <description>    &lt;p&gt;As I said a month ago, my main server &lt;em&gt;Delmak&lt;/em&gt; was dying. Well it still runs (proof: you could read this blog some days ago).&lt;/p&gt;


&lt;p&gt;Thanks to friends I host for free, they've kindly given enough money to buy a brand new server (C2D E8400, 4 GB RAM, 2x500 GB RAID 1) in order to replace the good old &lt;em&gt;Delmak&lt;/em&gt;.
&lt;img src=&quot;http://julien.danjou.info/blog/public/img/Prometheus_Stargate_Grace.jpg&quot; alt=&quot;Prometheus&quot; style=&quot;float:right; margin: 0 0 1em 1em;&quot; /&gt;This new box has been named &lt;em&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Tau%27ri_starships_in_Stargate#Prometheus&quot;&gt;Prometheus&lt;/a&gt;&lt;/em&gt; after the only &lt;em&gt;BC-303&lt;/em&gt; class battleship ever built.&lt;/p&gt;


&lt;p&gt;&lt;em&gt;Delmak&lt;/em&gt; was used to mainly run as a Web, mail and databases server. I decided to do use this server switch to change the server software I use.&lt;/p&gt;


&lt;p&gt;The first mail server I setup was based on &lt;em&gt;&lt;a href=&quot;http://www.exim.org&quot;&gt;Exim 3&lt;/a&gt;&lt;/em&gt;, &lt;em&gt;courier-{imap,pop}{-ssl,}&lt;/em&gt; with userdb files. That was... rough. Later I switched to &lt;em&gt;&lt;a href=&quot;http://www.exim.org&quot;&gt;Exim 4&lt;/a&gt;&lt;/em&gt;, using &lt;em&gt;&lt;a href=&quot;http://silverwraith.com/vexim/&quot;&gt;vexim&lt;/a&gt;&lt;/em&gt;, and &lt;em&gt;&lt;a href=&quot;http://www.mysql.org&quot;&gt;MySQL&lt;/a&gt;&lt;/em&gt; as a back-end. That was something like 3 years ago I guess. Since then I never really touched that back. I added &lt;em&gt;&lt;a href=&quot;http://www.spamassassin.apache.org&quot;&gt;spamassassin&lt;/a&gt;&lt;/em&gt; and &lt;em&gt;&lt;a href=&quot;http://www.clamav.net&quot;&gt;clamav&lt;/a&gt;&lt;/em&gt; filtering some months after, because some users asked for it. That's all.&lt;/p&gt;


&lt;p&gt;So this week, I decided to switch away from this configuration. I do not understand &lt;em&gt;Exim&lt;/em&gt; anymore anyway, so I decided to use &lt;em&gt;&lt;a href=&quot;http://www.postfix.org&quot;&gt;Postfix&lt;/a&gt;&lt;/em&gt; which I often use and administrate at work. Obviously, I also now use &lt;em&gt;&lt;a href=&quot;http://www.postgresql.org&quot;&gt;PostgreSQL&lt;/a&gt;&lt;/em&gt; as database back-end, since it rocks, and since &lt;em&gt;&lt;a href=&quot;http://postfixadmin.sourceforge.net/&quot;&gt;Postfixadmin&lt;/a&gt;&lt;/em&gt; supports it. By the way, be aware that the Debian package of &lt;em&gt;postfixadmin&lt;/em&gt; is crappy (the configuration file is readable by anyone by default, with the database password in it).
I also set up &lt;em&gt;&lt;a href=&quot;http://postgrey.schweikert.ch/&quot;&gt;postgrey&lt;/a&gt;&lt;/em&gt; which is quite nice and efficient.&lt;/p&gt;


&lt;p&gt;Well, then was time for &lt;em&gt;&lt;a href=&quot;http://www.ijs.si/software/amavisd/&quot;&gt;amavisd-new&lt;/a&gt;&lt;/em&gt; installation, but I did not do it. Seriously, &lt;em&gt;amavisd-new&lt;/em&gt; configuration is a bloody mess, as the language it is written in (yes, &lt;em&gt;&lt;a href=&quot;http://www.perl.org&quot;&gt;Perl&lt;/a&gt;&lt;/em&gt;).&lt;/p&gt;


&lt;p&gt;So I switched to &lt;em&gt;&lt;a href=&quot;http://dspam.nuclearelephant.com/&quot;&gt;dspam&lt;/a&gt;&lt;/em&gt; which I heard is nice. Well, it seems to be for now, since it even supports &lt;em&gt;clamav&lt;/em&gt; daemon usage directly, which is very very nice because that means I do not have to set up another thing for that.&lt;/p&gt;


&lt;p&gt;I also switched from &lt;em&gt;&lt;a href=&quot;http://www.courier-mta.org&quot;&gt;courier&lt;/a&gt;&lt;/em&gt; to &lt;em&gt;&lt;a href=&quot;http://www.dovecot.org&quot;&gt;dovecot&lt;/a&gt;&lt;/em&gt;, mainly because the latter seems to be faster and lighter. I then changed the default &lt;em&gt;virtual_transport&lt;/em&gt; to &lt;em&gt;&lt;a href=&quot;http://wiki.dovecot.org/LDA&quot;&gt;Dovecot LDA&lt;/a&gt;&lt;/em&gt;. The main advantage of this is that the LDA updates the &lt;em&gt;Dovecot&lt;/em&gt; index while delivering. It also supports quota, which I do not use and plug-ins, like the &lt;em&gt;&lt;a href=&quot;http://sieve.info/&quot;&gt;Sieve&lt;/a&gt;&lt;/em&gt; language for mail filtering.&lt;/p&gt;


&lt;p&gt;So I decided to change my &lt;em&gt;procmailrc&lt;/em&gt; to a new Sieve filter. My &lt;em&gt;procmailrc&lt;/em&gt; is quite small since I only use regex to match lists and some mail address, so it has only something like 12 rules.
And well, I did not do it since I discovered after some googling that &lt;em&gt;Dovecot&lt;/em&gt; implementation of &lt;em&gt;Sieve&lt;/em&gt; is grabbed from &lt;em&gt;Cyrus&lt;/em&gt; which does not support variables for now. That means that the following &lt;em&gt;procmailrc&lt;/em&gt; code:&lt;/p&gt;

&lt;pre&gt;
:0:
* ^X-Mailing-List: &amp;lt;debian-.+@lists.debian.org&amp;gt;
* ^X-Mailing-List: &amp;lt;debian-\/[^@]+
list-debian-$MATCH/
&lt;/pre&gt;


&lt;p&gt;which will translate to:&lt;/p&gt;

&lt;pre&gt;
require [ &amp;quot;regex&amp;quot;, &amp;quot;variables&amp;quot;, &amp;quot;fileinto&amp;quot; ]
if header :regex &amp;quot;X-Mailing-List&amp;quot; &amp;quot;&amp;lt;debian-(.+)@&amp;quot;
{
    fileinto &amp;quot;lists.debian.${1}&amp;quot;;
    stop;
}
&lt;/pre&gt;


&lt;p&gt;But that won't work since &lt;em&gt;Dovecot&lt;/em&gt; &lt;em&gt;Sieve&lt;/em&gt; implementation does not support &quot;variables&quot;. Well, since I'm not ready to list all the lists I'm subscribed to, &lt;em&gt;Sieve&lt;/em&gt; is a no-go for now. I'll stick with &lt;em&gt;procmail&lt;/em&gt;.&lt;/p&gt;</description>
    
    
    
      </item>
    
</channel>
</rss>