본문 바로가기

[Database]

PostgreSQL 테이블 사이즈, 스페이스 사이즈. 인덱스 사이즈 1. 테이블별 사이즈A. 테이블 스페이스 총량=> select spcname, pg_size_pretty(pg_tablespace_size(spcname)) from pg_tablespace;B. 각 테이블별 사이즈ð Index 미포함 : select pg_relation_size(‘TableName’);ð Index 포함 : select pg_total_relation_size(‘TableName’);C. 인덱스 사이즈ð select pg_relation_size(‘IndexName’);D. 총 사이즈(데이터 + 인덱스)ð select pg_total_relation_size(‘TableName’); 단위 적용 : pg_size_pretty() 추가 : DB 사이즈 ð select pg_size_pre.. 더보기
NULL 체크 및 문자열 합치기 1. coalesce - SELECT coalesce([컬럼명 혹은 쿼리], 값) FROM [table_name] 컬럼의 값 혹은 쿼리의 값이 NULL 이면 값을 리턴한다. NULL이 아니면 해당 값을 리턴한다. 2. || - SELECT [필드명]||'**' FROM [table_name] 문자열을 합친다. 더보기
DDL, DML, DCL DDL : Data Definition Language (데이터 정의어) - Create, Alter, Drop, TruncateDML : Data Manipulation Language (데이터 조작어) - Select, Insert, Update, DeleteDCL : Data Control Language (데이터 제어어) - Grant, Revoke 더보기
CSV 백업파일 생성 =# COPY [테이블명] to [생성파일경로/생성파일명.csv] delimiters ','; 더보기
psql 테이블 백업파일 insert psql -U [계정명] -d [데이터베이스명] -a -f [파일명]-a --echo-allPrint all nonempty input lines to standard output as they are read. (This does not apply to lines read interactively.) This is equivalent to setting the variable ECHO to all.-f filename --file=filenameUse the file filename as the source of commands instead of reading commands interactively. After the file is processed, psql terminates. This is i.. 더보기
pg_dump insert 구문 특정 insert 구문이 필요 할 경우. pg_dump -U [계정명] -t [테이블명] -a -O --inserts -E UTF8 [데이터베이스명] > dump.sql 그러면 insert 구문으로 백업된다. 테이블이 여러개일 경우.pg_dump -U [계정명] -t [테이블명1] -t [테이블명2] -t [테이블명3] -a -O --inserts -E UTF8 [데이터베이스명] > dump.sql -t 옵션을 빼면 database 전체가 백업된다. [option 참고] -U, --username=NAME connect as specified database user -t, --table=TABLE dump the named table(s) only -a, --data-only dump only the .. 더보기
pg_dump schema (MySQL : show create table tablename) PostgreSQL 스키마 알아보기. MySQL에서 사용하던 show create table [테이블이름] 을 지원하지 않는다. 그리하여 pg_dump --schema-only -t tablename 이명령을 써야 한다. pg_dump [DB이름] -U [접속계정] --schema-only -t [Table이름] > dump.sql 이렇게 하면 'dump.sql' 파일에 내용이 담긴다. 끝. 더보기
Start / 기본 명령어 - Port 확인 netstat -nplt - 계정변경 [test@localhost ~]$ su postgreSQL 암호: [postgreSQL@localhost TEST]$ - 시작 cd /PostgreSQL/bin pg_ctl restart -D /PostgreSQL/data/ - 접속 psql DatabaseName - 명령어 \d : database의 모든 테이블과 sequence view \d TABLE : table 속성, index view \di : database의 모든 index view \di INDEX : 지정한 index 속성 view \i FileName : file로 부터 SQL 명령을 읽어 수행 \q : 콘솔 종료 더보기