我建议您熟悉安德烈·萨尔尼科夫(Andrei Salnikov)对2018年报告的解码,“更新PostgreSQL版本的实践”
在大多数情况下,系统管理员和DBA担心会对数据库版本(RDBMS)进行重大更新,尤其是在该数据库正在运行且负载很高的情况下。造成这种情况的主要原因是某些数据库停机,这通常在此类工作的计划中隐含着。
实际上,这种升级需要相当长的时间,并且由于在准备阶段可以避免的琐碎错误,对此类操作经验很少的管理员通常不得不回滚到旧版本的数据库。
在Data Egret中,我们在没有错误余地的项目中进行大型PostgreSQL升级方面积累了丰富的经验。我将分享我的经验,并讨论该过程的后续步骤:如何为PostgreSQL升级做准备?在准备阶段需要做什么?如何计划升级本身的行动顺序?如何成功执行升级过程,而又不返回数据库的先前版本?如何最大程度地减少甚至避免整个升级过程中的停机时间?成功升级PostgreSQL后,我需要完成哪些步骤?我还将讨论两种最受欢迎的PostgreSQL升级过程pg_upgrade和pg_dump / pg_restore,每种方法的优缺点,并介绍该过程各个阶段的所有典型问题,以及如何避免它们。
对于初学者和长期使用PostgreSQL的DBA而言,该报告都将很有趣,但是他们想了解更多有关如何正确计划和尽可能轻松地进行升级的信息。
![](https://habrastorage.org/webt/qh/px/xd/qhpxxdul2aseoxu2_ohgojxftpu.png)
你好!我在Data Egret工作。我们致力于支持PostgreSQL服务器并提供PostgreSQL咨询服务。实践表明,很少有人更新数据库。他们启动了该项目,当时安装了当前版本,并且仍在工作。
该报告将包括三个部分。第一个是介绍性的术语,目的是为了达成一个通用术语。第二个是关于次要更新。第三个将涉及专业。
![](https://habrastorage.org/webt/yb/wk/bv/ybwkbvbiywdppdk19sky8vxd_vk.png)
该报告的目的是回答问题。
- ? , Postgres . , - . , . , . .
- , .
- , , .
- , : « ?». .
- , . , production .
, Postgres.
![](https://habrastorage.org/webt/9n/6v/uo/9n6vuovta77udhortpo17qcbhqw.png)
, , . 10 . , , , – .
![](https://habrastorage.org/webt/zz/ua/ku/zzuakuky0bgkb0_8pnyuxv56f3q.png)
10- . , . – , – .
![](https://habrastorage.org/webt/o9/rg/d6/o9rgd6cwxfxj2ysv6rrnskysrt8.png)
?
. , – . 9.6 , , , . . .
10- . , .
. . , .
. .
– , . 6. . , . . . 9.2. , , 9.2 . 9.2, .
: .
![](https://habrastorage.org/webt/mk/mj/fo/mkmjfozpligyczlzq19b4u7pudw.png)
. , , production :
- release notes. ? , release notes, release notes , . , . - . , , . , 10- , -. , , .
- ? . , . release notes, . , - . , Postgres , , . , Postgres, .
- - , , , , production .
- , – , . — , , , . .
, , , .
![](https://habrastorage.org/webt/ft/wd/sx/ftwdsxjongoxcwtzmofeol4flxs.png)
. .
, . , Postgres. Postgres.
:
- PostgreSQL. , - , , , Postgres . . . , . Ubuntu, , , . start.conf. . .
- PostgreSQL . , , common- . .
- – checkpoint. checkpoint? , . , , , . , , , , 250 GB, . checkpoint, Postgres.
- ? pgbouncer, , . pgbouncer, pgbouncer . pgbouncer’ – , - . latency . . . , pgbouncer, . checkpoint, pgbouncer, .
- , . . , .
- , extensions, - extensions. – extensions . . . . . .
- ( , release notes) release notes. – - . , 9.6.1 9.6.6, , release notes 9.6.2 – 9.6.6. - , , , .
- standby , , . , 14- , 2.3 . . , . .
, release notes.
![](https://habrastorage.org/webt/r7/po/fw/r7pofwu2d6pd3sfzov_zbnw-lsq.png)
Postgres.org. 9.6.2. , .
? , , . , . .
. . . , , release notes. .
![](https://habrastorage.org/webt/tp/fm/y4/tpfmy4cemzde9czdxxsr0pljldm.png)
, . . , , 9.6.5. 9.6.1. , . - . , – . – .
, . . . bash- , . alter extension, update .
![](https://habrastorage.org/webt/r0/r8/ek/r0r8ekgtztzazijacgoii-0qpss.png)
?
- . . , , .
- . , , , release notes.
- . , - , . . . .
- , . . . , checkpoint, 30 .
![](https://habrastorage.org/webt/ga/ph/cc/gaphcci6ovprvx85tkdq4ahzvve.png)
– .
. , . .
- Pg_dump restore – . , . - .
- Pg_upgrade – , , , 95 % , . .
- .
.
![](https://habrastorage.org/webt/nv/6c/6t/nv6c6tqljcr8ergpes79hmwrjrg.png)
pg_dump ?
- . , . 9.5, , 10. Ubuntu , RedHat – Postgres. , .
- locale, .
- Postgres, , , , , .
- , pg_dumop. PostgreSQL. ? pg_dump , , , . , , . . PostgreSQL, . . , . , .
- . pg_dump, . . , .
- . .
- , , , PostgreSQL.
, , , .
![](https://habrastorage.org/webt/yg/wy/_z/ygwy_zlxpezpbldwtlfbzkfb_ce.png)
pg_dump:
- . – . .
- . .
- . : , , . , .
- , , . .
- . , . . SSD-, SSD- . , , . .
- . , . , . , , . , , . .
![](https://habrastorage.org/webt/0_/qe/9o/0_qe9onjahbwmv3gajs4i5gdbus.png)
, pg_upgrade.
- Pg_upgrade . , . . , . .
- . , , .
- PostgreSQL. -, .
- . .
![](https://habrastorage.org/webt/j_/wo/jc/j_wojcl1m25krfsyc4qkq_fjmdo.png)
, pg_upgrade. : , , .
, pg_upgrade, , , . , , . .
, – pg_upgrade dump restore , pg_dump, restore , , , . .
. , , 8.4. Postgres .
, (, 9.0 10) -. , , . . , .
![](https://habrastorage.org/webt/7l/9t/6a/7l9t6aqjizxpby0hca5onk0d4ci.png)
, production. . . , – .
- PostgreSQL.
- locace. .
- pg_upgrade. «check». Check , . , - , , , , . , . , .
- Pg_dumpall — schema-only. check . pg_dumpall – schema-only, . , . , , check , dump .
- extensions . – PostGIS, PostGIS Postgres. extension Postgres, Postgres. changelog – , pg_upgrade , . dump restore .
![](https://habrastorage.org/webt/3g/4x/f7/3g4xf7lyqcnvv3hi-bs0fra4wj4.png)
, , , .
locale, pg_dumpall only, restore.
. , pgbouncer , . . , .
checkpoints, , .
pg_upgrade. , . . 45 . , 45 , . 15 , . .
![](https://habrastorage.org/webt/et/sy/er/etsyeryqtvdimdjivvq0jx_lrjw.png)
, . hard links. .
![](https://habrastorage.org/webt/cs/eo/sc/cseoscbeymrk5pjlzwbj9grk_rm.png)
PostgreSQL. . PostgreSQL? . , pg_upgrade .
.
. 10 . , .
:
pg_upgrade . , : , 10 .
, , .
9.5 . , .
![](https://habrastorage.org/webt/gi/dm/uk/gidmuk_tnbcrxet3qoghxfvpkd4.png)
. . , , . , vacuumdb 1, 10 . , . - . - . , , .
. , . - . , , . , , .
![](https://habrastorage.org/webt/kr/dh/y9/krdhy9toj4rsxvmlbokhhjaahno.png)
.
![](https://habrastorage.org/webt/o0/-v/_-/o0-v_-tammgsfm23g7spto9w080.png)
- Pg_upgrade extensions. , .
- release notes .
- , , extensions – alter extension EXTENSION_NAME update. . pg_stat_statements, - . pg_upgrade, pg_stat_statements. . .
![](https://habrastorage.org/webt/ri/50/6n/ri506n_tl93nkyy_m1-9gtrdtt4.png)
– ? :
- - - .
- , , , , , . . , , .
- ? Postgres. . . , , , 10 .
- PostgreSQL.
- pg_basebackup . .
- PostgreSQL.
- , rsync, . , , , . rsync , .
![](https://habrastorage.org/webt/fe/s_/_i/fes__isx8gdxhkejzomqabxytxc.png)
. :
9.4 . . , 10 11 .
, . Slony-l, Londiste, Bucardo . . .
![](https://habrastorage.org/webt/uy/yn/rd/uyynrdnjuv8_go1ttq3rsmsn2ns.png)
?
- PostgreSQL.
- - Postgres Postgres.
- , , . .
- , . . , Postgres. , , . . . , .
- Postgres, , .
- Postgres, . , , . - .
![](https://habrastorage.org/webt/8g/tv/of/8gtvofu-acouuounr5zfnjozen4.png)
?
- , . - .
- , . . . . , .
- sequences, -.
- DDL, . DDL , , . , .
- , , .
![](https://habrastorage.org/webt/2a/db/rv/2adbrv0193cxs8sglbod0f8jfnu.png)
, . pg_upgrade , .
? , 3 TB, 2 SSD RAID 3 TB. . .
. .
, , 99 - 9- . 15 . 15 . . - .
![](https://habrastorage.org/webt/bq/sl/ie/bqsliego7mt3nyx__tfzyrrlwb8.png)
, pg_upgrade. . .
.
! pgbouncer , , , , , . ?
, SSD . SSD , . . . . , , , , . , , . , Postgres. , .
pg_worm pg_hibernate, ?
, , .
! pg_upgrade?
, . , . , . , , - , . , , . , .
rsync -?
rsync? Rsync . , , , , . ? pg_upgrate . , . – pg_start_backup. rsync . - , rsync , . , , , tablespace HDD, rsync , . – , . , . – pg_basebackup.
! , …
这适用于次要更新。