Postgres шпаргалка

sudo su postgres
psql -U user comand

Список БД:

psql -U user -l

Подключиться к БД:

psql -U user -d dbname

Выполнить запрос:

$ psql -U user -d db
$ SELECT * FROM table;

Бэкап/Восстановление:

pg_dump -U user -F c -b -v -f "db.backup" db

pg_restore -h localhost -p 5432 -U service -d db -v "db.backup"

СОздание таблицы, назначение привелегий:

Change the user to postgres :

su - postgres

Create User for Postgres

$ createuser testuser

Create Database

$ createdb testdb

Acces the postgres Shell

psql ( enter the password for postgressql)

Provide the privileges to the postgres user

$ alter user testuser with encrypted password 'qwerty';
$ grant all privileges on database testdb to testuser;

Добавить привелегии на чтение и обновление для таблицы

GRANT SELECT, UPDATE ON table_name TO user;

Вывести список всех таблиц с привелегиями пользователей

\dp