PostgreSQL中恢复被误删除的行数据

如果自己搞不定可以找诗檀软件专业PostgreSQL数据库修复团队成员帮您恢复!

诗檀软件专业数据库修复团队

服务热线 : 13764045638   QQ号:47079569    邮箱:service@parnassusdata.com

 

在PostgreSQL中如果误删除了行数据 要如何恢复呢?

例如下面的例子:

 

postgres=# create database test3;
CREATE DATABASE
postgres=# \c test3
您现在已经连接到数据库 "test3",用户 "postgres".

test3=# create table novels(name varchar(100), id int);
CREATE TABLE

test3=# select * from pg_database where datname='test3';
oid | datname | datdba | encoding | datcollate | datctype | datistemplate | 
datallowconn | datconnlimit | datlastsysoid | datfrozenxid | datminmxid | dattablespace | datacl
-------+---------+--------+----------+--------------------------------+--------------------------------+---------------+--------------+--------------+---------------+--------------+------------+---------------+--------
16432 | test3 | 10 | 6 | Chinese (Simplified)_China.936 | 
Chinese (Simplified)_China.936 | f | t | -1 | 13317 | 480 | 1 | 1663 |
(1 行记录)


test3=# select * from pg_class where relname='novels';
oid | relname | relnamespace | reltype | reloftype | relowner | relam | 
relfilenode | reltablespace | relpages | reltuples | relallvisible | 
reltoastrelid | relhasindex | relisshared | relpersistence | relkind | 
relnatts | relchecks | relhasrules | relhastriggers | relhassubclass | relrowsecurity | 
relforcerowsecurity | relispopulated | relreplident | relispartition | relrewrite | 
relfrozenxid | relminmxid | relacl | reloptions | relpartbound
-------+---------+--------------+---------+-----------+----------+-------+-------------+---------------+----------+-----------+---------------+---------------+-------------+-------------+----------------+---------+----------+-----------+-------------+----------------+----------------+----------------+---------------------+----------------+--------------+----------------+------------+--------------+------------+--------+------------+--------------
16433 | novels | 2200 | 16435 | 0 | 10 | 2 | 16433 | 0 | 0 | 0 | 0 | 0 | f | f | 
p | r | 2 | 0 | f | f | f | f | f | t | d | f | 0 | 612 | 1 | | |
(1 行记录)

test3=# select * from novels;
name | id
----------+----
三国演义 | 1
水浒传 | 2
红楼梦 | 3
西游记 | 4
(4 行记录)

cd $PGDATA


λ ls -l base432433
-rw-r--r-- 1 st 197121 0 11月 15 14:54 'base432433'


我们通过cat命令查看改文件 可以看到 其中内容

λ cat base432433
X$□| , 0 ♦ i ПX □□P □□P X□P 0□P i
♣ □)↑ 西游记 ♦ h i ♣ @♣↑ 西游记 ♥ g ♥ ↑ 红楼梦 ♥ f ↑ 水浒传 e ↑ □□国演义


如果我们尝试删除该表所有行:

test3=# delete from novels;
DELETE 4

再次用 cat 查看文件

λ cat base432433
X$□| , 0 ♦ i ПX □□P □□P X□P 0□P i
♣ □)↑ 西游记 ♦ h i ♣ @♣↑ 西游记 ♥ g ♥ ↑ 红楼梦 ♥ f ↑ 水浒传 e ↑ □□国演义


仍能看到数据 还存放于文件中 , 等待60s后

λ sleep 60
λ cat base432433
H'□| , 0 ♦ i ПX □□P □□P X□P 0□P i
j ♣ □!↑ 西游记 ♦ h i ♣ @♣↑ 西游记 ♥ g j ♥ ↑ 红楼梦 ♥ f j ↑ 水浒传 e j ↑ □□国演义



数据仍在没有被vacuum清除 ,如果我们尝试手动vacuum 该表,先备份

cp base432433 base432433.bak

然后 vacuum

test3=# vacuum novels;
VACUUM


cat base432433

再次验证可以看到 数据已经没了;

 

 

 

所以postgreSQL中对于没有备份的且被delete的行数据而言,是否能恢复 其主要取决于是否被auto vacuum了。

 

对于大表的大量删除一般会引发这种自动清理,而对于小表而言一般不会。

 

可以得出如下结论:

  1. 对于postgreSQL中的大规模delete操作,因为其将引发vacuum操作,从而导致其物理上不可能恢复
  2. 对于少量数据的delete操作,不会引发vacuum,其物理上存在恢复可能

 

 

至于 truncate / drop table 在postgreSQL 中是不太可能恢复的,其原因说明

 

postgresql之vacuum

来源:https://www.cnblogs.com/daduxiong/archive/2010/10/11/1847975.html

数据库总是不断地在执行删除,更新等操作。良好的空间管理非常重要,能够对性能带来大幅提高。在postgresql中用于维护数据库磁盘空间的工具是VACUUM,其重要的作用是删除那些已经标示为删除的数据并释放空间。
VACUUM语法结构:

VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ table ]
VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] ANALYZE [ table [ (column [, …] ) ] ]

 

postgresql中执行delete操作后,表中的记录只是被标示为删除状态,并没有释放空间,在以后的update或insert操作中该部分的空间是不能够被重用的。经过vacuum清理后,空间才能得到释放。可惜的是vacuum工具不能够对相应的索引进行清理,唯一的办法就是手动去重建相应索引(令人非常不爽,而高兴的是在9.0之后有所改进)。
Full Vacuum
full vacuum与单纯的vacuum还是有很大的区别的。vacuum只是将删除状态的空间释放掉,转换到能够重新使用的状态,但是对于系统来说该数据块的空闲空间并没有反应到系统的元数据中。类似oracle中高水位标记并没有下降。Full vacuum将会使空间释放的信息表现在系统级别,其实质是将当前删除记录后面的数据进行移动,使得整体的记录连贯起来,降低了“高水位标记”。
Vacuum analyze
analyze的功能是更新统计信息,使得优化器能够选择更好的方案执行sql。oracle中同样也有analyze,作用也相同,目前更多的使用的是dbms_stats包。统计信息收集和更新对于系统性能来说非常重要,与oracle维护类似,通常可以通过采用手动或者定制任务的方式。也有不同,oracle在进行imp后自动的对相应数据对象进行统计信息的收集和更新,而postgresql的恢复过程还没有集成到里面,需要手动去执行。
自动vacuum配置
自动vacuum的执行直接由autovacuum参数值决定,默认值是on。
log_autovacuum_min_duration:默认值为-1,关闭vacuum的日志记录,配置为0表示记录autovacuum的所有log。参数设置为正整数表示对于在此时间内完成的vacuum操作不进行log记录,如果没能完成,则记录超出时间内的log。该参数对于了解对象执行vacuum操作的时间非常有用。
autovacuum_max_workers:最大的autovacuum进程的数量,默认值为3。参数大小的配置主要依据系统当前负载和资源。对于系统负载较重的情况,建议开启少量的进程为好,反之,空闲时间可以采用较大值的方式。
autovacuum_naptime:检查数据库的时间间隔。默认为1分钟。
autovacuum_vacuum_threshold:参数表示执行autovacuum操作之前,对单个表中记录执行DML操作的最少行数。达到该行数时自动激活autovacuum操作。该参数针对数据库中的所有表,还可以通过对单个表配置不同的值来改变相应表的autovacuum操作。默认值是50。
autovacuum_analyze_threshold:激活自动analyze操作的最小行数。默认值50。机制与上面相同。
autovacuum_vacuum_scale_factor:该参数采用百分比的方式设定阀值。默认值为20%,当DML涉及的数据量大于某个表的20%时,自动触发autovacuum操作。同样可以通过对单个表进行阀值设定。
autovacuum_analyze_scale_factor:机制与上面相同,到达阀值是自动激活analyze操作。同样可以通过对单个表进行阀值设定。
autovacuum_freeze_max_age:为防止事务ID的重置,在启用vacuum操作之前,表的pg_class .relfrozenxid字段的最大值,默认为200万。
autovacuum_vacuum_cost_delay:autovacuum进程的时间延迟限制,默认值是20ms。对于单个表同样适用。
autovacuum_vacuum_cost_limit:autovacuum进程的开销延迟限制,默认值是-1,表示不进行开销限制,系统将会直接依据vacuum_cost_limit参数管理vacuum的开销。对于单个表同样适用。

 

通过了解vacuum,能够更清楚postgresql是如何进行系统维护的,其中最为重要的是索引的维护,因为8.3中还不能对索引同时进行维护,这在实际的使用中需要耗费较大的精力,还好在9.0版本中有所改进(具体情况没有测试)。同时大致了解postgresql进行自动vacuum操作的机制与过程。

PostgreSQL 之 autovacuum的触发条件

本文链接:https://blog.csdn.net/pg_hgdb/article/details/79707659

autovacuum 是 postgresql 里非常重要的一个服务端进程,能够自动地执行,在一定条件下自动地对 dead tuples 进行清理并对表进行分析

autovacuum参数控制 autovacuum 进程是否打开,默认为 “on”

 

根据postgresql.conf相关配置,理解autovacuum会在两种情况下会被触发:

1.表上(update,delte 记录) >= autovacuum_vacuum_scale_factor* reltuples(表上记录数) + autovacuum_vacuum_threshold

 

说明:

清理基本阈值是autovacuum_vacuum_threshold

清理的缩放系数是autovacuum_vacuum_scale_factor

元组的数目是 reltuples 可以从统计收集器里面获取,参考sql如下:

SELECT reltuples from pg_class WHERE relkind = ‘r’ AND relname = ‘test’;

 

2.指定表上事务的最大年龄配置参数autovacuum_freeze_max_age,默认为2亿,达到这个阀值将触发 autovacuum进程,从而避免 wraparound。

表上的事务年龄可以通过 pg_class.relfrozenxid查询。
–例如,查询表 test_1 的事务年龄
select relname,age(relfrozenxid) from pg_class where relname=’test_1′;
 relname |   age    
