Skip to content

Instantly share code, notes, and snippets.

@infoslack
Last active August 29, 2015 14:21
Show Gist options
  • Save infoslack/5ecb0451a85ce31f1302 to your computer and use it in GitHub Desktop.
Save infoslack/5ecb0451a85ce31f1302 to your computer and use it in GitHub Desktop.
Postgres - trabalhando com users

Criar super usuário:

$ sudo -u postgres createuser --superuser $USER

Adicionar extensões:

$ sudo -u postgres psql template1 -c 'create extension if not exists "hstore"'

Criar usuário com senha e dar acesso a um banco:

$ psql -d template1 -U postgres

template1=# CREATE USER demo_user WITH PASSWORD 'demo_pass';
template1=# CREATE DATABASE demo_db;
template1=# GRANT ALL PRIVILEGES ON DATABASE demo_db to demo_user;

Ativar peer connection:

$ echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.3/main/pg_hba.conf
  • Não esqueça de dar restart no serviço.

  • Sobre o uso de Roles veja aqui

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment