
正文
pg10数据库还原 restore还原数据库
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
如何对postgres的数据库进行覆盖式地恢复
可以在用pg_dump导出时加一个-c参数(是小写的c),表示clean,会有一些drop table命令在里面;也或者你每次dump出来恢复时把目标库整个删了重建一下,再psql导入
相关问答
Q1: postgresql 怎么还原数据库
还原需要原先对数据库进行过备份,才能从备份恢复,如果没有备份过,那是无法还原的。
恢复数据库,指令如下:
pg_restore.exe --host localhost --port 5432 --username "postgres" --dbname "symbolmcnew" --no-password --verbose "databasename.backup"
指令解释:如上命令,psql是恢复数据库命令,localhost是要恢复到哪个数据库的地址,当然你可以写上ip地址,也就是说能远程恢复(必须保证 数据库允许外部访问的权限哦~);postgres 就是要恢复到哪个数据库的用户;symbolmcnew 是要恢复到哪个数据库,databasename.backup指备份文件。
Q2: 怎么把pgsql备份的数据库附加还原
打开数据库的企业管理器,点击到数据库,
右键,里边有一项所有任务 可以附加数据库,
然后选择你的数据库pgsql的路径的mdf文件,确定就好
Q3: 如何用data文件夹恢复postgresql数据库
您好,举例说明:如将一Shapfile文件“c:\road.shp”导入到数据表“road”中,数据库为“sjzmap”。1、运行“命令提示符”。2、切换至PostgreSQL数据库安装目录中的bin目录下。3、执行此目录下的shp2pgsql命令:“shp2pgsqlc:\road.shproadc:\road.sql”。4、如将此文件直接导入数据库(不推荐):“shp2pgsql-cc:\road.shproadsjzmap|psql-dsjzmap”。5、使用pgAdmin3选择数据库,再导入表。注:DropsthedatabasetablebeforecreatinganewtablewiththedataintheShapefile.AppendsdatafromtheShapefileintothedatabasetable.Notethattousethisoptiontoloadmultiplefiles,thefilesmusthavethesameattributesandsamedatatypes.CreatesanewtableandpopulatesitfromtheShapefile.OnlyproducesthetablecreationSQLcode,withoutaddinganyactualdata.Thiscanbeusedifyouneedtocompletelyseparatethetablecreationanddataloadingsteps.UsethePostgreSQL"dump"formatfortheoutputdata.Thiscanbecombinedwith-a,-cand-d.Itismuchfastertoloadthanthedefault"insert"SQLformat.Usethisforverylargedatasets.CreatesandpopulatesthegeometrytableswiththespecifiedSRID.Keepidentifiers'case(column,schemaandattributes).NotethatattributesinShapefileareallUPPERCASE.Coerceallintegerstostandard32-bitintegers,donotcreate64-bitbigints,eveniftheDBFheadersignatureappearstowarrantit.CreateaGiSTindexonthegeometrycolumn.OutputWKTformat,forusewitholder(0.x)versionsofPostGIS.NotethatthiswillintroducecoordinatedriftsandwilldropMvaluesfromshapefiles.Specifyencodingoftheinputdata(dbffile).Whenused,allattributesofthedbfareconvertedfromthespecifiedencodingtoUTF8.TheresultingSQLoutputwillcontainacommand,sothatthebackendwillbeabletoreconvertfromUTF8towhateverencodingthedatabaseisconfiguredtouseinternally.
Q4: 如何利用pg_dumpall备份的文件,恢复数据库
一、把SQL2005数据库备份恢复到SQL2005数据库中二、在SQL2005数据库中生成脚本 1、选定数据库--右键--任务--生成脚本 2、下一步--选择数据库 3、下一步--找到“为服务器版本编写脚本”--选择“SQL Server 2000数据库” 4、选择“表”,逐步执行下一步三、执行脚本,在SQL2000数据库中生成数据库结构 1、将脚本文件传输到SQL2000数据库电脑 2、运行SQL 2000的查询分析器 3、将脚本内容复制到查询分析器中,执行脚本内容,生成数据库结构 四、导入数据 1、在SQL 2000数据库中,创建数据库 2、选定数据库--右键--所有任务--导入数据 3、选择数据源--选择服务器--选择数据库 4、选择目的 5、逐步执行下一步
Q5: 如何将阿里云RDS PgSQL恢复到本地主机中
1. 时间很好理解,其实就是触及这个时间后的XLOG中的第一个事务结束位置作为停止点。
2. 字符串,这个是需要通过pg_create_restore_point函数来创建的一个还原点,需要超级用户调用这个函数。
3. XID也很好理解,就是恢复到指定事务的结束位置。
既然我们已经知道了数据库可以恢复到指定的这几个位置,我们怎么来结合呢?
例如我们在做一笔比较重要的操作前,可以创建一个还原点(但是需要超级用户),不适合阿里云RDS。
postgres=# select pg_create_restore_point('digoal');
pg_create_restore_point
-------------------------
1D6/FB17EC08
(1 row)
阿里云为了防止一些用户的误操作,只开放了普通用户给用户使用,所以有一些东西都无法操作,例如创建检查点,切换XLOG,创建还原点都无法操作。
postgres= checkpoint;
ERROR: must be superuser to do CHECKPOINT
postgres= select pg_switch_xlog();
ERROR: must be superuser to switch transaction log files
postgres= select pg_create_restore_point('ab');
ERROR: must be superuser to create a restore point
时间其实是一个比较模糊的概念,所以也不建议使用,除非是我们没有其他信息,才使用时间。
XID是一个很不错的信息,我们在阿里云就用它了。
首先要创建一个记录还原点XID的表。记录XID,时间,以及描述信息。(来代替pg_create_restore_point系统函数的功能)
postgres= create table restore_point(id serial primary key, xid int8, crt_time timestamp default now(), point text);
CREATE TABLE
创建一个函数,代替pg_create_restore_point的功能,插入还原点。
postgres= create or replace function create_restore_point(i_point text) returns void as $$
declare
begin
insert into restore_point(xid,point) values (txid_current(),i_point);
end;
$$ language plpgsql strict;
CREATE FUNCTION
插入一个还原点
postgres= select create_restore_point('digoal');
create_restore_point
----------------------
(1 row)
查询这个表的信息:
postgres= select * from restore_point;
id | xid | crt_time | point
----+--------+----------------------------+--------
1 | 561426 | 2015-06-19 09:18:57.525475 | digoal
(1 row)
postgres= select * from restore_point where point='digoal';
id | xid | crt_time | point
----+--------+----------------------------+--------
1 | 561426 | 2015-06-19 09:18:57.525475 | digoal
(1 row)
接下来要模拟一下还原:
postgres= create table test(id int,info text);
CREATE TABLE
postgres= insert into test select generate_series(1,1000),md5(random()::text);
INSERT 0 1000
记录当前哈希值。用于恢复后的比对。
postgres= select sum(hashtext(t.*::text)) from test t;
sum
--------------
-69739904784
(1 row)
接下来我要做一笔删除操作,在删除前,我先创建一条还原点信息。
postgres= select create_restore_point('before delete test');
create_restore_point
----------------------
(1 row)
postgres= delete from test;
DELETE 1000
postgres= select * from restore_point where point='before delete test';
id | xid | crt_time | point
----+--------+----------------------------+--------------------
2 | 561574 | 2015-06-19 09:45:28.030295 | before delete test
(1 row)
我只需要恢复到561574 即可。接下来就是模拟恢复了。
但是这个文件可能还没有归档,而pg_switch_xlog()函数又不能用,我们只能主动产生一些XLOG,让RDS触发归档。
postgres= select pg_xlogfile_name(pg_current_xlog_location());
pg_xlogfile_name
--------------------------
000000010000000200000041
(1 row)
postgres= insert into test select generate_series(1,100000);
INSERT 0 100000
postgres= insert into test select generate_series(1,100000);
INSERT 0 100000
postgres= select pg_xlogfile_name(pg_current_xlog_location());
pg_xlogfile_name
--------------------------
000000010000000200000042
(1 row)
已经切换。接下来我们需要下载阿里云RDS的备份和归档到本地。
并且在本地需要安装一个postgresql, 并且与阿里云RDS的编译配置参数一致(例如数据块的大小),最好使用的模块也一致,但是这里没有用到其他模块,所以无所谓。
给阿里云RDS一个建议,最好提供用户一个软件打包,方便用户恢复,降低恢复门槛。
编译项可以使用pg_config命令查看,但是RDS我们没有办法这么查看。通过pg_settings来看吧。
postgres= select name,setting,unit from pg_settings where category='Preset Options';
name | setting | unit
-----------------------+---------+------
block_size | 8192 |
data_checksums | on |
integer_datetimes | on |
max_function_args | 100 |
max_identifier_length | 63 |
max_index_keys | 32 |
segment_size | 131072 | 8kB
server_version | 9.4.1 |
server_version_num | 90401 |
wal_block_size | 8192 |
wal_segment_size | 2048 | 8kB
(11 rows)
postgres= select version();
version
--------------------------------------------------------------------------------------------------------------
PostgreSQL 9.4.1 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.4.6 20110731 (Red Hat 4.4.6-3), 64-bit
(1 row)
本地编译安装PostgreSQL 9.4.1,编译参数与RDS一致。阿里云RDS这几个参数都是默认的。
--with-blocksize=BLOCKSIZE
set table block size in kB [8]
--with-segsize=SEGSIZE set table segment size in GB [1]
--with-wal-blocksize=BLOCKSIZE
set WAL block size in kB [8]
--with-wal-segsize=SEGSIZE
set WAL segment size in MB [16]
关于pg10数据库还原和restore还原数据库的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。






