postgreSQL
신입 DBA의 DBMS찍먹기행
psql : localhost로 DB는 사용자이름과 같은 DB
--options--
-U username
-h host
-p port
-d target_database
PGPASSWORD='password'
------------
ex) PGPASSWORD='password' psql -U dba -h 10.1.2.3 -p 1234 -d testdb
PostgreSQL을 설치하고 많은 DB들을 create하게 된다.
접속 후 test2로 인스턴스를 변경하여 조회를 원한다면 DB를 나가고 -d test2 옵션으로 들어오는건 번거롭다
db접속 후 test2로 변경
db=# \c [dbname] [username]
위 예시 명령여(test1로 접속 -> test2로 instance변경)
test1=# \c test2
* \list, \l : 전체 DB Instance 조회
\d[ t | s | f | v | u ]
* \dt : db의 table조회
* \ds : sequence조회
* \df : function조회
* \dv : view조회
* \du : user조회(db에 권한있는 user뜸)
명령어 뒤에 +를 붙이면 더 자세한 정보가 조회됨.
information_schema
에 view,function 등 조회show grants for 'user'@'host';
로 권한 조회user_source type
에서 조회dba_users
등 조회할 수 있는 뷰가 많음* \d [table_name] : table의 칼럼정보 = desc [table_name];