[root@PRD-POSTGRES-P01 ~]# sudo su postgres bash-5.1$ psql psql (17.6) Saisissez « help » pour l'aide.
postgres=# CREATE DATABASE awx;
CREATE DATABASE
postgres=# \l
Liste des bases de données
Nom | Propriétaire | Encodage | Fournisseur de locale | Collationnement | Type caract. | Locale | Règles ICU : | Droits d'accès
-----------+--------------+----------+-----------------------+-----------------+--------------+--------+--------------+-----------------------
awx | postgres | UTF8 | libc | fr_FR.UTF-8 | fr_FR.UTF-8 | | |
postgres | postgres | UTF8 | libc | fr_FR.UTF-8 | fr_FR.UTF-8 | | |
registry | admin | UTF8 | libc | fr_FR.UTF-8 | fr_FR.UTF-8 | | | =Tc/admin +
| | | | | | | | admin=CTc/admin
template0 | postgres | UTF8 | libc | fr_FR.UTF-8 | fr_FR.UTF-8 | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | libc | fr_FR.UTF-8 | fr_FR.UTF-8 | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
(5 lignes)
postgres=# \conninfo
Vous êtes connecté à la base de données « postgres » en tant qu'utilisateur « postgres » via le socket dans « /run/postgresql » via le port « 5432 ».
postgres=# CREATE USER user_awx WITH PASSWORD 'XXXXX';
CREATE ROLE
postgres=# GRANT ALL PRIVILEGES ON DATABASE awx TO user_awx;
GRANT
postgres=# \c awx
Vous êtes maintenant connecté à la base de données « awx » en tant qu'utilisateur « postgres ».
awx=# -- Donne les droits sur le schéma public
GRANT ALL ON SCHEMA public TO user_awx;
-- Donne les droits sur toutes les tables existantes
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO user_awx;
-- Donne les droits sur toutes les séquences existantes
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO user_awx;
-- Applique les droits par défaut pour les objets futurs
ALTER DEFAULT PRIVILEGES IN SCHEMA public
GRANT ALL ON TABLES TO user_awx;
ALTER DEFAULT PRIVILEGES IN SCHEMA public
GRANT ALL ON SEQUENCES TO user_awx;
GRANT
GRANT
GRANT
ALTER DEFAULT PRIVILEGES
ALTER DEFAULT PRIVILEGES
awx=# \q
bash-5.1$ exit
exit
[root@PRD-POSTGRES-P01 ~]# history | grep pg_hba.conf
45 vi /var/lib/pgsql/17/data/pg_hba.conf
57 history | grep pg_hba.conf
[root@prd-k8s-m01 lab_cluste_postgress]# kubectl exe
c -it svc/postgresql-lab-rw -n test -- bash
Defaulted container "postgres" out of: postgres, bootstrap-controller (init)
postgres@postgresql-lab-1:/$ psql -U postgres
psql (17.0 (Debian 17.0-1.pgdg110+1))
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Locale Provider | Collate | Ctype | Locale | ICU Rules | Access privileges
-----------+----------+----------+-----------------+---------+-------+--------+-----------+-----------------------
appdb | appuser | UTF8 | libc | C | C | | |
postgres | postgres | UTF8 | libc | C | C | | |
template0 | postgres | UTF8 | libc | C | C | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | libc | C | C | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
(4 rows)
postgres=# \l
List of databases
Name | Owner | Encoding | Locale Provider | Collate | Ctype | Locale | ICU Rules | Access privileges
-----------+----------+----------+-----------------+---------+-------+--------+-----------+-----------------------
appdb | appuser | UTF8 | libc | C | C | | |
postgres | postgres | UTF8 | libc | C | C | | |
template0 | postgres | UTF8 | libc | C | C | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | libc | C | C | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
(4 rows)
postgres=# \c labdb
connection to server on socket "/controller/run/.s.PGSQL.5432" failed: FATAL: database "labdb" does not exist
Previous connection kept
postgres=# \c appdb
You are now connected to database "appdb" as user "postgres".
appdb=# CREATE TABLE sauvegarde_test (
id SERIAL PRIMARY KEY,
nom VARCHAR(100),
date_creation TIMESTAMP DEFAULT NOW()
);
INSERT INTO sauvegarde_test (nom) VALUES ('Sauvegarde test 1'), ('Sauvegarde test 2');
SELECT * FROM sauvegarde_test;
CREATE TABLE
INSERT 0 2
id | nom | date_creation
----+-------------------+----------------------------
1 | Sauvegarde test 1 | 2025-10-29 15:26:47.567904
2 | Sauvegarde test 2 | 2025-10-29 15:26:47.567904
(2 rows)
appdb=# INSERT INTO sauvegarde_test (nom) VALUES ('Sauvegarde test 4'), ('Sauvegarde test 3');
INSERT 0 2
appdb=# CREATE TABLE sauvegarde_test (
id SERIAL PRIMARY KEY,
nom VARCHAR(100),
date_creation TIMESTAMP DEFAULT NOW()
);
INSERT INTO sauvegarde_test (nom) VALUES ('Sauvegarde test 1'), ('Sauvegarde test 2');
SELECT * FROM sauvegarde_test;^C
appdb=# SELECT * FROM sauvegarde_test;
id | nom | date_creation
----+-------------------+----------------------------
1 | Sauvegarde test 1 | 2025-10-29 15:26:47.567904
2 | Sauvegarde test 2 | 2025-10-29 15:26:47.567904
3 | Sauvegarde test 4 | 2025-10-29 15:27:06.816419
4 | Sauvegarde test 3 | 2025-10-29 15:27:06.816419
(4 rows)
appdb=# ex