프로그래밍/DB

postgreSQL command line에서 사용하기

kugancity 2018. 4. 11. 14:59
반응형



postgreSQL command line에서 사용하기



postgreSQL 접속하기 


psql 커멘드를 사용하여 postgreSQL에 접속한다.

-U 로 사용자 이름, -d로 접속 데이터베이스를 지정할 수 있다. 



psql -U username -d dbname -W

Password for user username:
psql (9.6.6)

Type "help" for help.







터미널 접속하기 & 데이터베이스 목록 보기 (\l)



dbname=> \l
                                  List of databases
    Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
------------+----------+----------+-------------+-------------+-----------------------
 db1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres         +
            |          |          |             |             | postgres=CTc/postgres+
            |          |          |             |             | land=CTc/postgres

...





DB 변경하기 (\c)


db1=> \c db2
Password for user username:
You are now connected to database "db2" as user "username".

db2->


user 권한 확인하기(\du)




db1->\du
List of roles 
Role name | Attributes | Member of
------------------------------------------
user1 |                           | {}
user2 | Superuser, Create role, Create DB, ... | {}
 










참조: https://www.tutorialspoint.com/postgresql/postgresql_select_database.htm





728x90
반응형