基于ARM的M1Macw/BigSur上的Postgres错误

自从我买了一台新的基于 ARM 的 M1 MacBook Pro,我就一直遇到严重且一致的 PostgreSQL 问题 (psql 13.1)。无论我使用 Rails 服务器还是 Foreman,我都会在浏览器和终端中收到错误,例如PG::InternalError: ERROR: could not read block 15 in file "base/147456/148555": Bad addressorPG::Error (invalid encoding name: unicode)Error during failsafe response: PG::UnableToSend: no connection to the server。奇怪的是,我经常可以反复刷新浏览器以使其正常工作(直到它们不可避免地再次出现)。

我知道与基于 ARM 的 M1 Mac 相关的所有配置挑战,这就是为什么我以多种方式多次卸载并重新安装从 Homebrew 到 Postgres 的所有内容(使用 Rosetta,不使用 Rosetta,使用arch -x86_64 brew命令,使用 Postgres 应用程序)而不是 Homebrew 安装)。我在随机留言板上遇到了其他几个人,他们遇到了同样的问题(也在新的 Mac 上)并且没有任何运气,这就是为什么我不愿意相信这是一个驱动器损坏问题。(我也多次运行磁盘工具急救检查;它说一切正常,但我不知道它有多可靠。)

我正在使用thoughtbot parity 将我的开发环境数据库与当前生产中的数据库同步。当我运行时development restore production,我在终端中得到数百行,看起来像下面的输出(这是在下载完成后立即但在继续创建默认值、处理数据、序列集等之前)。我相信这是问题的根源,但我不确定解决方案是什么:

pg_restore: dropping TABLE [table name1]
pg_restore: from TOC entry 442; 1259 15829269 TABLE [table name1] u1oi0d2o8cha8f
pg_restore: error: could not execute query: ERROR:  table "[table name1]" does not exist
Command was: DROP TABLE "public"."[table name1]";
pg_restore: dropping TABLE [table name2]
pg_restore: from TOC entry 277; 1259 16955 TABLE [table name2] u1oi0d2o8cha8f
pg_restore: error: could not execute query: ERROR:  table "[table name2]" does not exist
Command was: DROP TABLE "public"."[table name2]";
pg_restore: dropping TABLE [table name3]
pg_restore: from TOC entry 463; 1259 15830702 TABLE [table name3] u1oi0d2o8cha8f
pg_restore: error: could not execute query: ERROR:  table "[table name3]" does not exist
Command was: DROP TABLE "public"."[table name3]";
pg_restore: dropping TABLE [table name4]
pg_restore: from TOC entry 445; 1259 15830421 TABLE [table name4] u1oi0d2o8cha8f
pg_restore: error: could not execute query: ERROR:  table "[table name4]" does not exist
Command was: DROP TABLE "public"."[table name4]";

有没有其他人经历过这种情况?任何解决方案的想法将不胜感激。谢谢!

编辑:我能够在较旧的 MacBook Pro(也运行 Big Sur)上重现相同的问题,因此它似乎与 M1 无关,但可能与 Big Sur 相关。

回答

对此的最终解决方法

在尝试了其他答案中的所有解决方法后,我仍然偶尔会收到此错误。即使在转储和恢复数据库之后,切换到 M1-native postgres,运行各种维护脚本等。

在对 postgresql.conf 进行大量修改后,唯一可以无限期可靠地解决此问题的方法(此后没有收到错误):

在 postgresql.conf 中,更改:

max_worker_processes = 8

max_worker_processes = 1

进行此更改后,我将所有测试都抛出到了我之前出错的数据库中,并且一次也没有显示相同的错误。以前我在大约 2000 万条记录的数据库上运行的提取例程在处理 1-2 百万条记录后会给出错误地址错误。现在它完成了整个过程。

显然,减少并行工作线程的数量会降低性能,但这是我找到的唯一可靠且永久解决此问题的方法。

  • Good to know, but it seems more like a workaround than a fix. It sounds like postgres has some race bug that is avoided if the race has only one competitor 🙂

以上是基于ARM的M1Macw/BigSur上的Postgres错误的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>