———+———-
 test_1  | 14208876
(1 row)

 

 

附:相关参数说明

autovacuum:是否启动系统自动清理功能,默认值为on。

autovacuum_max_workers:设置系统自动清理工作进程的最大数量。

autovacuum_naptime:设置两次系统自动清理操作之间的间隔时间。

autovacuum_vacuum_threshold和autovacuum_analyze_threshold:设置当表上被更新的元组数的阈值超过这些阈值时分别需要执行vacuum和analyze。

autovacuum_vacuum_scale_factor设置表大小的缩放系数。

autovacuum_freeze_max_age:设置需要强制对数据库进行清理的XID上限值。

 

更多详细内容参见如下:

https://www.postgresql.org/docs/9.6/static/runtime-config-autovacuum.html

 

autovacuum_vacuum_threshold (integer)

Specifies the minimum number of updated or deleted tuples needed to trigger a VACUUM in any one table. The default is 50 tuples. This parameter can only be set in the postgresql.conffile or on the server command line; but the setting can be overridden for individual tables by changing table storage parameters.

 

autovacuum_analyze_threshold (integer)

Specifies the minimum number of inserted, updated or deleted tuples needed to trigger an ANALYZE in any one table. The default is 50 tuples. This parameter can only be set in the postgresql.conf file or on the server command line; but the setting can be overridden for individual tables by changing table storage parameters.

 

autovacuum_vacuum_scale_factor (floating point)

Specifies a fraction of the table size to add to autovacuum_vacuum_threshold when deciding whether to trigger a VACUUM. The default is 0.2 (20% of table size). This parameter can only be set in the postgresql.conf file or on the server command line; but the setting can be overridden for individual tables by changing table storage parameters.

 

autovacuum_freeze_max_age (integer)

Specifies the maximum age (in transactions) that a table’s pg_class.relfrozenxid field can attain before a VACUUM operation is forced to prevent transaction ID wraparound within the table. Note that the system will launch autovacuum processes to prevent wraparound even when autovacuum is otherwise disabled.

Vacuum also allows removal of old files from the pg_clog subdirectory, which is why the default is a relatively low 200 million transactions. This parameter can only be set at server start, but the setting can be reduced for individual tables by changing table storage parameters. For more information see Section 24.1.5.
 

PostgreSQL源码分析AutoVacuum机制之autovacuum launcher

来源:http://mysql.taobao.org/monthly/2017/12/04/

背景

根据之前月报的分析,PostgreSQL中的MVCC机制(详见月报)同时存储新旧版本的元组,对于经常更新的表来说,会造成表膨胀的情况。为了解决这个问题,PostgreSQL 引入了VACUUMANALYZE命令,并且引入了AutoVacuum自动清理。

