-
TIL.97 PostgreSQL 기본 명령어TIL/PostgreSQL 2021. 1. 13. 19:40728x90
PostgreSQL의 기본명령어를 알아보자.
- PostgreSQL shell 진입
psql db_name -U user_name
- DB 목록 조회(show databases)
\list or \l
- 테이블 목록 조회(show tables)
\dt
- DB 생성
create database db_name
Database 소유하는 user 지정
create database db_name with owner=user_name
- DB 명 변경
alter database db_name rename to db_name2
소유하는 user 지정 변경
alter database db_name owner 변경user_name
-현재 존재하는 SCHEMA 조회
\dn
- Schema 생성
1.CREATE SCHEMA ‘schemaname’을 입력하여 SCHEMA를 생성합니다.
(Name 입력하지 않을 경우 에러발생)
create schema schema_name;
2. Authorization 옵션으로 스키마를 소유한 유저이름 지정 가능
이를 생략할 경우 접속되어 있던 USER가 default값으로 저장되고 SUPERUSER만이 다른 USER가 소유한 SCHEMA를 만들 수 있음
create schema test_s authorization codermun;
3. 특정이름의 schema가 없는 경우 해당 schema를 생성
create schema if not exists schema_name;
4. 특정 유저가 소유한 schema가 없을 경우 schema를 생성
(이름 지정하지 않는 경우 user 이름의 schema 생성)
(이름지정 불가?)
create schema if not exists authorization user_name;
5. schema 삭제
drop schema schema_name;
출처 : www.gurubee.net/postgresql/basic
728x90'TIL > PostgreSQL' 카테고리의 다른 글
TIL.96 PostgreSQL 튜토리얼 (0) 2021.01.12