Пользователи PostgreSQL

Содержание
Введение
Список пользователей
Создать пользователя (role)
Добавить пользователю прав (или роли атрибутов)
Изменить пароль
Похожие статьи

Введение

Пользователи

Получить список пользователей

postgres=# \du

List of roles Role name | Attributes | Member of -----------+------------------------------------------------+----------- postgres | Superuser, Create role, Create DB, Replication | {}

Создать пользователя

Чтобы создать пользователя выполните

postgres=# CREATE USER user01 WITH PASSWORD 'pwd01';

CREATE ROLE

Проверка

postgres=# \du

List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------+----------- postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {} user01 | | {}

Добавить пользователю прав

Правильнее сказать добавить роли атрибутов, так как в таблице пользователей они выглядят так

\du

List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------+----------- andrei | | {} postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

Как видите, у пользователя (роли) andrei никаких атрибутов нет. Добавим командой

postgres=# ALTER ROLE andrei WITH SUPERUSER CREATEDB CREATEROLE REPLICATION BYPASSRLS;

ALTER ROLE

Проверка

postgres=# \du

List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------+----------- andrei | Superuser, Create role, Create DB, Replication, Bypass RLS | {} postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

Изменить пароль

Чтобы изменить пароль пользователя выполните

sudo -u postgres psql -c "alter user ИМЯ_ПОЛЬЗОВАТЕЛЯ with encrypted password НОВЫЙ_ПАРОЛЬ"

Если вы вызываете команду из Python

f"sudo -u postgres psql -c \"alter user {dbuser} with encrypted password '{dbpass}'\"

Article author: Andrei Olegovich

Похожие статьи
PostgreSQL
Основы
Установка
postgresql.conf: Конфигурационный файл
Таблицы
Пользователи
SELECT
WHERE
bash скрипты для Postgres
Репликация master slave
Write Ahead Log
recovery.conf
pg_hba.conf
Help
Ошибки
EnterpriseDB

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: