카테고리 없음2013. 3. 22. 10:53

> PostgreSQL 서비스 실행

pg_ctl start -l logfile

또는

service postgres start


> psql 실행 하면서 <postgres> database에 연결 (Ubuntu, PostgreSQL 9.2 설치 기준)

sudo -u postgres psql postgres


> psql 종료

\q


> 도웅말 표시 

\?


> 사용자 목록 표시

\du


> database 목록 표시

\l


> schema 목록 표시

\dn


> test_schema 의 table 목록 표시

\dt test_schema.*


test_schema 의 test_table 의 column 목록 표시

\d test_schema.test_table



> database 생성

CREATE DATABASE test_db;


> test_db (database) 에 연결

\c test_db


> 버전 표시

SELECT VERSION();


> PSQL 에서 Query 또는 명령어 실행 ( 예) testdb 데이터베이스의 myschema.mytable 쿼리 )

psql -d testdb -c 'select * from myschema.mytable'


> PSQL 에서 파일에 저장된 Query 실행 ( 예) testdb 데이터베이스 연결하여 쿼리 실행 )

psql -d testdb -f my_query.sql 또는 psql -d testdb < my_query.sql


> PSQL 에서 원격지 서버 (192.168.0.10) 에 계정 postgres 로 연결

psql -h 192.168.0.10 -U postgres -d testdb < my_query.sql

> PSQL 에서 원격지 서버 (192.168.0.10) 접속시 비밀번호 (mypassword) 지정

PGPASSWORD=mypassword psql -h 192.168.0.10 -U postgres -d testdb < my_query.sql


Posted by 좋은나무