postgres / 포스트그레스 / db command / table 보는 법 / db 보는 법 / 모든 데이터베이스 / 테이블 보는 법 / sql 명령어 / beaver 에서 보는 법
postgresql meta command
postgresql 에선 mysql 에서 show tables, show databases 같은 명령어를 직접 제공하지 않는다. meta command 라는 것을 제공해서, 비슷한 기능을 제공한다. 몇몇 meta command 는 실질적으로 특정 sql 로 변환돼서 postgresql 에서 실행된다.
예를 들면 아래처럼 말이다. (-E option 이 sql 을 보여주는 옵션이다.)
cd d:\a\apps\PostgreSQL\13\bin
psql -E -h localhost -U postgres
postgres=# \l
********** 쿼리 **********
SELECT d.datname as "Name",
pg_catalog.pg_get_userbyid(d.datdba) as "Owner",
pg_catalog.pg_encoding_to_char(d.encoding) as "Encoding",
d.datcollate as "Collate",
d.datctype as "Ctype",
pg_catalog.array_to_string(d.datacl, E'\n') AS "Access privileges"
FROM pg_catalog.pg_database d
ORDER BY 1;
**************************
데이터베이스 목록
이름 | 소유주 | 인코딩 | Collate | Ctype | 액세스 권한
-------------+----------+--------+------------------+------------------+-----------------------
postgres | postgres | UTF8 | Korean_Korea.949 | Korean_Korea.949 |
mytest | postgres | UTF8 | Korean_Korea.949 | Korean_Korea.949 |
mytest-dev | postgres | UTF8 | Korean_Korea.949 | Korean_Korea.949 |
mytest-dog | postgres | UTF8 | Korean_Korea.949 | Korean_Korea.949 |
template0 | postgres | UTF8 | Korean_Korea.949 | Korean_Korea.949 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | Korean_Korea.949 | Korean_Korea.949 | =c/postgres +
| | | | | postgres=CTc/postgres
testdb | postgres | UTF8 | Korean_Korea.949 | Korean_Korea.949 |
twin-cat | postgres | UTF8 | Korean_Korea.949 | Korean_Korea.949 |
userhabitdb | postgres | UTF8 | Korean_Korea.949 | Korean_Korea.949 |
(9개 행)
다른 meta commnad 들
\c[데이터베이스 이름] - 지정된 데이터베이스에 연결한다.\l- 모든 데이터베이스를 나열한다.\d- 테이블, 뷰 및 시퀀스를 표시한다.\dt- 테이블만 표시한다.\dv- 뷰를 표시한다.\dm- 머티리얼라이즈드 뷰를 표시한다.\di- 인덱스를 표시한다.\dn- 스키마를 표시한다.\dT- 데이터 타입을 표시한다.- 기타 등등
\sv[뷰 이름] - 뷰의 정의를 표시한다.\x- 확장된 디스플레이를 전환한다. 많은 열이 있는 테이블에 유용한다.- on/off로 토글하거나 auto로 설정할 수 있습니다.
\set- 모든 내부 변수를 나열한다.\set[이름] [값] - 새로운 내부 변수를 설정한다.\unset[이름] - 내부 변수를 삭제한다.
\cd- psql이 작업하는 디렉터리를 변경한다.![명령] - 셸 명령을 실행한다.- 예:
! ls또는! pwd
- 예:
\timing- 쿼리의 실행 시간 측정을 전환한다.\echo[메시지] - 메시지를 콘솔에 출력한다.\copy- 파일로 복사한다.\i[파일명] - 파일에서 명령을 실행한다.\o[파일] - 콘솔 대신 파일로 출력을 작성한다.\q- psql을 종료한다.
댓글 없음:
댓글 쓰기