lundi 25 janvier 2016

Installation de PostgreSQL 9.4 sur Ubuntu



Avant toute installation, mettre à jour le "apt-get repository" :

sudo apt-get update

Installation de PostgreSQL 9.4 sur Ubuntu

$ sudo apt-get install postgresql postgresql-contrib

Voir les processus actifs de PostgreSQL :
$ ps -f -u postgres
6 processus actifs ( "postgres" est le user Linux )

Autoriser les connexions en "remote"

Dans le répertoire "/etc/postgresql/9.4/main

1) Modifier le fichier "postgresql.conf"
$ sudo vi postgresql.conf

listen_addresses = '*'

( le port par défaut est 5432 )

2) Modifier le fichier "pg_hba.conf"
$ sudo vi pg_hba.conf

# IPv4 local connections
host  all  all  (remote_ip)/32   md5
(autorise la connexion pour tous les utilisateurs pour toutes les bases à partir
du poste ayant l'adresse ip indiquée )

An IP address range is specified using standard numeric notation for the range's starting address, 
then a slash (/) and a CIDR mask length. The mask length indicates the number of high-order bits of the client IP address that must match. Bits to the right of this should be zero in the given IP address. There must not be any white space between the IP address, the /, and the CIDR mask length.

Typical examples of an IPv4 address range specified this way are :
 172.20.143.89/32   for a single host
 172.20.143.0/24    for a small network
 10.6.0.0/16      for a larger one

Restart Linux.

Création d'un utilisateur

Lancement de l'interpéteur SQL ( "psql" ) :
$ sudo -u postgres psql
Exemple : création d'un utilisateur "foo" avec mot de passe "foo" :
postgres=# create user foo createdb createuser password 'foo' ;
CREATE ROLE 
postgres=# 

Liste des utilisateurs existants :
postgres=# select * from pg_catalog.pg_user ;

postgres=# \q    (quit)

Création d'une base de données pour un utilisateur

sudo -u postgres psql
postgres=# create database foodb with encoding='UTF8' owner=foo connection limit=-1;
CREATE DATABASE
postgres=# 

Liste des bases de données existantss :
postgres=# \list
ou 
postgres=# select * from pg_database ;

Connexion JDBC à distance

Driver class : "org.postgresql.Driver"

URL : jdbc:postgresql://host:port/database
Exemple : 
   - URL : "jdbc:postgresql://10.226.159.81:5432/foodb"
   - User : "foo"
   - Password : "foo"

Aucun commentaire:

Enregistrer un commentaire