在PostgreSQL中,AutoVacuum自动清理操作包括:

  • 删除或重用无效元组的磁盘空间
  • 更新数据统计信息,保证执行计划更优
  • 更新visibility map,加速index-only scans (详见文档
  • 避免XID 回卷造成的数据丢失(详见文档

为了实现自动清理,PostgreSQL引入了两种类型的辅助进程:

  • autovacuum launcher
  • autovacuum worker

本文主要分析autovacuum launcher进程相关操作,autovacuum worker比较复杂和重要,我们将在下期月报详细分析。

autovacuum launcher

autovacuum launcher 进程可以理解为AutoVacuum机制的守护进程,周期性地调度autovacuum worker进程。

相关参数

autovacuum launcher 进程在postgresql.conf文件中的相关配置参数(支持对每个表单独配置参数,方法见文档)如下:

  • track_counts:是否开启统计信息收集功能。
  • autovacuum:是否启动系统自动清理功能,默认值为on。
  • autovacuum_max_workers:设置系统自动清理工作进程的最大数量。
  • autovacuum_naptime:设置两次系统自动清理操作之间的间隔时间。
  • autovacuum_vacuum_cost_limit:声明将在自动VACUUM操作里使用的开销限制数值。
  • autovacuum_vacuum_cost_delay :声明如果超过了上面的开销限制,则需要延迟清理的时间。
  • autovacuum_freeze_max_age:设置需要强制对数据库进行清理的XID上限值。
  • autovacuum_multixact_freeze_max_age:设置需要强制对数据库进行清理的multi XID上限值。

因为AutoVacuum依赖于统计信息,所以只有track_counts=on 且autovacuum=on 时,PostgreSQL才启动autovacuum launcher 进程。

autovacuum launcher 进程会周期性地创建autovacuum worker 进程,最多能够创建autovacuum_max_workers个autovacuum worker 进程。我们将会从下面二个方面来分析autovacuum launcher:

  • 执行周期,即autovacuum launcher进程的休眠时间
  • autovacuum worker 调度管理

执行周期

上文的参数autovacuum_naptime决定了autovacuum launcher 的基本执行周期。在PostgreSQL中,理想状态是在autovacuum_naptime的时间内对所有的数据库进行一次清理,即每个数据库希望能够分配到autovacuum_naptime/(数据库的个数) 的时间片去创建一个autovacuum worker进行自动清理。这就要求autovacuum launcher 进程每经过autovacuum_naptime/(数据库的个数) 的时间就要被唤醒,并启动对应的autovacuum worker 进程。

基于此设计思想,autovacuum launcher 进程中维护了一个数据库列表DatabaseList,其中维护了各个database的期望AutoVacuum时间等信息,具体的元素结构如下:

/* struct to keep track of databases in launcher */
typedef struct avl_dbase
{
	Oid			adl_datid;		/* hash key -- must be first */
	TimestampTz adl_next_worker;
	int			adl_score;
	dlist_node	adl_node;
} avl_dbase;

其中:

  • adl_datid 表示对应database oid,是该Hash表结构的key
  • TimestampTz 表示该database下次将要进行AutoVacuum的时间
  • adl_score 表示该database对应的分值,该分值决定该database启动worker 的时间
  • adl_node 表示该avl_dbase对应的在列表中的位置信息包括:
struct dlist_node
{
	dlist_node *prev;
	dlist_node *next;
};

当autovacuum launcher初始化时,DatabaseList为空,需要重建,具体步骤如下:

  • 刷新统计信息
  • 建立一个Hash表dbhash存储adl_datid,即数据库ID和avl_dbase(上面的结构体)的对应关系
  • 获取当前所有的数据库和数据库的统计信息,如果存在统计信息且不存在dbhash中,则插入到dbhash中,并将其avl_dbase->adl_score加1,adl_score最后统计存在统计信息且不存在dbhash中的database数量
  • 将Hash 表中的avl_dbase按照adl_score排序,按照顺序给每个database的adl_next_worker赋值为当前时间+每个数据库分到的时间片*其在列表中的顺序。其中每个数据库分到的时间片= autovacuum_naptime/adl_score

可以看出,创建完成之后,DatabaseList中存储按照期望执行自动化清理的时间从大到小排序的数据库信息。

通过分析代码发现,autovacuum launcher进程的执行周期主要是由launcher_determine_sleep 函数来决定的:

  1. 如果autovacuum worker 空闲列表(详见下文autovacuum worker 管理中的分析)为空,autovacuum launcher进程睡眠autovacuum_naptime 后唤醒,否则进行下面的判断
  2. 如果当前DatabaseList不为空,则将DatabaseList列表尾部的数据库期望AutoVacuum的时间戳作为下次唤醒的时间
  3. 除上面之外的情况,用autovacuum_naptime作为执行周期

如果当前的时间已经晚于第2种情况得到的时间戳,则纠正为autovacuum launcher最小的休眠时间100ms。

综上所述,我们知道:

  • autovacuum launcher 基本周期是autovacuum_naptime。如果当前不存在空闲的autovacuum worker,则休眠autovacuum_naptime
  • 在一个autovacuum_naptime工作周期里,每个database 数据库期望占用autovacuum_naptime/adl_score 时间(adl_score可以简单理解为当前存在统计信息的database总数),当该时间到达时,launch a worker,自动清理该数据库

autovacuum worker 管理

因为AutoVacuum的具体过程会消耗数据库资源(比如CPU),可能影响性能,在PostgreSQL中规定,autovacuum launcher可以启动最多autovacuum_max_workers个autovacuum worker 进程。为了管理autovacuum worker 进程,PostgreSQL维护了共享内存AutoVacuumShmemStruct来存储当前所有autovacuum worker的情况,其结构如下:

typedef struct
{
	sig_atomic_t av_signal[AutoVacNumSignals];
	pid_t		av_launcherpid;
	dlist_head	av_freeWorkers;
	dlist_head	av_runningWorkers;
	WorkerInfo	av_startingWorker;
	AutoVacuumWorkItem av_workItems[NUM_WORKITEMS];
} AutoVacuumShmemStruct;

其中:

  • av_signal目前是由长度为2的int 数组组成,分别用0,1来表示是否启动worker失败,是否需要重新计算对每个autovacuum worker 的资源限制
  • av_launcherpid代表autovacuum launcher 的pid
  • av_freeWorkers代表空闲的autovacuum woker 相应的WorkerInfoData 列表,WorkerInfoData的具体结构如下:
/*-------------
 * This struct holds information about a single worker's whereabouts.  We keep
 * an array of these in shared memory, sized according to
 * autovacuum_max_workers.
 *
 * wi_links		entry into free list or running list
 * wi_dboid		OID of the database this worker is supposed to work on
 * wi_tableoid	OID of the table currently being vacuumed, if any
 * wi_sharedrel flag indicating whether table is marked relisshared
 * wi_proc		pointer to PGPROC of the running worker, NULL if not started
 * wi_launchtime Time at which this worker was launched
 * wi_cost_*	Vacuum cost-based delay parameters current in this worker
 *
 * All fields are protected by AutovacuumLock, except for wi_tableoid which is
 * protected by AutovacuumScheduleLock (which is read-only for everyone except
 * that worker itself).
 *-------------
 */
typedef struct WorkerInfoData
{
	dlist_node	wi_links;
	Oid			wi_dboid;
	Oid			wi_tableoid;
	PGPROC	   *wi_proc;
	TimestampTz wi_launchtime;
	bool		wi_dobalance;
	bool		wi_sharedrel;
	int			wi_cost_delay;
	int			wi_cost_limit;
	int			wi_cost_limit_base;
} WorkerInfoData;
  • av_runningWorkers代表正在运行的autovacuum woker 相应的WorkerInfoData 列表
  • av_startingWorker代表正在启动的autovacuum woker 相应的WorkerInfoData
  • av_workItems存储着一组(256个)AutoVacuumWorkItem。AutoVacuumWorkItem存储着每个autovacuum worker的item 信息。

从上面可以看出,autovacuum launcher中维护三种不同状态的autovacuum worker 进程列表:

  • 空闲的autovacuum worker进程列表
  • 正在启动的autovacuum worker进程
  • 运行中的autovacuum worker进程列表

autovacuum launcher 通过维护AutoVacuumShmemStruct的信息,达到调度autovacuum worker的作用,具体如下:

  • 初始化共享内存时,初始化长度为autovacuum_max_workers的空闲autovacuum worker进程列表。
  • 如果autovacuum launcher进程需要一个worker进程,空闲列表为不空且没有启动中的autovacuum worker进程,则启动一个autovacuum worker进程,并从空闲列表取出一个autovacuum worker 进程,将共享内存中的av_startingWorker赋值为该autovacuum worker的WorkerInfoData。
  • 如果autovacuum worker启动成功,将该autovacuum worker 的WorkerInfoData放入共享内存的av_runningWorkers列表中。
  • autovacuum worker进程退出,将该autovacuum worker 的WorkerInfoData放入共享内存的av_freeWorkers列表中

其中需要注意的是autovacuum launcher进程中只允许存在一个“启动中”状态的autovacuum worker进程,如果启动超时(状态一直为“启动中”时间超过autovacuum_naptime)将被取消启动。autovacuum launcher进程调用launch_worker函数来选择一个database,并为其启动相应的autovacuum worker。launch_worker主要做两件事情:

  • 选取合适的database,并且向postmaster 发送信号创建worker进程
  • 更新该database的期望autovaccum的时间为当前时间+autovacuum_naptime/adl_score

其中,符合下面条件的database将会启动一个worker,进行自动清理:

  • 数据库的最大xid超过配置的autovacuum_freeze_max_age或者最大multixact超过autovacuum_multixact_freeze_max_age。
  • 没有符合上面条件的数据库,则选择数据库列表中最长时间未执行过自动清理操作的数据库。

至此,我们可以概括出autovacuum launcher的大致操作:

  • 调用函数rebuild_database_list,初始化时DatabaseList。DatabaseList保存每个database的laucher期望运行时间等信息
  • 设置进程休眠时间。根据空闲autovacuum worker列表和数据库列表DatabaseList来计算休眠的时间。同时autovacuum launcher休眠也可以被其他信号中断。
  • 处理失败的autovacuum worker进程列表,重新向Postmaster发送信号创建autovacuum worker进程。
  • 处理一直启动的autovacuum worker进程,如果超时,则重置该autovacuum worker信息。
  • 如果DatabaseList为空或者当前时间已经晚于DatabaseList中存储的各个数据库的期望执行autovacuum的最早时间,则会调用launch_worker。launch_worker会去选择合适的数据库并向Postmaster发送信号创建autovacuum worker进程。

总结

经过上面的分析,我们可以得出以下结论:

  • 优先对xid或者multixact 超限的数据库进行自动清理
  • 越长时间没有经过自动清理的数据库优先被清理
  • autovacuum launcher两次启动autovacuum worker的时间间隔不会大于autovacuum_naptime
  • 最多只能启动autovacuum_max_workers个autovacuum worker 进程

除此之外,autovacuum launcher中还涉及到对各个autovacuum_worker的资源限制,这部分内容我们将会和autovacuum_worker进程一起在下次月报进行分析。

PostgreSQL 参数列表





postgres=# SHOW all;
                  name                  |                       setting                       |                                                          description
----------------------------------------+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------
 allow_system_table_mods                | off                                                 | Allows modifications of the structure of system tables.
 application_name                       | psql                                                | Sets the application name to be reported in statistics and logs.
 archive_cleanup_command                |                                                     | Sets the shell command that will be executed at every restart point.
 archive_command                        | (disabled)                                          | Sets the shell command that will be called to archive a WAL file.
 archive_mode                           | off                                                 | Allows archiving of WAL files using archive_command.
 archive_timeout                        | 0                                                   | Forces a switch to the next WAL file if a new file has not been started within N seconds.
 array_nulls                            | on                                                  | Enable input of NULL elements in arrays.
 authentication_timeout                 | 1min                                                | Sets the maximum allowed time to complete client authentication.
 autovacuum                             | on                                                  | Starts the autovacuum subprocess.
 autovacuum_analyze_scale_factor        | 0.1                                                 | Number of tuple inserts, updates, or deletes prior to analyze as a fraction of reltuples.
 autovacuum_analyze_threshold           | 50                                                  | Minimum number of tuple inserts, updates, or deletes prior to analyze.
 autovacuum_freeze_max_age              | 200000000                                           | Age at which to autovacuum a table to prevent transaction ID wraparound.
 autovacuum_max_workers                 | 3                                                   | Sets the maximum number of simultaneously running autovacuum worker processes.
 autovacuum_multixact_freeze_max_age    | 400000000                                           | Multixact age at which to autovacuum a table to prevent multixact wraparound.
 autovacuum_naptime                     | 1min                                                | Time to sleep between autovacuum runs.
 autovacuum_vacuum_cost_delay           | 2ms                                                 | Vacuum cost delay in milliseconds, for autovacuum.
 autovacuum_vacuum_cost_limit           | -1                                                  | Vacuum cost amount available before napping, for autovacuum.
 autovacuum_vacuum_scale_factor         | 0.2                                                 | Number of tuple updates or deletes prior to vacuum as a fraction of reltuples.
 autovacuum_vacuum_threshold            | 50                                                  | Minimum number of tuple updates or deletes prior to vacuum.
 autovacuum_work_mem                    | -1                                                  | Sets the maximum memory to be used by each autovacuum worker process.
 backend_flush_after                    | 0                                                   | Number of pages after which previously performed writes are flushed to disk.
 backslash_quote                        | safe_encoding                                       | Sets whether "\'" is allowed in string literals.
 bgwriter_delay                         | 200ms                                               | Background writer sleep time between rounds.
 bgwriter_flush_after                   | 0                                                   | Number of pages after which previously performed writes are flushed to disk.
 bgwriter_lru_maxpages                  | 100                                                 | Background writer maximum number of LRU pages to flush per round.
 bgwriter_lru_multiplier                | 2                                                   | Multiple of the average buffer usage to free per round.
 block_size                             | 8192                                                | Shows the size of a disk block.
 bonjour                                | off                                                 | Enables advertising the server via Bonjour.
 bonjour_name                           |                                                     | Sets the Bonjour service name.
 bytea_output                           | hex                                                 | Sets the output format for bytea.
 check_function_bodies                  | on                                                  | Check function bodies during CREATE FUNCTION.
 checkpoint_completion_target           | 0.5                                                 | Time spent flushing dirty buffers during checkpoint, as fraction of checkpoint interval.
 checkpoint_flush_after                 | 0                                                   | Number of pages after which previously performed writes are flushed to disk.
 checkpoint_timeout                     | 5min                                                | Sets the maximum time between automatic WAL checkpoints.
 checkpoint_warning                     | 30s                                                 | Enables warnings if checkpoint segments are filled more frequently than this.
 client_encoding                        | GBK                                                 | Sets the client's character set encoding.
 client_min_messages                    | notice                                              | Sets the message levels that are sent to the client.
 cluster_name                           |                                                     | Sets the name of the cluster, which is included in the process title.
 commit_delay                           | 0                                                   | Sets the delay in microseconds between transaction commit and flushing WAL to disk.
 commit_siblings                        | 5                                                   | Sets the minimum concurrent open transactions before performing commit_delay.
 config_file                            | S:/Program Files/PostgreSQL/12/data/postgresql.conf | Sets the server's main configuration file.
 constraint_exclusion                   | partition                                           | Enables the planner to use constraints to optimize queries.
 cpu_index_tuple_cost                   | 0.005                                               | Sets the planner's estimate of the cost of processing each index entry during an index scan.
 cpu_operator_cost                      | 0.0025                                              | Sets the planner's estimate of the cost of processing each operator or function call.
 cpu_tuple_cost                         | 0.01                                                | Sets the planner's estimate of the cost of processing each tuple (row).
 cursor_tuple_fraction                  | 0.1                                                 | Sets the planner's estimate of the fraction of a cursor's rows that will be retrieved.
 data_checksums                         | off                                                 | Shows whether data checksums are turned on for this cluster.
 data_directory                         | S:/Program Files/PostgreSQL/12/data                 | Sets the server's data directory.
 data_directory_mode                    | 0700                                                | Mode of the data directory.
 data_sync_retry                        | off                                                 | Whether to continue running after a failure to sync data files.
 DateStyle                              | ISO, YMD                                            | Sets the display format for date and time values.
 db_user_namespace                      | off                                                 | Enables per-database user names.
 deadlock_timeout                       | 1s                                                  | Sets the time to wait on a lock before checking for deadlock.
 debug_assertions                       | off                                                 | Shows whether the running server has assertion checks enabled.
 debug_pretty_print                     | on                                                  | Indents parse and plan tree displays.
 debug_print_parse                      | off                                                 | Logs each query's parse tree.
 debug_print_plan                       | off                                                 | Logs each query's execution plan.
 debug_print_rewritten                  | off                                                 | Logs each query's rewritten parse tree.
 default_statistics_target              | 100                                                 | Sets the default statistics target.
 default_table_access_method            | heap                                                | Sets the default table access method for new tables.
 default_tablespace                     |                                                     | Sets the default tablespace to create tables and indexes in.
 default_text_search_config             | pg_catalog.simple                                   | Sets default text search configuration.
 default_transaction_deferrable         | off                                                 | Sets the default deferrable status of new transactions.
 default_transaction_isolation          | read committed                                      | Sets the transaction isolation level of each new transaction.
 default_transaction_read_only          | off                                                 | Sets the default read-only status of new transactions.
 dynamic_library_path                   | $libdir                                             | Sets the path for dynamically loadable modules.
 dynamic_shared_memory_type             | windows                                             | Selects the dynamic shared memory implementation used.
 effective_cache_size                   | 4GB                                                 | Sets the planner's assumption about the total size of the data caches.
 effective_io_concurrency               | 0                                                   | Number of simultaneous requests that can be handled efficiently by the disk subsystem.
 enable_bitmapscan                      | on                                                  | Enables the planner's use of bitmap-scan plans.
 enable_gathermerge                     | on                                                  | Enables the planner's use of gather merge plans.
 enable_hashagg                         | on                                                  | Enables the planner's use of hashed aggregation plans.
 enable_hashjoin                        | on                                                  | Enables the planner's use of hash join plans.
 enable_indexonlyscan                   | on                                                  | Enables the planner's use of index-only-scan plans.
 enable_indexscan                       | on                                                  | Enables the planner's use of index-scan plans.
 enable_material                        | on                                                  | Enables the planner's use of materialization.
 enable_mergejoin                       | on                                                  | Enables the planner's use of merge join plans.
 enable_nestloop                        | on                                                  | Enables the planner's use of nested-loop join plans.
 enable_parallel_append                 | on                                                  | Enables the planner's use of parallel append plans.
 enable_parallel_hash                   | on                                                  | Enables the planner's use of parallel hash plans.
 enable_partition_pruning               | on                                                  | Enables plan-time and run-time partition pruning.
 enable_partitionwise_aggregate         | off                                                 | Enables partitionwise aggregation and grouping.
 enable_partitionwise_join              | off                                                 | Enables partitionwise join.
 enable_seqscan                         | on                                                  | Enables the planner's use of sequential-scan plans.
 enable_sort                            | on                                                  | Enables the planner's use of explicit sort steps.
 enable_tidscan                         | on                                                  | Enables the planner's use of TID scan plans.
 escape_string_warning                  | on                                                  | Warn about backslash escapes in ordinary string literals.
 event_source                           | PostgreSQL                                          | Sets the application name used to identify PostgreSQL messages in the event log.
 exit_on_error                          | off                                                 | Terminate session on any error.
 external_pid_file                      |                                                     | Writes the postmaster PID to the specified file.
 extra_float_digits                     | 1                                                   | Sets the number of digits displayed for floating-point values.
 force_parallel_mode                    | off                                                 | Forces use of parallel query facilities.
 from_collapse_limit                    | 8                                                   | Sets the FROM-list size beyond which subqueries are not collapsed.
 fsync                                  | on                                                  | Forces synchronization of updates to disk.
 full_page_writes                       | on                                                  | Writes full pages to WAL when first modified after a checkpoint.
 geqo                                   | on                                                  | Enables genetic query optimization.
 geqo_effort                            | 5                                                   | GEQO: effort is used to set the default for other GEQO parameters.
 geqo_generations                       | 0                                                   | GEQO: number of iterations of the algorithm.
 geqo_pool_size                         | 0                                                   | GEQO: number of individuals in the population.
 geqo_seed                              | 0                                                   | GEQO: seed for random path selection.
 geqo_selection_bias                    | 2                                                   | GEQO: selective pressure within the population.
 geqo_threshold                         | 12                                                  | Sets the threshold of FROM items beyond which GEQO is used.
 gin_fuzzy_search_limit                 | 0                                                   | Sets the maximum allowed result for exact search by GIN.
 gin_pending_list_limit                 | 4MB                                                 | Sets the maximum size of the pending list for GIN index.
 hba_file                               | S:/Program Files/PostgreSQL/12/data/pg_hba.conf     | Sets the server's "hba" configuration file.
 hot_standby                            | on                                                  | Allows connections and queries during recovery.
 hot_standby_feedback                   | off                                                 | Allows feedback from a hot standby to the primary that will avoid query conflicts.
 huge_pages                             | try                                                 | Use of huge pages on Linux or Windows.
 ident_file                             | S:/Program Files/PostgreSQL/12/data/pg_ident.conf   | Sets the server's "ident" configuration file.
 idle_in_transaction_session_timeout    | 0                                                   | Sets the maximum allowed duration of any idling transaction.
 ignore_checksum_failure                | off                                                 | Continues processing after a checksum failure.
 ignore_system_indexes                  | off                                                 | Disables reading from system indexes.
 integer_datetimes                      | on                                                  | Datetimes are integer based.
 IntervalStyle                          | postgres                                            | Sets the display format for interval values.
 jit                                    | on                                                  | Allow JIT compilation.
 jit_above_cost                         | 100000                                              | Perform JIT compilation if query is more expensive.
 jit_debugging_support                  | off                                                 | Register JIT compiled function with debugger.
 jit_dump_bitcode                       | off                                                 | Write out LLVM bitcode to facilitate JIT debugging.
 jit_expressions                        | on                                                  | Allow JIT compilation of expressions.
 jit_inline_above_cost                  | 500000                                              | Perform JIT inlining if query is more expensive.
 jit_optimize_above_cost                | 500000                                              | Optimize JITed functions if query is more expensive.
 jit_profiling_support                  | off                                                 | Register JIT compiled function with perf profiler.
 jit_provider                           | llvmjit                                             | JIT provider to use.
 jit_tuple_deforming                    | on                                                  | Allow JIT compilation of tuple deforming.
 join_collapse_limit                    | 8                                                   | Sets the FROM-list size beyond which JOIN constructs are not flattened.
 krb_caseins_users                      | off                                                 | Sets whether Kerberos and GSSAPI user names should be treated as case-insensitive.
 krb_server_keyfile                     |                                                     | Sets the location of the Kerberos server key file.
 lc_collate                             | Chinese (Simplified)_China.936                      | Shows the collation order locale.
 lc_ctype                               | Chinese (Simplified)_China.936                      | Shows the character classification and case conversion locale.
 lc_messages                            | Chinese (Simplified)_China.936                      | Sets the language in which messages are displayed.
 lc_monetary                            | Chinese (Simplified)_China.936                      | Sets the locale for formatting monetary amounts.
 lc_numeric                             | Chinese (Simplified)_China.936                      | Sets the locale for formatting numbers.
 lc_time                                | Chinese (Simplified)_China.936                      | Sets the locale for formatting date and time values.
 listen_addresses                       | *                                                   | Sets the host name or IP address(es) to listen to.
 lo_compat_privileges                   | off                                                 | Enables backward compatibility mode for privilege checks on large objects.
 local_preload_libraries                |                                                     | Lists unprivileged shared libraries to preload into each backend.
 lock_timeout                           | 0                                                   | Sets the maximum allowed duration of any wait for a lock.
 log_autovacuum_min_duration            | -1                                                  | Sets the minimum execution time above which autovacuum actions will be logged.
 log_checkpoints                        | off                                                 | Logs each checkpoint.
 log_connections                        | off                                                 | Logs each successful connection.
 log_destination                        | stderr                                              | Sets the destination for server log output.
 log_directory                          | log                                                 | Sets the destination directory for log files.
 log_disconnections                     | off                                                 | Logs end of a session, including duration.
 log_duration                           | off                                                 | Logs the duration of each completed SQL statement.
 log_error_verbosity                    | default                                             | Sets the verbosity of logged messages.
 log_executor_stats                     | off                                                 | Writes executor performance statistics to the server log.
 log_file_mode                          | 0640                                                | Sets the file permissions for log files.
 log_filename                           | postgresql-%Y-%m-%d_%H%M%S.log                      | Sets the file name pattern for log files.
 log_hostname                           | off                                                 | Logs the host name in the connection logs.
 log_line_prefix                        | %m [%p]                                             | Controls information prefixed to each log line.
 log_lock_waits                         | off                                                 | Logs long lock waits.
 log_min_duration_statement             | -1                                                  | Sets the minimum execution time above which statements will be logged.
 log_min_error_statement                | error                                               | Causes all statements generating error at or above this level to be logged.
 log_min_messages                       | warning                                             | Sets the message levels that are logged.
 log_parser_stats                       | off                                                 | Writes parser performance statistics to the server log.
 log_planner_stats                      | off                                                 | Writes planner performance statistics to the server log.
 log_replication_commands               | off                                                 | Logs each replication command.
 log_rotation_age                       | 1d                                                  | Automatic log file rotation will occur after N minutes.
 log_rotation_size                      | 10MB                                                | Automatic log file rotation will occur after N kilobytes.
 log_statement                          | none                                                | Sets the type of statements logged.
 log_statement_stats                    | off                                                 | Writes cumulative performance statistics to the server log.
 log_temp_files                         | -1                                                  | Log the use of temporary files larger than this number of kilobytes.
 log_timezone                           | GMT                                                 | Sets the time zone to use in log messages.
 log_transaction_sample_rate            | 0                                                   | Set the fraction of transactions to log for new transactions.
 log_truncate_on_rotation               | off                                                 | Truncate existing log files of same name during log rotation.
 logging_collector                      | on                                                  | Start a subprocess to capture stderr output and/or csvlogs into log files.
 maintenance_work_mem                   | 64MB                                                | Sets the maximum memory to be used for maintenance operations.
 max_connections                        | 100                                                 | Sets the maximum number of concurrent connections.
 max_files_per_process                  | 1000                                                | Sets the maximum number of simultaneously open files for each server process.
 max_function_args                      | 100                                                 | Shows the maximum number of function arguments.
 max_identifier_length                  | 63                                                  | Shows the maximum identifier length.
 max_index_keys                         | 32                                                  | Shows the maximum number of index keys.
 max_locks_per_transaction              | 64                                                  | Sets the maximum number of locks per transaction.
 max_logical_replication_workers        | 4                                                   | Maximum number of logical replication worker processes.
 max_parallel_maintenance_workers       | 2                                                   | Sets the maximum number of parallel processes per maintenance operation.
 max_parallel_workers                   | 8                                                   | Sets the maximum number of parallel workers that can be active at one time.
 max_parallel_workers_per_gather        | 2                                                   | Sets the maximum number of parallel processes per executor node.
 max_pred_locks_per_page                | 2                                                   | Sets the maximum number of predicate-locked tuples per page.
 max_pred_locks_per_relation            | -2                                                  | Sets the maximum number of predicate-locked pages and tuples per relation.
 max_pred_locks_per_transaction         | 64                                                  | Sets the maximum number of predicate locks per transaction.
 max_prepared_transactions              | 0                                                   | Sets the maximum number of simultaneously prepared transactions.
 max_replication_slots                  | 10                                                  | Sets the maximum number of simultaneously defined replication slots.
 max_stack_depth                        | 2MB                                                 | Sets the maximum stack depth, in kilobytes.
 max_standby_archive_delay              | 30s                                                 | Sets the maximum delay before canceling queries when a hot standby server is processing archived WAL data.
 max_standby_streaming_delay            | 30s                                                 | Sets the maximum delay before canceling queries when a hot standby server is processing streamed WAL data.
 max_sync_workers_per_subscription      | 2                                                   | Maximum number of table synchronization workers per subscription.
 max_wal_senders                        | 10                                                  | Sets the maximum number of simultaneously running WAL sender processes.
 max_wal_size                           | 1GB                                                 | Sets the WAL size that triggers a checkpoint.
 max_worker_processes                   | 8                                                   | Maximum number of concurrent worker processes.
 min_parallel_index_scan_size           | 512kB                                               | Sets the minimum amount of index data for a parallel scan.
 min_parallel_table_scan_size           | 8MB                                                 | Sets the minimum amount of table data for a parallel scan.
 min_wal_size                           | 80MB                                                | Sets the minimum size to shrink the WAL to.
 old_snapshot_threshold                 | -1                                                  | Time before a snapshot is too old to read pages changed after the snapshot was taken.
 operator_precedence_warning            | off                                                 | Emit a warning for constructs that changed meaning since PostgreSQL 9.4.
 parallel_leader_participation          | on                                                  | Controls whether Gather and Gather Merge also run subplans.
 parallel_setup_cost                    | 1000                                                | Sets the planner's estimate of the cost of starting up worker processes for parallel query.
 parallel_tuple_cost                    | 0.1                                                 | Sets the planner's estimate of the cost of passing each tuple (row) from worker to master backend.
 password_encryption                    | md5                                                 | Encrypt passwords.
 plan_cache_mode                        | auto                                                | Controls the planner's selection of custom or generic plan.
 port                                   | 5432                                                | Sets the TCP port the server listens on.
 post_auth_delay                        | 0                                                   | Waits N seconds on connection startup after authentication.
 pre_auth_delay                         | 0                                                   | Waits N seconds on connection startup before authentication.
 primary_conninfo                       |                                                     | Sets the connection string to be used to connect to the sending server.
 primary_slot_name                      |                                                     | Sets the name of the replication slot to use on the sending server.
 promote_trigger_file                   |                                                     | Specifies a file name whose presence ends recovery in the standby.
 quote_all_identifiers                  | off                                                 | When generating SQL fragments, quote all identifiers.
 random_page_cost                       | 4                                                   | Sets the planner's estimate of the cost of a nonsequentially fetched disk page.
 recovery_end_command                   |                                                     | Sets the shell command that will be executed once at the end of recovery.
 recovery_min_apply_delay               | 0                                                   | Sets the minimum delay for applying changes during recovery.
 recovery_target                        |                                                     | Set to "immediate" to end recovery as soon as a consistent state is reached.
 recovery_target_action                 | pause                                               | Sets the action to perform upon reaching the recovery target.
 recovery_target_inclusive              | on                                                  | Sets whether to include or exclude transaction with recovery target.
 recovery_target_lsn                    |                                                     | Sets the LSN of the write-ahead log location up to which recovery will proceed.
 recovery_target_name                   |                                                     | Sets the named restore point up to which recovery will proceed.
 recovery_target_time                   |                                                     | Sets the time stamp up to which recovery will proceed.
 recovery_target_timeline               | latest                                              | Specifies the timeline to recover into.
 recovery_target_xid                    |                                                     | Sets the transaction ID up to which recovery will proceed.
 restart_after_crash                    | on                                                  | Reinitialize server after backend crash.
 restore_command                        |                                                     | Sets the shell command that will retrieve an archived WAL file.
 row_security                           | on                                                  | Enable row security.
 search_path                            | "$user", public                                     | Sets the schema search order for names that are not schema-qualified.
 segment_size                           | 1GB                                                 | Shows the number of pages per disk file.
 seq_page_cost                          | 1                                                   | Sets the planner's estimate of the cost of a sequentially fetched disk page.
 server_encoding                        | UTF8                                                | Sets the server (database) character set encoding.
 server_version                         | 12.0                                                | Shows the server version.
 server_version_num                     | 120000                                              | Shows the server version as an integer.
 session_preload_libraries              |                                                     | Lists shared libraries to preload into each backend.
 session_replication_role               | origin                                              | Sets the session's behavior for triggers and rewrite rules.
 shared_buffers                         | 128MB                                               | Sets the number of shared memory buffers used by the server.
 shared_memory_type                     | windows                                             | Selects the shared memory implementation used for the main shared memory region.
 shared_preload_libraries               |                                                     | Lists shared libraries to preload into server.
 ssl                                    | off                                                 | Enables SSL connections.
 ssl_ca_file                            |                                                     | Location of the SSL certificate authority file.
 ssl_cert_file                          | server.crt                                          | Location of the SSL server certificate file.
 ssl_ciphers                            | HIGH:MEDIUM:+3DES:!aNULL                            | Sets the list of allowed SSL ciphers.
 ssl_crl_file                           |                                                     | Location of the SSL certificate revocation list file.
 ssl_dh_params_file                     |                                                     | Location of the SSL DH parameters file.
 ssl_ecdh_curve                         | prime256v1                                          | Sets the curve to use for ECDH.
 ssl_key_file                           | server.key                                          | Location of the SSL server private key file.
 ssl_library                            | OpenSSL                                             | Name of the SSL library.
 ssl_max_protocol_version               |                                                     | Sets the maximum SSL/TLS protocol version to use.
 ssl_min_protocol_version               | TLSv1                                               | Sets the minimum SSL/TLS protocol version to use.
 ssl_passphrase_command                 |                                                     | Command to obtain passphrases for SSL.
 ssl_passphrase_command_supports_reload | off                                                 | Also use ssl_passphrase_command during server reload.
 ssl_prefer_server_ciphers              | on                                                  | Give priority to server ciphersuite order.
 standard_conforming_strings            | on                                                  | Causes '...' strings to treat backslashes literally.
 statement_timeout                      | 0                                                   | Sets the maximum allowed duration of any statement.
 stats_temp_directory                   | pg_stat_tmp                                         | Writes temporary statistics files to the specified directory.
 superuser_reserved_connections         | 3                                                   | Sets the number of connection slots reserved for superusers.
 synchronize_seqscans                   | on                                                  | Enable synchronized sequential scans.
 synchronous_commit                     | on                                                  | Sets the current transaction's synchronization level.
 synchronous_standby_names              |                                                     | Number of synchronous standbys and list of names of potential synchronous ones.
 syslog_facility                        | none                                                | Sets the syslog "facility" to be used when syslog enabled.
 syslog_ident                           | postgres                                            | Sets the program name used to identify PostgreSQL messages in syslog.
 syslog_sequence_numbers                | on                                                  | Add sequence number to syslog messages to avoid duplicate suppression.
 syslog_split_messages                  | on                                                  | Split messages sent to syslog by lines and to fit into 1024 bytes.
 tcp_keepalives_count                   | 0                                                   | Maximum number of TCP keepalive retransmits.
 tcp_keepalives_idle                    | -1                                                  | Time between issuing TCP keepalives.
 tcp_keepalives_interval                | -1                                                  | Time between TCP keepalive retransmits.
 tcp_user_timeout                       | 0                                                   | TCP user timeout.
 temp_buffers                           | 8MB                                                 | Sets the maximum number of temporary buffers used by each session.
 temp_file_limit                        | -1                                                  | Limits the total size of all temporary files used by each process.
 temp_tablespaces                       |                                                     | Sets the tablespace(s) to use for temporary tables and sort files.
 TimeZone                               | GMT                                                 | Sets the time zone for displaying and interpreting time stamps.
 timezone_abbreviations                 | Default                                             | Selects a file of time zone abbreviations.
 trace_notify                           | off                                                 | Generates debugging output for LISTEN and NOTIFY.
 trace_recovery_messages                | log                                                 | Enables logging of recovery-related debugging information.
 trace_sort                             | off                                                 | Emit information about resource usage in sorting.
 track_activities                       | on                                                  | Collects information about executing commands.
 track_activity_query_size              | 1kB                                                 | Sets the size reserved for pg_stat_activity.query, in bytes.
 track_commit_timestamp                 | off                                                 | Collects transaction commit time.
 track_counts                           | on                                                  | Collects statistics on database activity.
 track_functions                        | none                                                | Collects function-level statistics on database activity.
 track_io_timing                        | off                                                 | Collects timing statistics for database I/O activity.
 transaction_deferrable                 | off                                                 | Whether to defer a read-only serializable transaction until it can be executed with no possible serialization failures.
 transaction_isolation                  | read committed                                      | Sets the current transaction's isolation level.
 transaction_read_only                  | off                                                 | Sets the current transaction's read-only status.
 transform_null_equals                  | off                                                 | Treats "expr=NULL" as "expr IS NULL".
 unix_socket_directories                |                                                     | Sets the directories where Unix-domain sockets will be created.
 unix_socket_group                      |                                                     | Sets the owning group of the Unix-domain socket.
 unix_socket_permissions                | 0777                                                | Sets the access permissions of the Unix-domain socket.
 update_process_title                   | off                                                 | Updates the process title to show the active SQL command.
 vacuum_cleanup_index_scale_factor      | 0.1                                                 | Number of tuple inserts prior to index cleanup as a fraction of reltuples.
 vacuum_cost_delay                      | 0                                                   | Vacuum cost delay in milliseconds.
 vacuum_cost_limit                      | 200                                                 | Vacuum cost amount available before napping.
 vacuum_cost_page_dirty                 | 20                                                  | Vacuum cost for a page dirtied by vacuum.
 vacuum_cost_page_hit                   | 1                                                   | Vacuum cost for a page found in the buffer cache.
 vacuum_cost_page_miss                  | 10                                                  | Vacuum cost for a page not found in the buffer cache.
 vacuum_defer_cleanup_age               | 0                                                   | Number of transactions by which VACUUM and HOT cleanup should be deferred, if any.
 vacuum_freeze_min_age                  | 50000000                                            | Minimum age at which VACUUM should freeze a table row.
 vacuum_freeze_table_age                | 150000000                                           | Age at which VACUUM should scan whole table to freeze tuples.
 vacuum_multixact_freeze_min_age        | 5000000                                             | Minimum age at which VACUUM should freeze a MultiXactId in a table row.
 vacuum_multixact_freeze_table_age      | 150000000                                           | Multixact age at which VACUUM should scan whole table to freeze tuples.
 wal_block_size                         | 8192                                                | Shows the block size in the write ahead log.
 wal_buffers                            | 4MB                                                 | Sets the number of disk-page buffers in shared memory for WAL.
 wal_compression                        | off                                                 | Compresses full-page writes written in WAL file.
 wal_consistency_checking               |                                                     | Sets the WAL resource managers for which WAL consistency checks are done.
 wal_init_zero                          | on                                                  | Writes zeroes to new WAL files before first use.
 wal_keep_segments                      | 0                                                   | Sets the number of WAL files held for standby servers.
 wal_level                              | replica                                             | Set the level of information written to the WAL.
 wal_log_hints                          | off                                                 | Writes full pages to WAL when first modified after a checkpoint, even for a non-critical modifications.
 wal_receiver_status_interval           | 10s                                                 | Sets the maximum interval between WAL receiver status reports to the sending server.
 wal_receiver_timeout                   | 1min                                                | Sets the maximum wait time to receive data from the sending server.
 wal_recycle                            | on                                                  | Recycles WAL files by renaming them.
 wal_retrieve_retry_interval            | 5s                                                  | Sets the time to wait before retrying to retrieve WAL after a failed attempt.
 wal_segment_size                       | 16MB                                                | Shows the size of write ahead log segments.
 wal_sender_timeout                     | 1min                                                | Sets the maximum time to wait for WAL replication.
 wal_sync_method                        | open_datasync                                       | Selects the method used for forcing WAL updates to disk.
 wal_writer_delay                       | 200ms                                               | Time between WAL flushes performed in the WAL writer.
 wal_writer_flush_after                 | 1MB                                                 | Amount of WAL written out by WAL writer that triggers a flush.
 work_mem                               | 4MB                                                 | Sets the maximum memory to be used for query workspaces.
 xmlbinary                              | base64                                              | Sets how binary values are to be encoded in XML.
 xmloption                              | content                                             | Sets whether XML data in implicit parsing and serialization operations is to be considered as documents or content fragments.
 zero_damaged_pages                     | off                                                 | Continues processing past damaged page headers.
 

PostgreSQL PG 数据文件灾难恢复 – 解析与数据pg_filedump

作者

digoal

日期

2017-03-10

标签

PostgreSQL , 数据文件 , pg_filedump , 安全 , TDE


背景

俗话说常在河边站哪有不湿鞋,作为一名战斗在一线的DBA或者开发者,可能有遇到过磁盘损坏,磁盘阵列损坏,如果有备份或者备库的话,还好。

如果没有备份,或者没有备库(通常有一些小型或者创业型的企业),那么遇到磁盘损坏或者其他原因(比如掉电文件系统损坏),导致数据库的数据文件并不完整时,如何从有限的资料中找出数据呢?

比如PostgreSQL,如果读到坏块,会报块不可读的错误,这种情况下通过设置zero_damaged_pages=on可以跳过损坏的数据块。

如果连元数据都损坏了,又或者坏了一些磁盘,只有某些表空间被幸免于难,这些情况下你的数据库都已经无法启动时,如何能从有限的数据文件中找回数据呢?

 

 

数据文件解析pg_filedump

 

 

pg_filedump是PostgreSQL社区托管的一个项目,类似于pg_xlogdump,不需要开启数据库,可以直接从数据文件中将数据dump出来。

pg_filedump实际上可以DUMP 堆表、索引数据文件,控制文件的内容。(从pg_filedump引用的头文件也能看出端倪)

安装很简单

 

 

git clone git://git.postgresql.org/git/pg_filedump.git  
  
cd pg_filedump  
  
export PATH=/home/digoal/pgsql9.6/bin:$PATH  
  
make ; make install  

命令帮助如下,通常来说,你只需要指定需要DUMP的文件即可。

如果文件的块头损坏了,那么你可以手工指定一些信息,包括块大小,段大小,解析哪个块,根据什么格式解析(字段类型列表)等。

 

 

pg_filedump [-abcdfhikxy] [-R startblock [endblock]] [-D attrlist] [-S blocksize] [-s segsize] [-n segnumber] file  
  
Defaults are: relative addressing, range of the entire file, block size  
              as listed on block 0 in the file  
  
The following options are valid for heap and index files:  
  -a  Display absolute addresses when formatting (Block header  
      information is always block relative)  
  -b  Display binary block images within a range (Option will turn  
      off all formatting options)  
  -d  Display formatted block content dump (Option will turn off  
      all other formatting options)  
  -D  Try to decode tuples using given comma separated list of types.  
      List of supported types:  
        * bigint  
        * bigserial  
        * bool  
        * char  
        * charN     -- char(n)  
        * date  
        * float  
        * float4  
        * float8  
        * int  
        * json  
        * macaddr  
        * name  
        * oid  
        * real  
        * serial  
        * smallint  
        * smallserial  
        * text  
        * time  
        * timestamp  
        * timetz  
        * uuid  
        * varchar  
        * varcharN -- varchar(n)  
        * xid  
        * xml  
        * ~        -- ignores are attributes left in a tuple  
  -f  Display formatted block content dump along with interpretation  
  -h  Display this information  
  -i  Display interpreted item details  
  -k  Verify block checksums  
  -R  Display specific block ranges within the file (Blocks are  
      indexed from 0)  
        [startblock]: block to start at  
        [endblock]: block to end at  
      A startblock without an endblock will format the single block  
  -s  Force segment size to [segsize]  
  -n  Force segment number to [segnumber]  
  -S  Force block size to [blocksize]  
  -x  Force interpreted formatting of block items as index items  
  -y  Force interpreted formatting of block items as heap items  
  
The following options are valid for control files:  
  -c  Interpret the file listed as a control file  
  -f  Display formatted content dump along with interpretation  
  -S  Force block size to [blocksize]  
  
In most cases it's recommended to use the -i and -f options to get  
the most useful dump output.  

pg_filedump使用举例

 

 

1. 创建测试表

postgres=# create table digoal(id int, info text, crt_time timestamp);  
CREATE TABLE  

2. 插入测试数据

postgres=# insert into digoal select generate_series(1,1000000),md5(random()::text), clock_timestamp();  
INSERT 0 1000000  

3. 找出表对应的数据文件

postgres=# select pg_relation_filepath('digoal');  
 pg_relation_filepath   
----------------------  
 base/13269/173369  
(1 row)  

4. 调用checkpoint,把数据刷盘,便于我们接下来的观察

checkpoint;  

5. 使用pg_filedump直接读取数据文件,导出数据

-> cd $PGDATA/base/13269  
-> pg_filedump -i -f ./173369  
  
输出截取  
*******************************************************************  
* PostgreSQL File/Block Formatted Dump Utility - Version 9.6.0  
*  
* File: ./173369  
* Options used: -i -f   
*  
* Dump created on: Sun Mar 12 00:28:56 2017  
*******************************************************************  
  
首先是块的头部内容

Block    0 ********************************************************  
<Header> -----  
 Block Offset: 0x00000000         Offsets: Lower     452 (0x01c4)  
 Block: Size 8192  Version    4            Upper     488 (0x01e8)  
 LSN:  logid     61 recoff 0xe69d6490      Special  8192 (0x2000)  
 Items:  107                      Free Space:   36  
 Checksum: 0x0000  Prune XID: 0x00000000  Flags: 0x0000 ()  
 Length (including item array): 452  

...
 
然后是DATA部分,
<Data> ------ 
 Item   1 -- Length:   72  Offset: 8120 (0x1fb8)  Flags: NORMAL
  XMIN: 88072212  XMAX: 88072214  CID|XVAC: 0
  Block Id: 9345  linp Index: 86   Attributes: 3   Size: 24
  infomask: 0x0102 (HASVARWIDTH|XMIN_COMMITTED) 

  1fb8: 14e03f05 16e03f05 00000000 00008124  ..?...?........$
  1fc8: 56000300 02011800 01000000 43363134  V...........C614
  1fd8: 62653439 31616339 65356636 64633136  be491ac9e5f6dc16
  1fe8: 35653065 31323162 36316563 33000000  5e0e121b61ec3...
  1ff8: 791cce69 7ced0100                    y..i|...        

COPY: 1 614be491ac9e5f6dc165e0e121b61ec3        2017-03-12 00:26:23.553657
 Item   2 -- Length:   72  Offset: 8048 (0x1f70)  Flags: NORMAL
  XMIN: 88072212  XMAX: 0  CID|XVAC: 0
  Block Id: 0  linp Index: 2   Attributes: 3   Size: 24
  infomask: 0x0902 (HASVARWIDTH|XMIN_COMMITTED|XMAX_INVALID) 

  1f70: 14e03f05 00000000 00000000 00000000  ..?.............
  1f80: 02000300 02091800 02000000 43383335  ............C835
  1f90: 39653064 31623462 61323261 64336139  9e0d1b4ba22ad3a9
  1fa0: 65386634 38316231 61633336 31000000  e8f481b1ac361...
  1fb0: df1cce69 7ced0100                    ...i|...        

COPY: 2 8359e0d1b4ba22ad3a9e8f481b1ac361        2017-03-12 00:26:23.553759
......

为了得到记录,需要提供一下字段类型LIST,必须保证与表结构一致

-> pg_filedump -D int,text,timestamp ./173369|less  
  
*******************************************************************  
* PostgreSQL File/Block Formatted Dump Utility - Version 9.6.0  
*  
* File: ./173369  
* Options used: -D int,text,timestamp   
*  
* Dump created on: Sun Mar 12 00:31:25 2017  
*******************************************************************  
  
Block    0 ********************************************************  
<Header> -----  
 Block Offset: 0x00000000         Offsets: Lower     452 (0x01c4)  
 Block: Size 8192  Version    4            Upper     488 (0x01e8)  
 LSN:  logid     61 recoff 0xe69d6490      Special  8192 (0x2000)  
 Items:  107                      Free Space:   36  
 Checksum: 0x0000  Prune XID: 0x00000000  Flags: 0x0000 ()  
 Length (including item array): 452  
  
<Data> ------   
 Item   1 -- Length:   72  Offset: 8120 (0x1fb8)  Flags: NORMAL  
COPY: 1 614be491ac9e5f6dc165e0e121b61ec3        2017-03-12 00:26:23.553657  
 Item   2 -- Length:   72  Offset: 8048 (0x1f70)  Flags: NORMAL  
COPY: 2 8359e0d1b4ba22ad3a9e8f481b1ac361        2017-03-12 00:26:23.553759  
 Item   3 -- Length:   72  Offset: 7976 (0x1f28)  Flags: NORMAL  
COPY: 3 0dc8c441e91217897f994ae163510653        2017-03-12 00:26:23.553764  
..........  

COPY得到的就是使用-D提供的类型列表decode拼装的记录。

是不是可以从文件中DUMP数据了呢?莫急,还要看看掩码哦,否则你不知道这条记录是否为你需要的,因为它可能是DEAD TUPLE。

例子

-> pg_filedump -D int,text,timestamp -i -f ./173369|less  
  
COPY: 1 614be491ac9e5f6dc165e0e121b61ec3        2017-03-12 00:26:23.553657  
 Item   2 -- Length:   72  Offset: 8048 (0x1f70)  Flags: NORMAL  
  XMIN: 88072212  XMAX: 0  CID|XVAC: 0  
  Block Id: 0  linp Index: 2   Attributes: 3   Size: 24  
  infomask: 0x0902 (HASVARWIDTH|XMIN_COMMITTED|XMAX_INVALID)   

记录头的infomask解释

 

 

每条记录,头部都有infomask, infomask2掩码,掩码表示的意思,可以参考头文件

比如什么是DEAD TUPLE呢?

src/include/access/htup_details.h  
  
/*  
 * information stored in t_infomask:  
 */  
#define HEAP_HASNULL                    0x0001  /* has null attribute(s) */  
#define HEAP_HASVARWIDTH                0x0002  /* has variable-width attribute(s) */  
#define HEAP_HASEXTERNAL                0x0004  /* has external stored attribute(s) */  
#define HEAP_HASOID                             0x0008  /* has an object-id field */  
#define HEAP_XMAX_KEYSHR_LOCK   0x0010  /* xmax is a key-shared locker */  
#define HEAP_COMBOCID                   0x0020  /* t_cid is a combo cid */  
#define HEAP_XMAX_EXCL_LOCK             0x0040  /* xmax is exclusive locker */  
#define HEAP_XMAX_LOCK_ONLY             0x0080  /* xmax, if valid, is only a locker */  
  
 /* xmax is a shared locker */  
#define HEAP_XMAX_SHR_LOCK      (HEAP_XMAX_EXCL_LOCK | HEAP_XMAX_KEYSHR_LOCK)  
  
#define HEAP_LOCK_MASK  (HEAP_XMAX_SHR_LOCK | HEAP_XMAX_EXCL_LOCK | \  
                                                 HEAP_XMAX_KEYSHR_LOCK)  
#define HEAP_XMIN_COMMITTED             0x0100  /* t_xmin committed */  
#define HEAP_XMIN_INVALID               0x0200  /* t_xmin invalid/aborted */  
#define HEAP_XMIN_FROZEN                (HEAP_XMIN_COMMITTED|HEAP_XMIN_INVALID)  
#define HEAP_XMAX_COMMITTED             0x0400  /* t_xmax committed */  
#define HEAP_XMAX_INVALID               0x0800  /* t_xmax invalid/aborted */  
#define HEAP_XMAX_IS_MULTI              0x1000  /* t_xmax is a MultiXactId */  
#define HEAP_UPDATED                    0x2000  /* this is UPDATEd version of row */  
#define HEAP_MOVED_OFF                  0x4000  /* moved to another place by pre-9.0  
                                                                                 * VACUUM FULL; kept for binary  
                                                                                 * upgrade support */  
#define HEAP_MOVED_IN                   0x8000  /* moved from another place by pre-9.0  
                                                                                 * VACUUM FULL; kept for binary  
                                                                                 * upgrade support */  
#define HEAP_MOVED (HEAP_MOVED_OFF | HEAP_MOVED_IN)  
  
#define HEAP_XACT_MASK                  0xFFF0  /* visibility-related bits */  

观察deadtuple

postgres=# update digoal set info='new' where id=1;  
UPDATE 1  
postgres=# checkpoint;  
CHECKPOINT  

观察

pg_filedump -D int,text,timestamp -i -f ./173369|less  
  
 Item   1 -- Length:   72  Offset: 8120 (0x1fb8)  Flags: NORMAL  
  包含了xmax,说明是更新过的记录  
  XMIN: 88072212  XMAX: 88072214  CID|XVAC: 0  
  blockid表示记录指向,即新版本记录在哪个新数据块,Linp指新数据块的第几条记录。  
  Block Id: 9345  linp Index: 86   Attributes: 3   Size: 24  
  infomask 参考前面的头文件,解读  
  infomask: 0x0102 (HASVARWIDTH|XMIN_COMMITTED)   
  
  1fb8: 14e03f05 16e03f05 00000000 00008124  ..?...?........$  
  1fc8: 56000300 02011800 01000000 43363134  V...........C614  
  1fd8: 62653439 31616339 65356636 64633136  be491ac9e5f6dc16  
  1fe8: 35653065 31323162 36316563 33000000  5e0e121b61ec3...  
  1ff8: 791cce69 7ced0100                    y..i|...          
  
COPY: 1 614be491ac9e5f6dc165e0e121b61ec3        2017-03-12 00:26:23.553657  

查看新版本(编号为9345数据块,第86条记录)

pg_filedump -D int,text,timestamp -i -f -R 9345 ./173369|less  
  
 Item  86 -- Length:   40  Offset: 2032 (0x07f0)  Flags: NORMAL  
  XMIN: 88072214  XMAX: 0  CID|XVAC: 0  
  Block Id: 9345  linp Index: 86   Attributes: 3   Size: 24  
  infomask: 0x2802 (HASVARWIDTH|XMAX_INVALID|UPDATED)   
  
  07f0: 16e03f05 00000000 00000000 00008124  ..?............$  
  0800: 56000300 02281800 01000000 096e6577  V....(.......new  
  0810: 791cce69 7ced0100                    y..i|...          
  
COPY: 1 new     2017-03-12 00:26:23.553657  

PostgreSQL数据块的简介

对于数据文件的组织形式,可以参考头文件

src/include/storage

/*  
 * BlockNumber:  
 *  
 * each data file (heap or index) is divided into postgres disk blocks  
 * (which may be thought of as the unit of i/o -- a postgres buffer  
 * contains exactly one disk block).  the blocks are numbered  
 * sequentially, 0 to 0xFFFFFFFE.  
 *  
 * InvalidBlockNumber is the same thing as P_NEW in buf.h.  
 *  
 * the access methods, the buffer manager and the storage manager are  
 * more or less the only pieces of code that should be accessing disk  
 * blocks directly.  
 */  
typedef uint32 BlockNumber;  
  
#define InvalidBlockNumber              ((BlockNumber) 0xFFFFFFFF)  
  
#define MaxBlockNumber                  ((BlockNumber) 0xFFFFFFFE)  

每个块内的组织,与对象类型有关,比如堆表,B-TREE,HASH等索引,TOAST, FSM等。

可以参考数据layout介绍

https://www.postgresql.org/docs/9.6/static/storage.html

也可以参考对应类型的头文件

阅读pg_filedump的源码,也有助于你对PostgreSQL存储构造的理解

不妨仔细阅读以下头文件

#include "access/gin_private.h"  
#include "access/gist.h"  
#include "access/hash.h"  
#include "access/htup.h"  
#include "access/htup_details.h"  
#include "access/itup.h"  
#include "access/nbtree.h"  
#include "access/spgist_private.h"  
#include "catalog/pg_control.h"  
#include "storage/bufpage.h"  

Postgre SQL 9.1 beta:开源世界的礼物

开源数据库产品Postgre SQL最新版本9.1的beta发布了,其开发者宣称这将会是划时代的一个版本,9.1将为我们带来企业级别的可靠性与数据完整性。Postgre SQL的核心开发小组成员Josh Berkus表示,即将到来的9.1版本引入了大量通过同步复制特性来完善数据库容错能力,使得数据库可以保证在主节点失败的情景中不丢失写操作。Berkus说:”在这个版本中,我们将提供Oracle DataGuard所能提供的所有特性,这将让如日本NTT等使用Oracle的公司从容地迁移到Postgre SQL上来”。

对于还在酝酿中的9.2版本,核心开发小组认为在他们试图提供更多容错与集群技术之前,首要的任务是完善最基础的同步复制功能,而后才有可能引入更为复杂的特性。

一个令人鼓舞的消息是EnterpriseDB公司正和NTT公司合作一个名为”PostgresXC”的项目,其目的为Postgre增加类似于Oracle RAC的功能,虽然在具体设计上2者存在区别。另一方面Postgres-R项目组获得了足够的资金,该项目致力于为Postgre SQL加入基于群组通信的集群功能,因为解决了后顾之忧该项目可能在今年发布新的版本。

Postgre SQL如果能成功引入Data Guard和RAC的相关功能,那么不失为一个功能丰富而又价格低廉的解决方案!

更多原始信息可以参考:PostgreSQL devs lift open source database to enterprise heights

Performance: PostgreSQL VS SQLSERVER

最近(2010 March) redhat公司release了一份对PostgreSQL和SQLSERVER的性能检测报告,使用相同的HP ProLiant DL370 G6(Intel Xeon W5580)主机,操作系统是Redhat Enterprise Linux 5:Windows Server 2008 Enterprise;PostgreSQL 部分参数进行了优化,包括checkpoint_timeout,effective_cache_size等,值得注意的是关掉了自动vacuum(autovacuum=false).测试结果是PostgreSQL略有优势,见图:

点击浏览性能报告.

PostgreSQL.Essential.Reference

download PostgreSQL Essential Reference here

EnterpriseDB Replication,复制Oracle数据测试(2)

介绍完了EnterpriseDB复制软件基本原理和注意事项,我们接下来进行Oracle数据复制到EntepriseDB advanced Server的实际演练。

先在Oracle实例中创建复制测试所用到的数据:

SQL> drop user  source cascade;

User dropped.

SQL> create user source identified by source;

User created.

SQL> grant dba to source;

Grant succeeded.

SQL> grant create any trigger to source;

Grant succeeded.

SQL> conn source/source
Connected.
SQL> create table EMP
2  (
3    EMPNO    NUMBER(4) not null,
4    ENAME    VARCHAR2(10),
5    JOB      VARCHAR2(9),
6    MGR      NUMBER(4),
7    HIREDATE DATE,
8    SAL      NUMBER(7,2),
9    COMM     NUMBER(7,2),
10    DEPTNO   NUMBER(2)
11  )
12  tablespace USERS;

Table created.

SQL> alter table EMP
2    add constraint pk_empno primary key (EMPNO);

Table altered.

SQL> create table DEPT
2  (
DEPTNO NUMBER(2) not null,
DNAME  VARCHAR2(14),
LOC    VARCHAR2(13)
)
3    4    5    6    7  tablespace USERS;

Table created.

SQL> alter table DEPT
2    add constraint PK_DEPT primary key (DEPTNO);

Table altered.

SQL> alter table EMP
2    add constraint fk_deptno foreign key (DEPTNO)
3    references dept (DEPTNO);

Table altered.

SQL>

同时创建EnterpriseDB Advanced Server中的目标数据库及用户:

edb=#  create user subuser password 'subuser';
ERROR:  role "subuser" already exists
edb=# alter user subuser with Superuser;
ALTER ROLE
edb=# create database subuser tablespace users;
CREATE DATABASE

EnterpriseDB复制服务需要DBA Management Server服务的相关支持,其运作方式如下图:

我们首先需要注册管理服务器,其默认端口为9000,为确保主机上的管理服务已打开可以运行以下命令:

[enterprisedb@rh2 ~]$ source edb_83.env
[enterprisedb@rh2 ~]$ cd $EDBHOME
[enterprisedb@rh2 edba]$ cd mgmtsvr/bin
[enterprisedb@rh2 bin]$ ls
attachments            DBA_Management_Server.pid  jboss_init_redhat.sh  mgmtsvr.000  run.conf  shutdown.jar  twiddle.sh    wrapper.log   wsrunclient.sh
BrowserLauncher.class  deployer.sh                jboss_init_suse.sh    mgmtsvr.sh   run.jar   shutdown.sh   wrapper_83    wsconsume.sh  wstools.sh
classpath.sh           jboss_init_hpux.sh         kill_wrapper.sh       probe.sh     run.sh    twiddle.jar   wrapper.conf  wsprovide.sh
[enterprisedb@rh2 bin]$ ./mgmtsvr.sh  status
DBA Management Server is running (31198).           --目前服务已打开
[enterprisedb@rh2 bin]$ ./mgmtsvr.sh  stop
Stopping DBA Management Server...
Stopped DBA Management Server.
[enterprisedb@rh2 bin]$ ./mgmtsvr.sh  start           -- 若未打开,则start
Starting DBA Management Server...

接着我们可以从桌面上的application栏打开replication console,并选择注册管理服务(register management Server):

成功注册服务后,我们需要分别在发布服务和订阅服务中配置JVM option,右键点击Publication service选择Advanced JVM options,在该窗口内Insert一条记录,如图:

其内容为-Djava.rmi.server.hostname=$IP, 其中$IP为已注册的DBA Management Server所监听的IP地址。配置完成后分别启动发布与订阅服务。

针对订阅服务也需要进行以上配置,JVM options也添加的条目为-Djava.rmi.server.hostname=$IP。
开始创建发布服务Oracle数据源:

并创建相关的发布服务:

接着创建订阅服务数据库:

创建具体的订阅服务:

上述配置均成功完成后,源端的数据定义默认已复制到订阅端,我们来验证一下:

[enterprisedb@rh2 ~]$ psql subuser subuser
Password for user subuser:
Welcome to psql 8.3.0.112, the EnterpriseDB interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with edb-psql commands
       \g or terminate with semicolon to execute query
       \q to quit

subuser=# desc source.emp;
                 Table "source.emp"
  Column  |            Type             | Modifiers
----------+-----------------------------+-----------
 empno    | numeric(4,0)                | not null
 ename    | character varying(10)       |
 job      | character varying(9)        |
 mgr      | numeric(4,0)                |
 hiredate | timestamp without time zone |
 sal      | numeric(7,2)                |
 comm     | numeric(7,2)                |
 deptno   | numeric(2,0)                |
Indexes:
    "pk_empno" PRIMARY KEY, btree (empno)

subuser=# desc source.dept;
            Table "source.dept"
 Column |         Type          | Modifiers
--------+-----------------------+-----------
 deptno | numeric(2,0)          | not null
 dname  | character varying(14) |
 loc    | character varying(13) |
Indexes:
    "pk_dept" PRIMARY KEY, btree (deptno)

接下来尝试在源端Oracle数据库中产生一定量的数据,并通过快照方式复制到订阅端:

SQL> insert into dept select * from scott.dept;

4 rows created.

SQL> commit;

Commit complete.

SQL> select * from dept;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON

SQL> begin
  2  for i in 1..9999 loop
  3  insert into emp values(i,'Maclean','DBA',1,sysdate-365,8888,50,10);
  4  end loop;
  5  commit;
  6  end;
  7  /

PL/SQL procedure successfully completed.

SQL> select count(*) from emp;

  COUNT(*)
----------
      9999

在点中订阅服务subuser中选择功能栏中的snapshot复制方式:

其复制过程中产生的日志:

Source database connectivity info…
conn =jdbc:oracle:thin:@192.168.0.115:1521:g10r21
user =source
password=******
Target database connectivity info…
conn =jdbc:edb://192.168.0.115:5444/subuser
user =subuser
password=******
Importing redwood schema SOURCE…
Table List: ‘DEPT’,’EMP’
Loading Table Data in 8 MB batches…
Disabling FK constraints & triggers on source.dept before truncate…
Truncating table DEPT before data load…
Disabling indexes on source.dept before data load…
Loading Table: DEPT …
Migrated 4 rows.
Enabling FK constraints & triggers on source.dept…
Enabling indexes on source.dept after data load…
Creating Constraint: PK_DEPT
Table Data Load Summary: Total Time(s): 1.261 Total Rows: 4
Disabling FK constraints & triggers on source.emp before truncate…
Truncating table EMP before data load…
Disabling indexes on source.emp before data load…
Loading Table: EMP …
Migrated 9999 rows.
Enabling FK constraints & triggers on source.emp…
Enabling indexes on source.emp after data load…
Creating Constraint: PK_EMPNO
Table Data Load Summary: Total Time(s): 3.782 Total Rows: 9999 Total Size(MB): 0.494140625
Performing ANALYZE on EnterpriseDB database…
Data Load Summary: Total Time (sec): 5.043 Total Rows: 10003 Total Size(MB): 0.506

Schema SOURCE imported successfully.

Migration process completed successfully.

Migration logs have been saved to /s01/edba/mgmtsvr/server/default/deploy/edb-rrep-ws.war/WEB-INF/logs

******************** Migration Summary ********************
Tables: 2 out of 2
Constraints: 2 out of 2

Total objects: 4
Successful count: 4
Failure count: 0

*************************************************************

可以看到快照成功复制了我们需要的数据,现在我们来尝试使用同步模式(synchronize mode) ,我们先来定义一个持续性的间隔为5s的 Scheduled Task,选中订阅服务并点击功能栏中的Configure Schedule,选择Synchronize和Continuously,间隔时间选择为10s:

我们在源端Oracle数据库中修改员工工资,并观察订阅端EDB数据库中的情况:

-- source database
20:08:51 SQL> select sum(sal) from emp;

  SUM(SAL)
----------
  88871112

20:09:09 SQL> update emp set sal=sal*1.1 ;

9999 rows updated.

20:09:34 SQL> commit;

Commit complete.

20:09:36 SQL> select sum(sal) from emp;

  SUM(SAL)
----------
97758223.2
-- EntepriseDB端
subuser=# select sum(sal) from source.emp;
     sum
-------------
 97758223.20
(1 row)

好了,以上我们利用EnterpriseDB Replication软件完成了一个由Oracle数据库到EDB advanced server间最简单的数据复制服务的配置。

沪ICP备14014813号-2

沪公网安备 31010802001379号