Postgres Database


```typeREVOKE CONNECT ON DATABASE thedb FROM public;DROP DATABASE mms;CREATE DATABASE mms;OWNER =  role_name```

```typeCREATE DATABASE db_nameOWNER =  role_nameTEMPLATE = template			ENCODING = encoding			LC_COLLATE = collate			LC_CTYPE = ctypeTABLESPACE = tablespace_nameCONNECTION LIMIT = max_concurrent_connection```


### copy
- connection 있을때 안되서 [pg_dump](https://texonom.com/pgdump-2c85cd5d072149289b1df14b3db66687) 이용이 편함
```typeSELECT pid, usename, client_addr FROM pg_stat_activity WHERE datname ='';SELECT pg_terminate_backend (pid)FROM pg_stat_activityWHERE datname = '';CREATE DATABASE mms_test WITH TEMPLATE mms;```

### Drop
connect to that db
```typeSELECT pid, pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = current_database() AND pid <> pg_backend_pid();```


> [Postgresql - unable to drop database because of some auto connections to DB](https://stackoverflow.com/questions/17449420/postgresql-unable-to-drop-database-because-of-some-auto-connections-to-db)

> [PostgreSQL Copy Database Made Easy](https://www.postgresqltutorial.com/postgresql-copy-database/)

> [PostgreSQL CREATE DATABASE with Example](https://www.guru99.com/postgresql-create-database.html)

> [PostgreSQL Copy Database Made Easy](https://www.postgresqltutorial.com/postgresql-copy-database/)





