数据导出 .tar:
pg_dump -h 192.168.4.97 -p 5432 -U postgres -d gv_place -F t -f /home/place.tar
单独导出一张表:
pg_dump -h 192.168.4.17 -p 5431 -U postgres -d new_world -t world -F t -f /data/postgresql/world.tar
导出一个文件夹
pg_dump -h 192.168.4.17 -p 5431 -U postgres -d new_world -F d -f ./data1
导入 .sql .dmp .dump
psql -h 192.168.4.17 -p 5431 -U postgres -f ./xx.sql
psql -h 192.168.4.17 -p 5431 -U postgres -d db_name -f ./test.dmp
psql -h 192.168.4.17 -p 5431 -U postgres -d db_name -f ./test.dump
数据导入:
psql -h 192.168.4.38 -p 5431 -U postgres
DROP DATABASE IF EXISTS gv_place;
报错:
ERROR: database “gv_place” is being accessed by other users
DETAIL: There are 200 other sessions using the database.
错误: 其他用户正在使用源数据库 “template1”
描述: 那里有1个其它会话正在使用数据库.
解决方案:
select pg_terminate_backend(pid) from pg_stat_activity where DATNAME=‘gv_place’;
创建gv_place数据库
create database gv_place encoding = ‘UTF-8’;
退出数据库
\q
将tar包数据导入到gv_place数据库
pg_restore -h 192.168.4.38 -p 5431 -U postgres -d gv_place -v ./place.tar
报错:type “public.geometry” does not exist
错误: 缺少插件
解决方案:
\c database //进入这个database
CREATE EXTENSION postgis;
\q
重新导入