AU départ la base est dans cet état:
postgres=# drop database bench;
DROP DATABASE
postgres=# drop role bench;
DROP ROLE
postgres=# l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
———–+———-+———-+————-+————-+———————–
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
test | postgres | UTF8 | fr_FR.UTF-8 | fr_FR.UTF-8 |
(4 rows)
postgres=# du
List of roles
Role name | Attributes | Member of
———–+————————————————————+———–
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
1 – Commencer par créer un nouvel utilisateur puis une nouvelle base :
[postgres@localhost ~]$ createuser -p 5432 -d bench
[postgres@localhost ~]$ createdb bench -U bench
[postgres@localhost ~]$ psql -U postgres
psql (9.5.1)
Type « help » for help.
postgres=# l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
———–+———-+———-+————-+————-+———————–
bench | bench | 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
test | postgres | UTF8 | fr_FR.UTF-8 | fr_FR.UTF-8 |
(5 rows)
postgres=# du
List of roles
Role name | Attributes | Member of
———–+————————————————————+———–
bench | Create DB | {}
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
2- Ensuite vous pouvez utiliser (enfin!) l’utilitaire pgbench pour alimenter votre base de données :
[postgres@localhost ~]$ pgbench -i -s 10 -U bench bench
NOTICE: table « pgbench_history » does not exist, skipping
NOTICE: table « pgbench_tellers » does not exist, skipping
NOTICE: table « pgbench_accounts » does not exist, skipping
NOTICE: table « pgbench_branches » does not exist, skipping
creating tables…
100000 of 1000000 tuples (10%) done (elapsed 0.20 s, remaining 1.81 s)
200000 of 1000000 tuples (20%) done (elapsed 0.37 s, remaining 1.48 s)
300000 of 1000000 tuples (30%) done (elapsed 0.55 s, remaining 1.29 s)
400000 of 1000000 tuples (40%) done (elapsed 0.81 s, remaining 1.22 s)
500000 of 1000000 tuples (50%) done (elapsed 1.01 s, remaining 1.01 s)
600000 of 1000000 tuples (60%) done (elapsed 1.39 s, remaining 0.93 s)
700000 of 1000000 tuples (70%) done (elapsed 1.82 s, remaining 0.78 s)
800000 of 1000000 tuples (80%) done (elapsed 2.06 s, remaining 0.52 s)
900000 of 1000000 tuples (90%) done (elapsed 2.29 s, remaining 0.25 s)
1000000 of 1000000 tuples (100%) done (elapsed 2.53 s, remaining 0.00 s)
vacuum…
set primary keys…
done.
-i : permet d’initialiser
-s : permet de donner une valeur factorielle , dans mon exemple 10 , par défaut 1
-U : nom du role autorisé à se connecter à la base de données bench
Laisser un commentaire