Instalando a versão PostGreSQL-8.2.23 no Ubuntu 10.04 LTS
Autor: Marcos G.A | Publicado: 2011-12-19T05:52:00-08:00



Instalação


            A grande jogada nesta instalação, é instalar uma versão de postgresql, da qual, os repositórios do ubuntu não possue. Para a versão de linux que vamos trabalhar, a 10.04 LTS, o postgresql liberado é o 8.2.7 e vamos atualizar para último da categoria 8.2.23



1) Baixar ou enviar os fontes do postgres para máquina a ser instalado;

Repositório fpt oficial para download

ftp://ftp.postgresql.org/pub/source






Comando - Para descompactar
$ sudo -s
$ cd /usr/src
$ tar jxvf /home/trabin/postgresql-8.2.23.tar.bz2Obs: Mova a pasta criada na descompactação para o seguinte caminho /usr/src/



2) Para que possamos criar um clusters em LATIN1 é preciso ajustar a language do sistema operacional.Comando$sudo apt-get install language-support-pt

$sudo echo "pt_BR.ISO-8859-1 ISO-8859-1" &gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/var/lib/locales/supported.d/pt$sudo localedef -i pt_BR -c -f ISO-8859-1 pt_BRPor fim, edite o arquivo /etc/default/locale e altere

De:

LANG="pt_BR.UTF-8"

LANGUAGE="pt_BR:pt:en"

Para:

LANG="pt_BR.ISO-8859-1"

LANGUAGE="pt_BR:pt:en"

3) Instalação do PostgreSQL 8.2 dos repositórios da versão "hardy"
Comando:
$ sudo -s
$ echo "deb http://archive.ubuntu.com/ubuntu hardy main universe" &gt; /etc/apt/sources.list.d/ubuntu-8.04.list
$ apt-get update -o APT::Cache-Limit="50331648"
$ apt-get install postgresql-8.2
$ rm /etc/apt/sources.list.d/ubuntu-8.04.list
$ apt-get update

b) Instalação Compilador + Libs necessárias para compilar o PG:
Comando:$ sudo apt-get install build-essential libreadline-dev zlib1g-dev flex bison libssl-dev vim


c) Compilação / Instalação do PostgreSQL 8.2 
Obs:  Verifique se você esta no seguinte caminho /usr/src/postgresql-8.2.23
Comando:
./configure
make
su
make install
adduser postgres
mkdir /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
/usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data &gt;logfile 2&gt;&amp;1 &amp; 

d) Incluindo a senha ao postgresComando
sudo su postgres -c psql postgres ALTER USER postgres WITH PASSWORD ‘sua senha’; 
\q;





e) Remover o cluster atual do 8.2 (Só na primeira)

$ sudo pg_dropcluster --stop 8.2 main




f) Verificar tamanho do bloco da partição onde será instalado o cluster

$ sudo blockdev --getbsz /dev/sda1

4096






g) Verificando que o tamanho do bloco da partição "/dev/sda1" é "4096" vamos customizar a compilação do PostgreSQL para que também utilize esse tamanho de bloco

$ sudo -s

$ cd /usr/src/postgresql-8.2.23

$ vim src/include/pg_config_manual.h &nbsp;&nbsp;(neste ponto iremos editar o arquivo)




Alterar o

#define BLCKSZ &nbsp;8192

para

#define BLCKSZ &nbsp;4096



(salvar e sair)


h) Compilar / Instalar o PostgreSQL dentro da infra-estrutura do Ubuntu/Debian

$ sudo -s

$ cd /usr/src/postgresql-8.2.23

$ ./configure '--prefix=/usr' '--includedir=/usr/include' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--sysconfdir=/etc' '--localstatedir=/var' '--libexecdir=/usr/lib/postgresql-8.2' '--srcdir=.' '--mandir=/usr/share/postgresql/8.2/man' '--with-docdir=/usr/share/doc/postgresql-doc-8.2' '--datadir=/usr/share/postgresql/8.2' '--bindir=/usr/lib/postgresql/8.2/bin' '--libdir=/usr/lib/postgresql/8.2/lib' '--includedir=/usr/include/postgresql/' '--enable-integer-datetimes' '--with-openssl'

$ make

$ make install

$ exit




i) Depois de compilado e instalado agora vamos criar o novo Cluster

$ sudo pg_createcluster -e LATIN1 8.2 main

$ sudo /etc/init.d/postgresql-8.2 start




j) Neste ponto já temos o novo cluster operacional, vamos verificar:

$ pg_lsclusters

Version Cluster &nbsp;&nbsp;Port Status Owner &nbsp;&nbsp;&nbsp;Data directory &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log file

8.2 &nbsp;&nbsp;&nbsp;&nbsp;main &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5432 online postgres /var/lib/postgresql/8.2/main &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/var/log/postgresql/postgresql-8.2-main.log

(Observe que o "Status" está "online")




l) Agora algumas configurações básicas no seu PostgreSQL:

$ sudo nano /etc/postgresql/8.2/main/postgresql.conf

listen_addresses = '*'

ssl = false

log_line_prefix = '%t [%p]: [%l-1] user=%u,db=%d '

autovacuum = off



$ sudo nano /etc/postgresql/8.2/main/pg_hba.conf

# Database administrative login by UNIX sockets

#local &nbsp;&nbsp;all &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;postgres &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ident sameuser



# TYPE &nbsp;DATABASE &nbsp;&nbsp;&nbsp;USER &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CIDR-ADDRESS &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;METHOD

# "local" is for Unix domain socket connections only

local &nbsp;&nbsp;all &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;all &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trust

# IPv4 local connections:

host &nbsp;&nbsp;&nbsp;all &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;all &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;127.0.0.1/32 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trust

# IPv6 local connections:

host &nbsp;&nbsp;&nbsp;all &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;all &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;::1/128 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trust



$ sudo /etc/init.d/postgresql-8.2 restart




m) Feito todas etapas agora temos o novo cluster com a versão 8.2.23 compilada pronta para uso



$ psql -U postgres -l

 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List of databases

 &nbsp;Name &nbsp;&nbsp;&nbsp;| &nbsp;Owner &nbsp;&nbsp;| Encoding

-----------+----------+----------

postgres &nbsp;| postgres | LATIN1

template0 | postgres | LATIN1

template1 | postgres | LATIN1

(3 rows)



$ psql -U postgres

Welcome to psql 8.2.23, the PostgreSQL interactive terminal.



Type: &nbsp;\copyright for distribution terms

 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\h for help with SQL commands

 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\? for help with psql commands

 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\g or terminate with semicolon to execute query

 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\q to quit



postgres=# select version();

 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;version &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

-------------------------------------------------------------------------------------------

PostgreSQL 8.2.23 on i686-pc-linux-gnu, compiled by GCC gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3

(1 row)



Este material é cópia alterada do documento postado no blog de um amigo de Porto Alegre.

Fonte: Fabrízio de Royes Mello