MacOSX上でのPostgreSQLでinitdbがうまくいかない

一応解決したので書いておく。

MacportsからPostgreSQL8.1.5を入れたんだけど、initdbを動かすと途中でエラーが起こる。
メッセージを読んでみるとどうもshared_memoryがつくれないみたいなことを言ってる。
色々ググって見ると、ここの方も同じようなエラーが。同じく/etc/sysctl.confを書いてみてもダメ。

さらにググって見ると、

Article 18924 at 06/04/05 07:39:11 From: sdr0x07b6@mac.com Subject: [macosx-jp:18924] Mac OS X 10.4.6アップデートにてPostgreSQL起動失敗

というのを発見。元のドキュメントとSHMMAXの値とかが違うなーとか思いつつ、色々探っていくと

Re: SHMMAX seems entirely broken in OS X 10.4.2

10.4.2のときから何か問題があったのか。とりあえずここの設定を元にしたらinitdbが最後まで動いてくれました。

PostgreSQL: Documentation: Manuals: PostgreSQL 7.4: Server Run-time Environment
PostgreSQL: Documentation: Manuals: PostgreSQL 8.1: Managing Kernel Resources


MacOS X

In OS X 10.2 and earlier, edit the file /System/Library/StartupItems/SystemTuning/SystemTuning and change the values in the following commands:

sysctl -w kern.sysv.shmmax
sysctl -w kern.sysv.shmmin
sysctl -w kern.sysv.shmmni
sysctl -w kern.sysv.shmseg
sysctl -w kern.sysv.shmall

In OS X 10.3 and later, these commands have been moved to /etc/rc and must be edited there. Note that /etc/rc is usually overwritten by OS X updates (such as 10.3.6 to 10.3.7) so you should expect to have to redo your editing after each update.

In OS X 10.3.9 and later, instead of editing /etc/rc you may create a file named /etc/sysctl.conf, containing variable assignments such as

kern.sysv.shmmax=4194304
kern.sysv.shmmin=1
kern.sysv.shmmni=32
kern.sysv.shmseg=8
kern.sysv.shmall=1024
This method is better than editing /etc/rc because your changes will be preserved across system updates. Note that all five shared-memory parameters must be set in /etc/sysctl.conf, else the values will be ignored.

Beware that recent releases of OS X ignore attempts to set SHMMAX to a value that isn't an exact multiple of 4096.

SHMALL is measured in 4 kB pages on this platform.

In all OS X versions, you'll need to reboot to make changes in the shared memory parameters take effect.
PostgreSQL: Documentation: Manuals

コメント付きのドキュメントのほうにもMacOSX関係で書いてありますね。とりあえず本文に書かれている記述と実態が食い違ってるぽい。