---
# System prepended metadata

title: Postgresql NOTES

---

Postgresql NOTES
===

- DROP USER username;
- DROP DATABASE namedb;
- CREATE USER user WITH PASSWORD 'userpw';
- CREATE DATABASE grcdb OWNER grc ENCODING 'UTF8';
- CREATE DATABASE grcdb OWNER grc WITH ENCODING 'UTF8' LC_COLLATE='pt_BR.UTF8' LC_CTYPE='pt_BR.UTF8';
- CREATE DATABASE grcdbprod OWNER postgres ENCODING 'UTF8' LC_COLLATE 'pt_BR.UTF8';
- CREATE DATABASE grcdbprod ENCODING 'UTF8' LC_COLLATE 'pt_BR.UTF8' LC_CTYPE 'pt_BR.UTF8' template template0;

- Acesse psql prompt
docker exec -it postgres psql -U postgres
- Make a dump
docker exec <postgres_container_name> pg_dump -U postgres <database_name> > backup.sql
- E.G.
docker exec docker-composer_postgres-db_1 pg_dump -U teste teste > backup.sql
- Make a restau
docker exec -i <postgres_container_name> psql -U postgres -d <database_name> < backup.sql
- E.G.
docker exec -i docker-composer_postgres-db_1 psql -U teste -d teste < Cloud_SQL_Export_2020-02-22.dump

### PG_DUMP
`pg_dump -h localhost -U postgres -W -d grcdb > ~/Cloud_SQL_Export_2020-05-03.dump`

# Referências:
Locale pt_br
https://www.vivaolinux.com.br/dica/Encode-LATIN1-no-PostgreSQL
https://www.linhadecomando.com/so-linux/linux-instalando-o-locale-pt_br-utf-8 
