Le SGBDR * PostgreSQL
Installation de PostgreSQL
PostgreSQL est utilisable en table de commande, il est possible d' utiliser l'interface graphique PhppgAdmin.
Le système d'exploitation GNU/Linux Knoppix7 que j'utilise, basé sur la version stable de Debian (wheezy), a la particularité de ne pas demander de mot de passe pour passer en super-utilisateur. Sur Ubuntu, je pense qu'il vaut mieux passer directement à la version postgresql 9.3. Quant à moi, je laisse Aptitude décider
knoppix@Microknoppix:~$su
root@Microknoppix:/home/knoppix#aptitude install postgresql postgresql-client phppgadmin
Les paquets suivants seront installés :
- javascript-common
- libjs-jquery
- libpq5
- logrotate
- php5-pgsql
- phppgadmin
- postgresql
- postgresql-9.1
- postgresql-client
- postgresql-client-9.1
- postgresql-client-common
- postgresql-common
- postgresql-doc
- postgresql-doc-9.1
- wwwconfig-common
Si après avoir téléchargé ces outils, vous fermez votre ordinateur, n'oubliez pas à la prochaine session de redémarrer le moteur de base de données pour la configuration du SGBDR PostgreSQL
knoppix@Microknoppix:~$ sudo /etc/init.d/postgresql start
[ ok ] Starting PostgreSQL 9.1 database server: main.
knoppix@Microknoppix:~$
Démarrer aussi le serveur Apache. Ce n'est pas utile pour l'instant, mais vous en aurez besoin plus tard.
knoppix@Microknoppix:~$ sudo /etc/init.d/apache2 start
[....] Starting web server: apache2apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
. ok
knoppix@Microknoppix:~$
Lire ses fichiers web sur localhost
Localhost-Apache-Linux
Configuration du SGBDR
Pour voir si les processus tournent:
knoppix@Microknoppix:~$su
root@Microknoppix:/home/knoppix#ps aux | grep postgres
postgres 3327 0.0 0.3 48944 7064 ? S 20:40 0:00 /usr/lib/postgresql/9.1/bin/postgres -D /var/lib/postgresql/9.1/main -c config_file=/etc/postgresql/9.1/main/postgresql.conf postgres 3330 0.0 0.0 48928 1764 ? Ss 20:40 0:00 postgres: writer process postgres 3331 0.0 0.0 48928 1520 ? Ss 20:40 0:00 postgres: wal writer process postgres 3332 0.0 0.1 49480 2680 ? Ss 20:40 0:00 postgres: autovacuum launcher process postgres 3333 0.0 0.0 19176 1620 ? Ss 20:40 0:00 postgres: stats collector process root@Microknoppix:/home/knoppix#
Pour voir les ports à l'écoute:
knoppix@Microknoppix:~$su
root@Microknoppix:/home/knoppix#netstat -tupwan | grep 5432
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 5184/postgres tcp6 0 0 ::1:5432 :::* LISTEN 5184/postgres
Se connecter à l'aide de l'utilisateur créé par défaut par l'installation du service. L'utilisateur (compte système unix) créé par défaut se nomme postgres.
root@Microknoppix:/home/knoppix# cat /etc/passwd | grep postgres
postgres:x:120:129:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash
Créer la base de données, je la nommerai dbdemo
:
knoppix@Microknoppix:~$su
root@Microknoppix:/home/knoppix#su postgres
postgres@Microknoppix:/home/knoppix$createdb dbdemo
CREATE DATABASE postgres@Microknoppix:/home/knoppix$
Créer l'utilisateur que je nommerai jack
root@Microknoppix:/home/knoppix#su postgres
postgres@Microknoppix:/home/knoppix$createuser jack
Le nouveau rôle est-il super-utilisateur ? (o/n)o
CREATE ROLE postgres@Microknoppix:/home/knoppix$
A cette question vous pouvez aussi répondre n
. Être super-utilisateur n'est pas utile pour localhost. D'ailleurs, si vous avez un espace web en accès gratuit chez free.fr, vous remarquerez que vous ne pouvez pas créer une autre base de données (ce qui n'empêche pas de pouvoir créer des tables)
knoppix@Microknoppix:~$su
root@Microknoppix:/home/knoppix#su postgres
postgres@Microknoppix:/home/knoppix$psql dbdemo
psql (9.1.11) Saisissez « help » pour l'aide. dbdemo=#
Créer une table que je nommerai tabledemo
dbdemo=#create table tabledemo (id numeric(2), lib char(30));
CREATE TABLE dbdemo=#grant SELECT on tabledemo to jack;
GRANT dbdemo=#insert into tabledemo values (1, 'aaa');
INSERT 0 1 dbdemo=#insert into tabledemo values (2, 'aab');
INSERT 0 1 dbdemo=#insert into tabledemo values (3, 'aac');
INSERT 0 1 dbdemo=#SELECT * from tabledemo;
id | lib ----+-------------------------------- 1 | aaa 2 | aab 3 | aac (3 lignes) dbdemo=#ALTER user jack password 'jack';
ALTER ROLE dbdemo=#
Dès à présent je peux me rendre sur l'interface graphique PhppgAdmin et entrer utilisateur: jack et mot de passe: jack. (capture-2) paragraphe ci-dessous
Vous pouvez aussi lister les bases de données en table de commande:
knoppix@Microknoppix:~$su postgres
postgres@Microknoppix:/home/knoppix$psql -l
qui me donne:
Nom | Propriétaire | Encodage | Collationnement | Type caract. | Droits d'accès -----------+--------------+----------+-----------------+--------------+----------------------- dbdemo | postgres | UTF8 | fr_FR.UTF-8 | fr_FR.UTF-8 | postgres | postgres | UTF8 | fr_FR.UTF-8 | fr_FR.UTF-8 | template0 | postgres | UTF8 | fr_FR.UTF-8 | fr_FR.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | fr_FR.UTF-8 | fr_FR.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres (4 lignes)
phpPgAdmin
Interface de PostgreSQL (capture-1)
Cliquer pour arriver à:Interface de connection (capture-2)
Bases de données (capture-3)
J' ai fait un résumé succint sur PostgreSQL, englobant phpPgAdmin, son interface graphique. Pour plus d' information allez sur le wiki de debian, hélas toujours en anglais, en italien ou en russe et d' une version précédente:
debian wiki PostgreSQL
Documentation PostgreSQL (en anglais)
Créer et gérer une base de données PostgreSQL