PostgreSQL

PostgreSQL

Subs.

Instalación

# yum instal postgresql-server
# service postgresql initdb
Initializing database:                                     [  OK  ]
# service postgresql start
Starting postgresql service:                               [  OK  ]
# su - postgres 
-bash-4.0$ psql -d template1
psql (8.4.4)
Type "help" for help.

template1=# SELECT version();
                                                    version                                                    
---------------------------------------------------------------------------------------------------------------
 PostgreSQL 8.4.4 on i386-redhat-linux-gnu, compiled by GCC gcc (GCC) 4.4.3 20100127 (Red Hat 4.4.3-4), 32-bit
(1 row)

template1=# 

Ejemplo de creación de BD

[root@movix ~]# su - postgres
-bash-4.1$  psql -d template1
psql (8.4.4)
Digite «help» para obtener ayuda.

template1=# 
template1=# create role pinsales with createdb login password 'secretazo';
CREATE ROLE
template1=# create database pinsales_development owner pinsales;
CREATE DATABASE
template1=# create database pinsales_test owner pinsales;
CREATE DATABASE
template1=# create database pinsales_production owner pinsales;
CREATE DATABASE

¿IPv6? Tip

Es posible que no pueda conectarse y no vea el error, el asunto es que psql soporta IPv6, en consecuencia debe configurar el control de acceso para IPv6, ejemplo:

pg_hba.conf

# "local" is for Unix domain socket connections only
local   all         all                               ident
# IPv4 local connections:
#host    all         all         127.0.0.1/32          ident
host    all         all         127.0.0.1/32     password
# IPv6 local connections:
host    all         all         ::1/128          password

Si no desea lidiar con IPv6, debe deshabilitar en su kernel.

Un caso fastidioso es "localhost" ya que usualmente en /etc/hosts tenemos algo como:

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 movix.fedora-ve.org
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6 movix.fedora-ve.org

Note que el nombre localhost tiene tanto ipv4 como ipv6 definida. Al usar psql el nombre localhost este decide intentar primero ipv6. Una opcion es usar localhost4 o simplemente comentar la línea respectiva a ipv6 de localhost. Si tiene deshabilitado el soporte ipv6 no tendrá este problema.