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 ~]# ...
随机推荐
- Jax
The scope of this project is to automate the current Credit Correction process of opening, editing, ...
- 选择语言之switch case
程序语言-选择语言之switch case 多选一,类似if else if else if else 模版: Switch(选择条件) { Case(条件一)//相当于if Conso ...
- exe4j将可执行的jar封装成exe文件
1,将java项目打包成可执行的jar:https://www.cnblogs.com/3b2414/p/9355292.html, 2,下载好exe4j工具, 3,首先注册,如果你不注册,打包好的软 ...
- 解决FormClosing事件点击关闭2次的问题
以下代码:提示框会跳出2遍 private void mFrmmain_FormClosing(object sender, FormClosingEventArgs e) { if (Dialog ...
- IE 浏览器在地址栏输入中文字符,发送get请求报400错误的问题
因为学校有JavaWeb的课程,所以才接触这方面.最近遇到了个小问题. 先看一段很简单的jsp代码例子 <%@ page language="java" import=&qu ...
- Spring框架之控制反转和依赖注入
学Spring框架必须理解控制反转和依赖注入.下面各自举一个例子,来说明控制反转和依赖注入. IOC(控制反转):应用本身创建和维护的依赖对象:现在交由外部容器(Spring)来创建和维护:这个控制权 ...
- java正则表达式匹配字符
假设要匹配${2}中间为数字的这个类型的变量String,则 Pattern p = Pattern.compile("\\$\\{\\d+\\}"); Matcher m = p ...
- codeforces_455B
B. A Lot of Games time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Jmeter的面板介绍
一.jmeter面板介绍,这里是5.1.1版本 1.jmeter面板大致分为菜单区,图标区,目录树以及详细配置区域. 2.大多数人用着英文的面板不太舒服,可以在options里切换jmeter的语言 ...
- vba txt读写的几种方式
四种方式写txt 1.这种写出来的是ANSI格式的txt Dim TextExportFile As String TextExportFile = ThisWorkbook.Path & & ...