PostgreSQL
-
postgresql 테이블을 csv로 저장하기 (with pandas)프로그래밍/DB 2019. 1. 15. 21:03
postgresql 테이블을 csv로 저장하기 (with pandas) flask에서 postgreSQL 테이블 내용을 csv로 저장하는 함수 작성을 하고 기록해둔다.처음에는 psycopg2에서 제공하는 함수를 사용해볼까 했는데 함수 자체의 설명도 부족하고 어차피 기계 실험해야 하면 pandas 사용해야 해서 pandas 의 read_sql, to_csv의 함수를 사용했는데 간편하고 좋은 것 같다. import psycopg2 as pcimport pandas as pd dataReceive = request.get_json()df = get_data(dataReceive) def get_data(req_data): try: conn = pc.connect("dbname=디비이름 user=계정 passw..
-
postgreSQL - .pgpass 파일 설정법프로그래밍/DB 2018. 12. 31. 16:46
.pgpass 파일 설정 방법 pgpass 파일은 postgreSQL 계정의 암호를 기록해두는 설정파일로 해당 파일을 생성해두면 psql 이나 pg_dump 명령어를 사용할때 암호를 입력하지 않고 사용할 수 있다. 그리고 따로 암호를 입력할 수 없는 스크립트에서도 pg_dump 등의 명령어를 사용할 수 있게 해준다. 우선 홈디렉토리의 계정에 .pgpass 파일을 생성한다. 포맷은 아래와 같다. hostname:port:database:username:password 처음 네 개의 필드는 값을 입력하거나 * (와일드카드)를 사용한다. 암호 필드는 와일드 카드를 사용할 수 없다. 앞의 값이 다 * 라면 현재 커넥션의 파라미터들(사용자 이름, 디비 등)이 사용된다. 아래는 pgpass 파일 설정 예시이다. #..
-
리눅스(ubuntu)에 postgreSQL 설치하기프로그래밍/DB 2018. 11. 24. 19:32
리눅스에 postgreSQL 설치한 과정을 정리해두겠다. apt-get install로 아래와 같이 패키지 설치를 한다. sudo apt-get install postgresql postgresql-contrib # sudo apt-get install postgresql postgresql-contribReading package lists... DoneBuilding dependency treeReading state information... DoneThe following packages were automatically installed and are no longer required: duplicity librsync1 python-lockfileUse 'apt-get autoremove' t..