Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3056030
  • 博文数量: 206
  • 博客积分: 3409
  • 博客等级: 中校
  • 技术积分: 4066
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-24 10:21
个人简介

● ITPUB名人堂嘉宾 ● ChinaUnix社区博客专家 ● ChinaUnix社区Oracle板块版主 ● 优酷网认证音乐牛人:EricGuitar ● SDOUG 核心成员 ●E-mail:gaoqiangdba@163.com

文章分类

全部博文(206)

文章存档

2021年(11)

2020年(7)

2019年(7)

2016年(5)

2015年(36)

2014年(23)

2013年(15)

2012年(23)

2011年(61)

2010年(18)

分类: Mysql/postgreSQL

2015-02-07 16:41:29

  





 PostgreSQL数据库的简单导入、导出操作体验,操作还是非常简单易用的。当然该工具还提供了众多的参数,以供不同的情景下使用,在此我们只做最简单的导出和导入操作。

创建测试用表:
postgres=# \c music
您现在已经连线到数据库 "music",用户 "postgres".


music=#  create table test(ID int);
CREATE TABLE
music=# insert into test values(1);
INSERT 0 1
music=# insert into test values(2);
INSERT 0 1
music=# insert into test values(3);
INSERT 0 1

验证数据插入成功:
music=# select * from test;
 id 
----
  1
  2
  3
(3 行记录)


music=# \d
              关联列表
 架构模式 | 名称 |  型别  |  拥有者  
----------+------+--------+----------
 public   | test | 资料表 | postgres       -------查看表信息
(1 行记录)




备份数据库:
-bash-3.2$ pg_dump music >/tmp/music.dmp

查看备份:

-bash-3.2$ cd /tmp/
-bash-3.2$ ls
db2.tmp.5072  dmp  keyring-BJJFsF  mapping-root  music.dmp  PostgreSQL9.4_PACK  scim-panel-socket:0-root  vmware-tools-distrib




删除数据库:
postgres=# drop database music;
DROP DATABASE
postgres=# \l
                                     资料库列表
   名称    |  拥有者  | 字元编码 |  校对规则   |    Ctype    |       存取权限        
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 template0 | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(3 行记录)

从上面信息看,music数据库已删除!~~~



恢复数据库:

postgres=# create database music;
CREATE DATABASE

开始恢复:
$ psql music
SET
SET
SET
SET
SET
SET
CREATE EXTENSION
COMMENT
SET
SET
SET
CREATE TABLE
ALTER TABLE
COPY 3
REVOKE
REVOKE
GRANT
GRANT
-bash-3.2$ 
-bash-3.2$ 
-bash-3.2$ psql
psql (9.4.0)
输入 "help" 来获取帮助信息.






验证是否恢复数据库:
postgres=# \l
                                     资料库列表
   名称    |  拥有者  | 字元编码 |  校对规则   |    Ctype    |       存取权限        
-----------+----------+----------+-------------+-------------+-----------------------
 music     | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 postgres  | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 template0 | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(4 行记录)




连接数据库:
postgres=# \c music
您现在已经连线到数据库 "music",用户 "postgres".

music=# \d
              关联列表
 架构模式 | 名称 |  型别  |  拥有者  
----------+------+--------+----------
 public   | test | 资料表 | postgres   ---表已恢复过来!
(1 行记录)



验证是否已把数据恢复过来:
music=# select * from test;   ----查看数据存在否
 id 
----
  1
  2
  3
(3 行记录)




恢复成功!


阅读(21483) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

gongping112015-05-29 18:23:05

最近也做这方面的学习,也做到了差不多这部分