Linux(Ubuntu 14.04)에서 Postgre 설치


1. Postgre 설치

커맨드창에서 아래와 같이 명령을 입력한다.
sudo apt-get install postgresql

Linux 에서 psycopg2 설치(django에서 DB API 어댑터설치)

http://initd.org/psycopg/docs/install.html#install-from-a-package

커맨드창에서 아래와 같이 명령을 입력한다.
sudo apt-get install python-psycopg2
 
또는 다음과 같이 pip로 설치가 가능하다.
pip install psycopg2
 
현재 지원되는 버전은 다음과 같다.
  • Python 2 versions from 2.5 to 2.7
  • Python 3 versions from 3.1 to 3.4
  • PostgreSQL versions from 7.4 to 9.4

참고링크)
https://help.ubuntu.com/community/PostgreSQL

postgres 가 기본 데이터베이스로 사용되고 관리계정으로  postgres가 사용된다.
django에서 기본적으로 패스워드 설정이 안되어있으면 접속이 안되게 되어 있어
패스워드 설정도 해야한다.

postgres계정으로 psql을 실행한다.
$ sudo -u postgres psql postgres
 
postgres계정의 패스워드 설정(psql명령)
\password postgres
 
Database 생성 
$ sudo -u postgres createdb mydb 
또는 postgres로 접속이 되었다면 createdb 명령으로도 생성이 된다.

postgres 계정으로 접속하기

$ sudo -i -u postgres

postgre 서비스 시작하기

sudo service postgresql start
서비스 재시작시 
service postgresql restart 

2. 장고에서 db 설정하기

https://docs.djangoproject.com/en/1.9/ref/settings/#databases 

DATABASES = {
    'default': {
        # 'ENGINE': 'django.db.backends.sqlite3',
        # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'postgres',
        'USER': 'postgres',
        'PASSWORD': 'postgres',
        'HOST': '127.0.0.1',
        'PORT': '5432',        
    }
}

migrate 수행

$ python manage.py migrate

댓글

이 블로그의 인기 게시물

dtsrun 실행하기

Set nocount on 옵션 설정하기

Slug가 뭘까?