DataBase/Postgresql

postgresql 세팅 및 사용

shwezarl 2010. 11. 19. 14:06
 * sudo bash -> root 권한으로 실행, 실행시마다 sudo를 하지 않아도 됨.

ubuntu postgresql 설치


sudo apt-get install postgresql-8.3 postgresql-client-8.3
sudo apt-get install postgresql-8.3-postgis


(선택사항)
sudo apt-get install pgadmin3 pgadmin3-data (x-window admintool) .OR.
sudo apt-get install phppgadmin (web base admintool)


postgres 유저 비밀번호 설정
1. sudo su postgres -c psql template1
2. (psql 진입후) ALTER USER postgres WITH PASSWORD 'password';
3. \q


postgres 외부에서 Connect 하기위해
1. pg_hba.conf(PostgreSQL8.3 -> Configuration files)
Type DATABASE USER CIDR-ADDRESS METHOD 추가
host all all 210.92.150.24/26 md5
2. postgresql.conf(PostgreSQL8.3 -> Configuration files)
listen_addresses = 'localhost, 210.92.150.24' 추가


postgis 함수를 db에 추가 하기위해
1. sudo su postgres
2. createdb mytestdb
3. createlang plpgsql mytestdb
4. psql -d mytestdb -f /usr/share/postgresql-8.3-postgis/lwpostgis.sql
5. psql -d mytestdb -f /usr/share/postgresql-8.3-postgis/spatial_ref_sys.sql
6. shp2pgsql -D myshape.shp mytable mytestdb | psql mytestdb




* shp2pgsql -s 4326 -c ntt1 ntt1 urimap | iconv -f cp949 -t utf8 > ../../sql/ntt1.sql
- shape file을 sql 문으로 변환
- SRID 4326으로 설정
- -c 옵션 : create table
- ntt1.shp 파일을 urimap database에 ntt1 table을 생성하여 삽입
- cp949 코드를 utf8로 변환하여 ntt1.sql 파일로 저장

* sql 파일을 이용하여 PostGIS에 import
- sudo su postgres : postgres 사용자 ID로 실행
- psql -f ntt1.sql urimap : ntt1.sql 파일을 urimap Database에 데이터 삽입


'DataBase > Postgresql' 카테고리의 다른 글

POSTGRESQL ALTER문  (0) 2013.08.02
PostGIS Shapefile and DBF Loader 등록  (0) 2013.08.02
Automatically fixing ring self-intersections in shp2pgsql 발생시  (0) 2013.08.02
DB CASE 식  (0) 2013.08.02