J.BF Story

[PostgreSQL] psql 기본 명령어 본문

DB/PostgreSQL

[PostgreSQL] psql 기본 명령어

J.BF 2022. 6. 10. 23:54

Connect PostgreSQL

psql -U postgres // 'postgres' user로 접속
psql -U postgres -d testdb // 'testdb' database로 접속
psql -U postgres -h 10.01.1.1 // '10.01.1.1' IP로 접속
psql -U postgres -p 54321 // '54321' port로 접속

** 기본값

  • [-U] user: 현재 서버 사용자 이름
  • [-h] IP: localhost(127.0.0.1)
  • [-p] port: 5432
  • [-d] database: psql에 접속한 유저 이름과 동일한 데이터베이스

 

Database

Create Database

CREATE DATABASE {database name};
CREATE DATABASE {database name} ENCODING 'utf-8';
CREATE DATABASE {database name} OWNER {user};

List Tables

\l

Connect Database

\c {database name}

 

Table

List Tables

\dt
\dt+ // detail

Show Table Schema

\d {table name}

List Table Using pg_catalog Schema

SELECT *
FROM pg_catalog.pg_tables
WHERE schemaname != 'pg_catalog' AND 
    schemaname != 'information_schema';

User

List Users

SELECT * FROM PG_USER;

 

 

ETC

Check Version

SELECT VERSION();

'DB > PostgreSQL' 카테고리의 다른 글

[PostgreSQL] pgModeler 설치(MAC)  (0) 2022.06.11
Comments