Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- 웹뷰
- javascript
- Maven
- SpringSource Tool Suite
- Redirect
- 이클립스
- Web Service
- Apache Lucene
- 자바
- C#
- MSsql
- STS
- 자바스크립트
- jsp
- Java
- Eclipse
- 웹 서비스
- MANTIS
- html
- Android
- TextBox
- WebView
- scrollView
- asp.net
- Bootstrap
- 안드로이드
- decompiler
- varags
- MS-SQL
- 컬럼명
Archives
- Today
- Total
bboks.net™
How to Execute PostgreSQL Commands Inside Unix Shell Scripts 본문
Operating System/Linux
How to Execute PostgreSQL Commands Inside Unix Shell Scripts
bboks.net 2016. 3. 28. 13:39Question: How do I executed PostgreSQL Commands inside a Linux / UNIX shell script?
Answer: With the help of the psql interactive terminal, you can execute the psql commands from the shell script. For this purpose, you should enable the password less login by pg_hba.conf, or .pgpass.
Syntax
psql DBNAME USERNAME << EOF statement 1; statement 2; . . statement n; EOF
PostgreSQL: Execute SQL from shell scripts
EOF 블록 사이에 postgreSQL 모든 명령어 입력
dbname="test" username="test" psql $dbname $username << EOF SELECT * FROM test; EOF
PostgreSQL: Using variables in SQL from shell scripts
EOF 블록 내부에 쉘 스트립트 변수를 사용할 수 있음
dbname="test" username="test" wherecond="tgs" psql $dbname $username << EOF SELECT * FROM test WHERE col_name = '$wherecond'; EOF
이를 이용해서 스키마(schema)를 삭제하고 복구(restore)하는 실행파일 작성
dbname="test"
schemaname="test"
psql $dbname << EOF
DROP SCHEMA IF EXISTS $schemaname CASCADE;
\q
EOF
pg_restore --username "username" --dbname "test" --no-password --no-owner --verbose 백업파일(절대경로)
[출처] How to Execute PostgreSQL Commands Inside Unix Shell Scripts