postgresql备份和恢复
备份: pg_dump -d m3vg -h localhost -p 5432 -U delta -W -f 1024.dump -F tar
恢复: pg_restore -h localhost -p 5432 -Udelta -W 1024.dump -d m3vg
忘记postgresql的用户的密码,怎么进入psql呢?
1. sudo su postgres -
2. psql
执行上面两部就可以进入了
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
pg_dump is an effective tool to backup postgres database. It creates a *.sql file with CREATE TABLE, ALTER TABLE, and COPY SQL statements of source database. To restore these dumps psql command is enough.
Using pg_dump, you can backup a local database and restore it on a remote database at the same time, using a single command. In this article, let us review several practical examples on how to use pg_dump to backup and restore.
For the impatient, here is the quick snippet of how backup and restore postgres database using pg_dump and psql:
Backup: $ pg_dump -U {user-name} {source_db} -f {dumpfilename.sql} Restore: $ psql -U {user-name} -d {desintation_db}-f {dumpfilename.sql}
1. Backup a single postgres database
This example will backup erp database that belongs to user geekstuff, to the file mydb.sql
$ pg_dump -U geekstuff erp -f mydb.sql
It prompts for password, after authentication mydb.sql got created with create table, alter table and copy commands for all the tables in the erp database. Following is a partial output of mydb.sql showing the dump information of employee_details table.
2. Backup all postgres databases
To backup all databases, list out all the available databases as shown below.
Login as postgres / psql user:
$ su postgres
List the databases:
$ psql -l List of databases
Name | Owner | Encoding
-----------+-----------+----------
article | sathiya | UTF8
backup | postgres | UTF8
erp | geekstuff | UTF8
geeker | sathiya | UTF8
Backup all postgres databases using pg_dumpall:
You can backup all the databases using pg_dumpall command.
$ pg_dumpall > all.sql
Verify the backup:
Verify whether all the databases are backed up,
$ grep "^[\]connect" all.sql
\connect article
\connect backup
\connect erp
\connect geeker
3. Backup a specific postgres table
$ pg_dump --table products -U geekstuff article -f onlytable.sql
To backup a specific table, use the –table TABLENAME option in the pg_dump command. If there are same table names in different schema then use the –schema SCHEMANAME option.
How To Restore Postgres Database
1. Restore a postgres database
$ psql -U erp -d erp_devel -f mydb.sql
This restores the dumped database to the erp_devel database.
Restore error messages
While restoring, there may be following errors and warning, which can be ignored.
psql:mydb.sql:13: ERROR: must be owner of schema public
psql:mydb.sql:34: ERROR: must be member of role "geekstuff"
psql:mydb.sql:59: WARNING: no privileges could be revoked
psql:mydb.sql:60: WARNING: no privileges could be revoked
psql:mydb.sql:61: WARNING: no privileges were granted
psql:mydb.sql:62: WARNING: no privileges were granted
2. Backup a local postgres database and restore to remote server using single command:
$ pg_dump dbname | psql -h hostname dbname
The above dumps the local database, and extracts it at the given hostname.
3. Restore all the postgres databases
$ su postgres
$ psql -f alldb.sql
4. Restore a single postgres table
The following psql command installs the product table in the geek stuff database.
$ psql -f producttable.sql geekstuff
postgresql备份和恢复的更多相关文章
- PostgreSQL 备份和恢复
备份和恢复有三种不同的基本方法来备份PostgreSQL数据SQL转储文件系统级备份File system level backup连续归档 1. SQL转储 pg_dump dbname > ...
- PostgreSQL备份和恢复数据表
备份数据表: pg_dump -U user_name db_name -t table_name -f /tmp/backup_file.suffix 恢复数据表: 方法1: 登录数据库:\i /t ...
- postgresql数据库备份和恢复
PostgreSQL自带一个客户端pgAdmin,里面有个备份,恢复选项,也能对数据库进行备份 恢复(还原),但最近发现数据库慢慢庞大的时候,经常出错,备份的文件过程中出错的几率那是相当大,手动调节灰 ...
- PostgreSQL的备份和恢复
关于PostgreSQL的备份和恢复详细信息请参阅<PostgreSQL中文文档>. 备份: #pg_dump --username=postgres v70_demo > v70_ ...
- postgresql数据库备份和恢复(超快)
PostgreSQL自带一个客户端pgAdmin,里面有个备份,恢复选项,也能对数据库进行备份 恢复(还原),但最近发现数据库慢慢庞大的时候,经常出错,备份的文件过程中出错的几率那是相当大,手动调节灰 ...
- PostgreSQL数据库常用脚本-初始化、备份、恢复推荐脚本
公司最近开始逐步推广使用PostgreSQL,为方便开发人员和实施人员操作,特整理数据库初始化.备份.恢复的推荐脚本如下: 1. 连接数据库 psql -h 127.0.0.1 -p 1921 -U ...
- Gitlab备份和恢复操作记录
前面已经介绍了Gitlab环境部署记录,这里简单说下Gitlab的备份和恢复操作记录: 1)Gitlab的备份目录路径设置 [root@code-server ~]# vim /etc/gitlab/ ...
- 转载:Gitlab备份和恢复操作记录
转载:Gitlab备份和恢复操作记录 包含了备份和数据恢复的操作记录,实验可行 前面已经介绍了Gitlab环境部署记录,这里简单说下Gitlab的备份和恢复操作记录: 1)Gitlab的备份目录路径设 ...
- Gitlab+Jenkins学习之路(四)之gitlab备份和恢复
gitlab的备份和恢复 (1)创建备份目录,并授权 [root@linux-node1 ~]# mkdir /data/backups/gitlab -p [root@linux-node1 ~]# ...
随机推荐
- JOptionPane.showMessageDialog出现在浏览器下面的解决方法
将JOptionPane.showMessageDialog(null, result, "发布公告:", JOptionPane.INFORMATION_MESSAGE);中的参 ...
- Spring(二) -- 春风拂面之 核心 AOP
”万物皆对象“是面向对象编程思想OOP(Object Oriented Programming) 的最高境界.在面向对象中,我一直将自己(开发者)放在一个至高无上的位置上,可以操纵万物(对象),犹如一 ...
- CentOS 7下ElasticSearch集群搭建案例
最近在网上看到很多ElasticSearch集群的搭建方法,本人在这人使用Elasticsearch5.0.1版本,介绍如何搭建ElasticSearch集群并安装head插件和其他插件安装方法. 一 ...
- 利用eclipse调试JDK源码
先看效果图 综合网上各种教程,总结如下 新建 D:/jdk/src .D:/jdk/debug 目录 src存放源码 debug存放编译结果 将 %JAVA_HOME%/src.zip 解压到 D:/ ...
- vscode常好用的插件以及几个快捷操作
使用方法,可以在官网中搜索需要的插件或者在VsCode的“”扩展“”中搜索需要的插件添加方法使用Ctrl+P, 输入 ext install xxxx ,搜索要安装的插件,点击安装按钮即可(各取所需插 ...
- Magento 多站点多域名安装教程(可以设置手机模版哟,亲 \(^o^)/)
这篇文章是安装magento子域名的教程,请先进行安装之前,确认以下几点: 1.请先确认子域名是否已经指向你的服务器 2.可以编辑.htaccess文件 3. 熟悉Cpanel操作 我们的目标是建立一 ...
- View Programming Guide for iOS
https://developer.apple.com/library/archive/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/Wi ...
- Understanding and Analyzing Application Crash Reports
Introduction When an application crashes, a crash report is created and stored on the device. Crash ...
- Masonry 原理与使用说明
原理: 1)约束生成:MASConstraintMaker: 2)缺省补齐: - (void)setSecondViewAttribute:(id)secondViewAttribute { if ( ...
- JS模拟CSS3动画-贝塞尔曲线
一.什么是贝塞尔曲线 1962年,法国工程师皮埃尔·贝塞尔(Pierre Bézier),贝塞尔曲线来为为解决汽车的主体的设计问题而发明了贝塞尔曲线.如今,贝赛尔曲线是计算机图形学中相当重要的一种曲线 ...