PostgreSQL 맛보기

싱하·2023년 7월 7일
0

postgre

목록 보기
1/4
post-thumbnail

postgreSQL

신입 DBA의 DBMS찍먹기행

DB 접속방법

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
  • DBA로 일하면서 다른 계정을 들어갈일은 없지만 oracle,maria,mssql, postgre 접속방법들이 다 달라서 외우는거도 일...

DB instance 변경

PostgreSQL을 설치하고 많은 DB들을 create하게 된다.
접속 후 test2로 인스턴스를 변경하여 조회를 원한다면 DB를 나가고 -d test2 옵션으로 들어오는건 번거롭다

db접속 후 test2로 변경
db=# \c [dbname] [username]

위 예시 명령여(test1로 접속 -> test2로 instance변경)
test1=# \c test2

DB list 조회

* \list, \l : 전체 DB Instance 조회

다뤄본 DBMS의 비슷한 명령어

  • mariadb의 show databases;
  • oracle의 select tablespace_name from dba_tablespaces;

접속 DB의 정보 조회

\d[ t | s | f | v | u ]

* \dt : db의 table조회
* \ds : sequence조회
* \df : function조회
* \dv : view조회
* \du : user조회(db에 권한있는 user뜸)
명령어 뒤에 +를 붙이면 더 자세한 정보가 조회됨.

다른 DBMS의 비슷한 명령어

  • mariadb
    information_schema에 view,function 등 조회
    user는 show grants for 'user'@'host';로 권한 조회
  • oracle
    user_source type에서 조회
    dba_users 등 조회할 수 있는 뷰가 많음
* \d [table_name] : table의 칼럼정보 = desc [table_name];
profile
끄적끄적...

0개의 댓글

관련 채용 정보