如何导入PostgreSQL数据库数据
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何导入PostgreSQL数据库数据相关的知识,希望对你有一定的参考价值。
参考技术A 您好,举例说明:如将一Shapfile文件“c:\road.shp”导入到数据表“road”中,数据库为“sjzmap”。
1、运行“命令提示符”。
2、切换至PostgreSQL数据库安装目录中的bin目录下。
3、执行此目录下的shp2pgsql命令:“shp2pgsql c:\road.shp road > c:\road.sql”。
4、如将此文件直接导入数据库(不推荐):“shp2pgsql -c c:\road.shp road sjzmap | psql -d sjzmap”。
5、使用pgAdmin3 选择数据库,再导入表。
注:
Drops the database table before creating a new table with the data in the Shape file.
Appends data from the Shape file into the database table. Note that to use this option to load multiple files, the files must have the same attributes and same data types.
Creates a new table and populates it from the Shape file.
Only produces the table creation SQL code, without adding any actual data. This can be used if you need to completely separate the table creation and data loading steps.
Use the PostgreSQL "dump" format for the output data. This can be combined with -a, -c and -d. It is much faster to load than the default "insert" SQL format. Use this for very large data sets.
Creates and populates the geometry tables with the specified SRID.
Keep identifiers' case (column, schema and attributes). Note that attributes in Shapefile are all UPPERCASE.
Coerce all integers to standard 32-bit integers, do not create 64-bit bigints, even if the DBF header signature appears to warrant it.
Create a GiST index on the geometry column.
Output WKT format, for use with older (0.x) versions of PostGIS. Note that this will introduce coordinate drifts and will drop M values from shapefiles.
Specify encoding of the input data (dbf file). When used, all attributes of the dbf are converted from the specified encoding to UTF8. The resulting SQL output will contain a command, so that the backend will be able to reconvert from UTF8 to whatever encoding the database is configured to use internally.本回答被提问者和网友采纳
Postgresql 数据库,如何进行数据备份以及导入到另外的数据库
方法其实有很多种,这里用的方法比较稳妥。之后有时间会补充别的方法。
该方法分为三步:备份数据,新建表结构,导入数据
备份数据:>>\copy table_name to ‘/home/bak/table_name.sql‘;
新建表结构:把原来表结构的sql语句复制,删除没必要和不适应的信息,在新的数据库运行新建表语句。
导入数据:>>\copy table_name from ‘/home/bak/table_name.sql‘;
以上是关于如何导入PostgreSQL数据库数据的主要内容,如果未能解决你的问题,请参考以下文章