Creating a PostgreSQL database
es:Creación de una base de datos PostgreSQL
fr:Créer une base de donnés PostgreSQL
This article has been created by an automatic translation software. You can view the article source here.
Introduction
This article deals with the creation of a database and its owner user.
Connecting to PostgreSQL
We go under the user postgres user, then we connect to PostgreSQL :
# su - postgres
postgres@vm-postgres:~$ psql
psql (9.1.24lts2)
Saisissez « help » pour l aide.
postgres=#
Creation of the database
We create the database test :
postgres=# CREATE DATABASE test;
CREATE DATABASE
Let's check that it is created:
postgres=# \l
Liste des bases de données
Nom | Propriétaire | Encodage | Collationnement | Type caract. | Droits d accès
-----------+--------------+----------+-----------------+--------------+-----------------------
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 lignes)
As we can see, the owner of the database test is the user postgres, we will change this later.
Creating a user
Still connected to PostgreSQL, we create a user test_user with a password password_ikoula :
postgres=# CREATE USER test_user WITH PASSWORD 'password_ikoula';
CREATE ROLE
Change of ownership of a database
Still connected to PostgreSQL, we change the database owner test database for our user test_user :
postgres=# ALTER DATABASE test OWNER TO test_user;
ALTER DATABASE
We check that the owner is modified for test_user :
postgres=# \l
Liste des bases de données
Nom | Propriétaire | Encodage | Collationnement | Type caract. | Droits d accès
-----------+--------------+----------+-----------------+--------------+-----------------------
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 | test_user | UTF8 | fr_FR.UTF-8 | fr_FR.UTF-8 |
(4 lignes)
Cet article vous a semblé utile ?
Enable comment auto-refresher