<?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>Chronosbox &#187; PostgreSQL</title>
	<atom:link href="http://chronosbox.org/blog/categories/databases/postgresql/feed" rel="self" type="application/rss+xml" />
	<link>http://chronosbox.org/blog</link>
	<description>idéias e dicas de uma mente insana trabalhando com TI</description>
	<lastBuildDate>Sun, 30 Oct 2011 04:57:21 +0000</lastBuildDate>
	<language>pt</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Introdução ao PostgreSQL e HTML 5 (WTH!?)</title>
		<link>http://chronosbox.org/blog/postgres-slides-and-html5</link>
		<comments>http://chronosbox.org/blog/postgres-slides-and-html5#comments</comments>
		<pubDate>Thu, 02 Sep 2010 02:07:15 +0000</pubDate>
		<dc:creator>Felipe 'chronos' Prenholato</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">http://chronosbox.org/blog/?p=370</guid>
		<description><![CDATA[Nota: Olá meus caros leitores, apesar do ChronosBox ser um ótimo Blog, eu estou focando meus esforços em um blog conjunto com meu amigo Handrus Nogueira, portanto não deixem de visitar o Dev With Passion! Todos os posts do ChronosBox estarão no Dev With Passion, exceto por alguns comentários novos. Abraços! O MySQL é um [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Nota</strong>: Olá meus caros leitores, apesar do ChronosBox ser um ótimo Blog, eu estou focando meus esforços em um blog conjunto com meu amigo <a href="http://twitter.com/handrus">Handrus Nogueira</a>, portanto não deixem de visitar o <a href="http://devwithpassion.com">Dev With Passion</a>! Todos os posts do ChronosBox estarão no <a href="http://devwithpassion.com">Dev With Passion</a>, exceto por alguns comentários novos. Abraços!</em></p>
<div>
<p>O MySQL é um banco muito conhecido, e muitos sabem &#8216;usar&#8217;. O PostgreSQL já não é tão conhecido e muitos só já ouviram falar. Com este fato, a pouco tempo, comecei a desenvolver uma série de slides introdutórios ao PostgreSQL, tendo como alvo uma palestra na <a title="Lightcomm" href="http://www.lightcomm.com.br/" target="_blank">Lightcomm</a>, empresa onde trabalho.</p>
<p>Os slides em si, são bastante introdutórios, apenas ao nível básico, então se quem conhece bem PostgreSQL quiser dar uma revisada eu ficaria muito honrado <img src='http://chronosbox.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . A parte interessante destes slides para quem já conhece PostgreSQL e até mesmo para quem nunca mecheu, é que elas usam como &#8216;engine&#8217; os slides demonstrados no <a title="HTML5ROCKS" href="http://www.html5rocks.com/" target="_blank">html5rocks.com</a>, todo baseado em HTML5 / CSS3 / JS &#8230; Atualmente só testei ele no Chrome, e o resultado, na minha opnião foi muito bom.</p>
<p>Desenvolvi a palestra com muito conforto, pois é puro HTML / CSS, os slides ainda do <a title="HTML5ROCKS" href="http://www.html5rocks.com/" target="_blank">html5rocks.com</a> ainda vem com demos de uso de SVG, vídeo e áudio, o que pode realmente ser muito útil em palestra mais complexas (introdução ao Django por exemplo). Eu adotei esse método como o meu default para construção de slides, o código está no github <a href="http://github.com/chronossc/postgres_presentation/" target="_blank">[1]</a> e se quiser você pode fazer o download do pacote tgz / zip <a href="http://github.com/chronossc/postgres_presentation/downloads">[2]</a> <img src='http://chronosbox.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Eu aconselho a experimentar! Quem quiser pode contribuir melhorando a palestra, traduzindo para outras línguas ou só me apontando bugs <img src='http://chronosbox.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>[1]<a href="http://github.com/chronossc/postgres_presentation/">http://github.com/chronossc/postgres_presentation/</a></p>
<p>[2] <a href="http://github.com/chronossc/postgres_presentation/downloads">http://github.com/chronossc/postgres_presentation/downloads</a></p>
<p>See ya</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://chronosbox.org/blog/postgres-slides-and-html5/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Migrando bases de dados LATIN1 para UTF-8 com o PostgreSQL</title>
		<link>http://chronosbox.org/blog/moving-postgresql-databases-from-latim1-to-utf8</link>
		<comments>http://chronosbox.org/blog/moving-postgresql-databases-from-latim1-to-utf8#comments</comments>
		<pubDate>Sat, 06 Feb 2010 05:59:22 +0000</pubDate>
		<dc:creator>Felipe 'chronos' Prenholato</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Debian/Ubuntu]]></category>
		<category><![CDATA[Dicas]]></category>
		<category><![CDATA[Gentoo]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Servidores]]></category>
		<category><![CDATA[clusters]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[iso-8859-1]]></category>
		<category><![CDATA[latin1]]></category>
		<category><![CDATA[pgsql]]></category>
		<category><![CDATA[psql]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[utf-8]]></category>
		<category><![CDATA[utf8]]></category>

		<guid isPermaLink="false">http://chronosbox.org/blog/?p=264</guid>
		<description><![CDATA[Nos dias atuais é um padrão que todos os sites e servidores web rodem ao menos com UTF-8 como encoding default, entretanto pode-se encontrar casos onde ainda se roda LATIN1 ou até mesmo ASCII. O caso que tratamos hoje é de um servidor Debian, versão 5.0.3 (lenny), que usava o encode LATIN1 quando instalado e [...]]]></description>
			<content:encoded><![CDATA[<p>Nos dias atuais é um padrão que todos os sites e servidores web rodem ao menos com UTF-8 como encoding default, entretanto pode-se encontrar casos onde ainda se roda LATIN1 ou até mesmo ASCII.</p>
<p>O caso que tratamos hoje é de um servidor Debian, versão 5.0.3 (lenny), que usava o encode LATIN1 quando instalado e configurado o Postgresql, e não me deixava criar uma base de dados UTF-8, gerando o seguinte erro:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;color: #FCFFBA;">debian:~<span style="color: #666666; font-style: italic;"># su postgres -c 'createdb teste3  -E UTF-8'</span>
createdb: database creation failed: ERROR:  encoding UTF8 does not match server<span style="color: #ff0000;">'s locale en_US
DETAIL:  The server'</span>s LC_CTYPE setting requires encoding LATIN1.</pre></div></div>

<p><span id="more-264"></span></p>
<h3>Porque??</h3>
<p>O Postgresql, quando roda pela primeira vez, cria um cluster usando o encode default do sistema, e após feito isso, não se pode alterar o encode do cluster. O cluster default é o main, em todas as intalações que eu vi. </p>
<p>No caso deste servidor o encode default (locales) era en_US, que para o Debian significa en_US.ISO-8859-1. Por default o Debian Lenny, nas minhas instalações do zero, usa en_US.UTF-8, então o servidor provavelmente deveria ser um antigo Debian Etch atualizado.</p>
<h3>A solução</h3>
<p>Depois de alguma pesquisa, descobri que, após configurar o encode do servidor para usar UTF-8, poderia criar um novo cluster que suportasse tal encode.</p>
<p>Vamos ao passo a passo da solução do problema.</p>
<ul>
<li><strong>Criando um novo cluster:</strong> Para criar um novo cluster no Debian, é bastante simples:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;color: #FCFFBA;">debian:~<span style="color: #666666; font-style: italic;"># pg_createcluster 8.3 utf8_cluster</span>
Creating new cluster <span style="color: #7a0874; font-weight: bold;color: #CCC;">&#40;</span>configuration: <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>etc<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>postgresql<span style="color: #000000; font-weight: bold;color: #CCC;">/</span><span style="color: #000000;color: #DDD;">8.3</span><span style="color: #000000; font-weight: bold;color: #CCC;">/</span>utf8_cluster, data: <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>var<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>lib<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>postgresql<span style="color: #000000; font-weight: bold;color: #CCC;">/</span><span style="color: #000000;color: #DDD;">8.3</span><span style="color: #000000; font-weight: bold;color: #CCC;">/</span>utf8_cluster<span style="color: #7a0874; font-weight: bold;color: #CCC;">&#41;</span>...
Moving configuration <span style="color: #c20cb9; font-weight: bold;color: #577A61;">file</span> <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>var<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>lib<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>postgresql<span style="color: #000000; font-weight: bold;color: #CCC;">/</span><span style="color: #000000;color: #DDD;">8.3</span><span style="color: #000000; font-weight: bold;color: #CCC;">/</span>utf8_cluster<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>postgresql.conf to <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>etc<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>postgresql<span style="color: #000000; font-weight: bold;color: #CCC;">/</span><span style="color: #000000;color: #DDD;">8.3</span><span style="color: #000000; font-weight: bold;color: #CCC;">/</span>utf8_cluster...
Moving configuration <span style="color: #c20cb9; font-weight: bold;color: #577A61;">file</span> <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>var<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>lib<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>postgresql<span style="color: #000000; font-weight: bold;color: #CCC;">/</span><span style="color: #000000;color: #DDD;">8.3</span><span style="color: #000000; font-weight: bold;color: #CCC;">/</span>utf8_cluster<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>pg_hba.conf to <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>etc<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>postgresql<span style="color: #000000; font-weight: bold;color: #CCC;">/</span><span style="color: #000000;color: #DDD;">8.3</span><span style="color: #000000; font-weight: bold;color: #CCC;">/</span>utf8_cluster...
Moving configuration <span style="color: #c20cb9; font-weight: bold;color: #577A61;">file</span> <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>var<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>lib<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>postgresql<span style="color: #000000; font-weight: bold;color: #CCC;">/</span><span style="color: #000000;color: #DDD;">8.3</span><span style="color: #000000; font-weight: bold;color: #CCC;">/</span>utf8_cluster<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>pg_ident.conf to <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>etc<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>postgresql<span style="color: #000000; font-weight: bold;color: #CCC;">/</span><span style="color: #000000;color: #DDD;">8.3</span><span style="color: #000000; font-weight: bold;color: #CCC;">/</span>utf8_cluster...
Configuring postgresql.conf to use port <span style="color: #000000;color: #DDD;">5433</span>...
&nbsp;
debian:~<span style="color: #666666; font-style: italic;"># /etc/init.d/postgresql-8.3 restart</span></pre></div></div>

<p>O cluster vai rodar na primeira porta livre que achar depois da 5432, a não ser que você especifique. Para ter efeito, reinicia-se o Postgresql.</li>
<li><strong>Criando o usuário:</strong> Agora crie o usuário da base de dados, recomendo o mesmo nome e senha além de editar sua autenticação para trust no pg_hba.conf do seu cluster:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;color: #FCFFBA;">debian:~<span style="color: #666666; font-style: italic;"># su postgres -c &quot;createuser -P pyuser -p 5433&quot;</span>
Enter password <span style="color: #000000; font-weight: bold;color: #B83A24;">for</span> new role:
Enter it again:
Shall the new role be a superuser? <span style="color: #7a0874; font-weight: bold;color: #CCC;">&#40;</span>y<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>n<span style="color: #7a0874; font-weight: bold;color: #CCC;">&#41;</span> n
Shall the new role be allowed to create databases? <span style="color: #7a0874; font-weight: bold;color: #CCC;">&#40;</span>y<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>n<span style="color: #7a0874; font-weight: bold;color: #CCC;">&#41;</span> n
Shall the new role be allowed to create <span style="color: #c20cb9; font-weight: bold;color: #577A61;">more</span> new roles? <span style="color: #7a0874; font-weight: bold;color: #CCC;">&#40;</span>y<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>n<span style="color: #7a0874; font-weight: bold;color: #CCC;">&#41;</span> n</pre></div></div>

</li>
<li><strong>Migrando as bases:</strong> Agora você deve migrar as bases de dados. Primeiro crie ela e depois faça um dump seguido de um psql, direto na linha de comando. Siga o exemplo:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;color: #FCFFBA;">debian:~<span style="color: #666666; font-style: italic;"># su postgres -c &quot;createdb teste3 -e -p 5433 -O pyuser&quot;</span>
CREATE DATABASE teste3 OWNER pyuser;</pre></div></div>

<p>Agora liste a base de dados:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;color: #FCFFBA;">debian:~<span style="color: #666666; font-style: italic;"># su postgres -c &quot;psql -l -p 5433&quot;</span>
        List of databases
   Name    <span style="color: #000000; font-weight: bold;color: #CCC;">|</span>  Owner   <span style="color: #000000; font-weight: bold;color: #CCC;">|</span> Encoding
-----------+----------+----------
 postgres  <span style="color: #000000; font-weight: bold;color: #CCC;">|</span> postgres <span style="color: #000000; font-weight: bold;color: #CCC;">|</span> UTF8
 template0 <span style="color: #000000; font-weight: bold;color: #CCC;">|</span> postgres <span style="color: #000000; font-weight: bold;color: #CCC;">|</span> UTF8
 template1 <span style="color: #000000; font-weight: bold;color: #CCC;">|</span> postgres <span style="color: #000000; font-weight: bold;color: #CCC;">|</span> UTF8	
 teste3    <span style="color: #000000; font-weight: bold;color: #CCC;">|</span> pyuser   <span style="color: #000000; font-weight: bold;color: #CCC;">|</span> UTF8
<span style="color: #7a0874; font-weight: bold;color: #CCC;">&#40;</span><span style="color: #000000;color: #DDD;">4</span> rows<span style="color: #7a0874; font-weight: bold;color: #CCC;">&#41;</span></pre></div></div>

<p>Após criar a base de dados, então faremos a população dela, atenção quanto as portas:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;color: #FCFFBA;">debian:~<span style="color: #666666; font-style: italic;"># pg_dump -U pyuser teste3 | psql -U pyuser -p 5433 teste3</span></pre></div></div>

</li>
<li><strong>Configurando sua aplicação:</strong> Esta é a parte mais simples, apenas altere a porta da sua aplicação para a porta do novo cluster.</li>
</ul>
<p>Repita os passos da criação da base de dados para cada base que precisa ser movida, e pronto, tudo funcionando agora com suporte a UTF-8.</p>
]]></content:encoded>
			<wfw:commentRss>http://chronosbox.org/blog/moving-postgresql-databases-from-latim1-to-utf8/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

