중요
번역은 여러분이 참여할 수 있는 커뮤니티 활동입니다. 이 페이지는 현재 73.68% 번역되었습니다.
16.3. 수업: 가져오기와 내보내기
Of course, a database with no easy way to migrate data into it and out of it would not be of much use. Fortunately, there are a number of tools that will let you easily move data into and out of PostgreSQL.
16.3.1. shp2pgsql
shp2pgsql is a commandline tool to import ESRI Shapefile to the database. Under Unix, you can use the following command for importing a new PostgreSQL table:
shp2pgsql -s <SRID> -c -D -I <path to shapefile> <schema>.<table> | \
psql -d <databasename> -h <hostname> -U <username>
윈도우에서는, 가져오기 과정을 두 단계로 수행해야 합니다:
shp2pgsql -s <SRID> -c -D -I <path to shapefile> <schema>.<table> > import.sql
psql psql -d <databasename> -h <hostname> -U <username> -f import.sql
다음 오류가 발생할 수도 있습니다:
ERROR: operator class "gist_geometry_ops" does not exist for access method
"gist"
여러분이 가져오는 데이터에 대한 공간 인덱스의 생성 원위치(in situ) 와 관련된, 잘 알려진 문제점입니다. 이 오류를 피하려면 -I 파라미터를 빼십시오. 이렇게 하면 공간 인덱스를 자동으로 생성하지 않고, 데이터를 가져온 다음 여러분이 데이터베이스에 직접 생성해줘야 합니다. (공간 인덱스 생성에 대해서는 다음 수업에서 배울 것입니다.)
16.3.2. pgsql2shp
pgsql2shp is a commandline tool to export PostgreSQL Tables, Views or SQL select queries. To do this under Unix:
pgsql2shp -f <path to new shapefile> -g <geometry column name> \
-h <hostname> -U <username> <databasename> <table | view>
쿼리를 사용해서 데이터를 내보내려면:
pgsql2shp -f <path to new shapefile> -g <geometry column name> \
-h <hostname> -U <username> "<query>"
16.3.3. ogr2ogr
ogr2ogr is a very powerful tool to convert data into and from PostgreSQL to many data formats. ogr2ogr is part of the GDAL library and has to be installed separately. To export a table from PostgreSQL to GML, you can use this command:
ogr2ogr -f GML export.gml PG:'dbname=<databasename> user=<username>
host=<hostname>' <Name of PostgreSQL-Table>
16.3.4. DB 관리자
You may have noticed another option in the Database menu labeled DB Manager. This is a tool that provides a unified interface for interacting with spatial databases including PostgreSQL. It also allows you to import and export from databases to other formats. Since the next module is largely devoted to using this tool, we will only briefly mention it here.
16.3.5. 결론
데이터베이스에 데이터를 가져오거나 데이터베이스에서 내보내는 방법은 여러 가지가 있습니다. 특히 서로 전혀 다른 데이터 소스를 이용할 경우, 이 기능들을 (또는 다른 비슷한 기능들을) 상시적으로 사용하게 될 것입니다.
16.3.6. 다음은 무엇을 배우게 될까요?
다음으로 이전에 생성했던 데이터를 어떻게 쿼리할 수 있는지 알아보겠습니다.