导出表
pg_dump -h localhost -U postgres(用户名) 数据库名(缺省时同用户名) -t table(表名) > dump.sql
导入表
psql -f dump.sql
完整的导入导出表的例子
1,查看一下原数据库
-bash-3.2$ psql -U playboy -d playboy //原数据库
Welcome to psql 8.1.23, the PostgreSQL interactive terminal.
Type: copyright for distribution terms
h for help with SQL commands
? for help with psql commands
g or terminate with semicolon to execute query
q to quit
playboy=> dt;
List of relations
Schema | Name | Type | Owner
--------+------------+-------+---------
public | contents | table | playboy
public | entries | table | playboy
public | properties | table | playboy
public | settings | table | playboy
public | test | table | playboy
(5 rows)
playboy=> q
2,导出数据库和表
1.-bash-3.2$ pg_dump -O playboy > /var/lib/pgsql/data/playboy2013.sql //导出playboy数据库
2.
3.-bash-3.2$ pg_dumpall > /var/lib/pgsql/data/all_databases2013.sql //导出全部数据库
4.
5.-bash-3.2$ pg_dump -O playboy -Ft -t test > /var/lib/pgsql/data/playboy_test2013.tar //导出一张表.tar的文件供pg_restore
6.
7.-bash-3.2$ ls /var/lib/pgsql/data |grep 2013 //查看一下导好了
8.playboy2013.sql all_databases2013.sql playboy_test2013.tar
-bash-3.2$ pg_dump -O playboy > /var/lib/pgsql/data/playboy2013.sql //导出playboy数据库
-bash-3.2$ pg_dumpall > /var/lib/pgsql/data/all_databases2013.sql //导出全部数据库
-bash-3.2$ pg_dump -O playboy -Ft -t test > /var/lib/pgsql/data/playboy_test2013.tar //导出一张表.tar的文件供pg_restore
-bash-3.2$ ls /var/lib/pgsql/data |grep 2013 //查看一下导好了
playboy2013.sql all_databases2013.sql playboy_test2013.tar3,创建新数据库,并导入
-bash-3.2$ psql -U playboy -d playboy //原数据库
Welcome to psql 8.1.23, the PostgreSQL interactive terminal.
Type: copyright for distribution terms
h for help with SQL commands
? for help with psql commands
g or terminate with semicolon to execute query
q to quit
playboy=> dt;
List of relations
Schema | Name | Type | Owner
--------+------------+-------+---------
public | contents | table | playboy
public | entries | table | playboy
public | properties | table | playboy
public | settings | table | playboy
public | test | table | playboy
(5 rows)
playboy=> q
-bash-3.2$ createdb playboy_test -O playboy //创建一个归属playboy的数据库playboy_test
CREATE DATABASE
-bash-3.2$ pg_restore -d playboy_test /var/lib/pgsql/data/playboy_test2013.tar //导入单表,
//将上面导入表删除后,在把playboy的数据库导入到playboy_test中去,权限归属playboy
-bash-3.2$ psql -d playboy_test -U playboy -f /var/lib/pgsql/data/playboy2013.sql
SET
SET
SET
COMMENT
SET
CREATE SEQUENCE
setval
--------
18
(1 row)
SET
SET
CREATE TABLE
CREATE SEQUENCE
setval
--------
4
(1 row)
CREATE TABLE
CREATE TABLE
CREATE SEQUENCE
setval
--------
3
(1 row)
CREATE TABLE
CREATE TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
CREATE INDEX
REVOKE
REVOKE
GRANT
GRANT
-bash-3.2$ psql -U playboy -d playboy_test //登录到playboy_test
Welcome to psql 8.1.23, the PostgreSQL interactive terminal.
Type: copyright for distribution terms
h for help with SQL commands
? for help with psql commands
g or terminate with semicolon to execute query
q to quit
playboy_test=> dt; //查看一下表,根playboy数据库一样的。
List of relations
Schema | Name | Type | Owner
--------+------------+-------+----------
public | contents | table | playboy
public | entries | table | playboy
public | properties | table | playboy
public | settings | table | playboy
public | test | table | playboy
(5 rows)
pgsql导入写法比较多,上面已经有二种了,在说一种
1.-bash-3.2$ psql -U playboy playboy_test < /var/lib/pgsql/data/playboy2013.sql
敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载像素火影骨架佐助 (Perseverance Fire Shadow)手机版v1.16
下载要塞英雄 安卓版v33.20.0-39082670-Android
下载梦想城镇vivo最新版本 安卓版v12.0.1
梦想城镇vivo版是这款卡通风模拟经营类手游的渠道服版本,玩
怦然心动的瞬间 安卓版v1.0
怦然心动的瞬间是一款真人向的恋爱互动游戏,在游戏中玩家将扮演
曼尼汉堡店游戏 安卓版v1.0.3
曼尼汉堡店是一款非常好玩的精品恐怖类型冒险游戏,在这款游戏中
现代总统模拟器去广告版 安卓版v1.0.46
现代总统模拟器是一款休闲养成类游戏,可能对于不少的玩家来说都
现代总统模拟器付费完整版 安卓版v1.0.46
现代总统模拟器高级版在商店是需要付费的,相对于普通版本,高级