Outsider's Dev Story: Database/etc... 카테고리 글 목록
https://blog.outsider.ne.kr/
Stay Hungry. Stay Foolish. Don't Be Satisfied.
2024-03-15T12:06:24+09:00
Textcube 1.10.7 : Tempo primo
Ubuntu에서 PostgresSQL 설정하기
Outsider
https://blog.outsider.ne.kr/377
2009-09-29T15:57:20+09:00
2009-09-24T03:13:34+09:00
PostgreSQL은 처음 만져보는 데 PostgreSQL을 만져봐야 할 일이 생겼는데 역시 처음부터 헤매게 되는군요. ㅎ<br><br>일단 설치부터해야 됩니다. 설치는 PostgreSQL서버와 클라이언트, 그리고 관련 라이브러리를 설치합니다. 여기서 Ubuntu는 9.04이고 PostgreSQL 8.3을 사용합니다. <br><br><div class="imageblock center" style="text-align: center; clear: both;"><img src="//blog.outsider.ne.kr/attach/1/1005135953.gif" alt="PostgreSQL 설치 " height="158" width="550" /></div><br><div style="margin-left: 40px;"><span style="color: rgb(255, 118, 53);">sudo apt-get install postgresql-8.3 postgresql-client-8.3 postgresql-contrib-8.3</span><br></div><br>시냅틱을 이용해서 설치할 수도 있지만 apt-get을 이용해서 설치합니다.(apt-get에 자꾸 익숙해져서야 해서...)<br><br><div class="imageblock center" style="text-align: center; clear: both;"><img src="//blog.outsider.ne.kr/attach/1/1180928119.gif" alt="pgadmin3 설치" height="187" width="496" /></div><br><div style="margin-left: 40px;"><span style="color: rgb(255, 118, 53);">sudo apt-get install pgadmin3</span><br></div><br>pgadmin3는 Toad나 엔터프라이즈 메니저같은 PostgreSQL GUI클라이언트 툴입니다.<br><br>이제 postgres계정의 패스워드를 리셋해 줍니다.<br><br><div class="imageblock center" style="text-align: center; clear: both;"><img src="//blog.outsider.ne.kr/attach/1/1214122515.gif" alt="postgres 비밀번호 설정 " height="308" width="448" /></div><br><div style="margin-left: 40px;"><span style="color: rgb(255, 118, 53);">sudo su postgres -c psql template1</span><br style="color: rgb(255, 118, 53);"><span style="color: rgb(255, 118, 53);">postgres=# ALTER USER postgres WITH PASSWORD ‘4321’;</span><br style="color: rgb(255, 118, 53);"><span style="color: rgb(255, 118, 53);">postgres=# \q</span><br style="color: rgb(255, 118, 53);"><span style="color: rgb(255, 118, 53);">sudo passwd -d postgres</span><br style="color: rgb(255, 118, 53);"><span style="color: rgb(255, 118, 53);">sudo su postgres -c passwd</span><br></div><br>데이터베이스에서 유저의 패스워드를 교체해주주고 우분투의 postgres유저의 비밀번호를 다시 설정해 줍니다.<br><br><div class="imageblock center" style="text-align: center; clear: both;"><img src="//blog.outsider.ne.kr/attach/1/1228771013.gif" alt="유저 생성 " height="84" width="522" /></div><br><div style="margin-left: 40px;"><span style="color: rgb(255, 118, 53);">sudo -u postgres createuser -D -A -P mynewuser</span><br style="color: rgb(255, 118, 53);"><span style="color: rgb(255, 118, 53);">sudo -u postgres createdb -O mynewuser mydatabase</span><br></div><br>이제 PostgreSQL에서 사용할 유저를 생성하고 그 유저의 데이터베이스를 생성합니다. 여기서 생성한 유저와 비번을 이용해서 해당 데이터베이스로 pgAdmin을 이용해서 접속하면 아래와 같이 접속할 수 있습니다.<br><br><div class="imageblock center" style="text-align: center; clear: both;"><img src="//blog.outsider.ne.kr/attach/1/1347338656.gif" alt="사용자 삽입 이미지" height="551" width="550" /></div><br>만약 로컬에서 접속하는게 아닌 원격에서 접속해야 한다면 <span style="color: rgb(204, 153, 0);">/etc/postgresql/8.2/main/postgresql.conf</span>를 수정해주어야 합니다.<br><br><span style="color: rgb(255, 118, 53);">sudo vi /etc/postgresql/8.2/main/postgresql.conf</span><br><br>이 파일에서 아래의 2줄을 밑에처럼 변경해 줍니다.<br><br style="color: rgb(204, 153, 0);"><div style="margin-left: 40px;"><span style="color: rgb(204, 153, 0);">#listen_addresses = ‘localhost’</span><br style="color: rgb(204, 153, 0);"><span style="color: rgb(204, 153, 0);">#password_encryption = on</span><br style="color: rgb(204, 153, 0);"><br style="color: rgb(204, 153, 0);"><span style="color: rgb(204, 153, 0);">listen_addresses = ‘*’</span><br style="color: rgb(204, 153, 0);"><span style="color: rgb(204, 153, 0);">password_encryption = on</span><br></div><br>설정읠 변경했다면 <span style="color: rgb(204, 153, 0);">sudo /etc/init.d/postgresql-8.2 restart </span>로 PostgreSQL을 재시작해줍니다.<br><p><strong><a href="https://blog.outsider.ne.kr/377?commentInput=true#entry377WriteComment">댓글 쓰기</a></strong></p>