Index syndication
comment syndication

OpenBSD, postgresql and semaphore failures during initdb

April 22, 2008 at 1:54 · Filed under openbsd, unix

Today I upgraded my postgresql database instance on OpenBSD. Did a pg_dumpall, removed the old packages and then added the new ones (latest version 8.1.9 for OpenBSD 4.0 - yes I’m behind).

During the initialisation of the new DB, I got the following error:

creating directory /var/postgresql/data/pg_tblspc ... ok
selecting default max_connections ... 10
selecting default shared_buffers ... 50
creating configuration files ... ok
creating template1 database in /var/postgresql/data/base/1 ... FATAL:  could not create semaphores: No space left on device
DETAIL:  Failed system call was semget(1, 17, 03600).

The PostgreSQL documentation talks about this extensively. However I don’t want to recompile my kernel away from default. What else can I do?

AFAIK It is not possible to pass the max_connections to initdb.

After some searching, I found the solution. It looks like the problem is that the semaphores from the old installation are still hanging around, and never got cleaned up. You can use ipcs and ipcrm to clean then up and run your initdb again.

First list the existing semaphores:

server:~# ipcs                                                                                                  
Message Queues:
T       ID     KEY        MODE       OWNER    GROUP
 
Shared Memory:
T       ID     KEY        MODE       OWNER    GROUP
m    65536    5432001 --rw------- _postgresql _postgresql
 
Semaphores:
T       ID     KEY        MODE       OWNER    GROUP
s  1376256          0 --rw-------      www      www
s  1245185          0 --rw-------      www      www
s    65538    5432001 --rw------- _postgresql _postgresql
s    65539    5432002 --rw------- _postgresql _postgresql
s    65540    5432003 --rw------- _postgresql _postgresql
s    65541       5419 --rw-r--r--      www      www

You want to remove the semaphore sets according to the ipcrm man page:

server:~# ipcrm -s 65538   
server:~# ipcrm -s 65539 
server:~# ipcrm -s 65540 

Using ipcs shows the _postgresql semaphores gone:

Semaphores:
T       ID     KEY        MODE       OWNER    GROUP
s  1376256          0 --rw-------      www      www
s  1245185          0 --rw-------      www      www
s    65541       5419 --rw-r--r--      www      www

Now you can switch to the postgres account and run your initdb:

server:/usr/local/share/postgresql# su - _postgresql 
#initdb                                                                                                         
The files belonging to this database system will be owned by user "_postgresql".
This user must also own the server process.
 
The database cluster will be initialized with locale C.
 
creating directory /var/postgresql/data ... ok
creating directory /var/postgresql/data/global ... ok
creating directory /var/postgresql/data/pg_xlog ... ok
creating directory /var/postgresql/data/pg_xlog/archive_status ... ok
creating directory /var/postgresql/data/pg_clog ... ok
creating directory /var/postgresql/data/pg_subtrans ... ok
creating directory /var/postgresql/data/pg_twophase ... ok
creating directory /var/postgresql/data/pg_multixact/members ... ok
creating directory /var/postgresql/data/pg_multixact/offsets ... ok
creating directory /var/postgresql/data/base ... ok
creating directory /var/postgresql/data/base/1 ... ok
creating directory /var/postgresql/data/pg_tblspc ... ok
selecting default max_connections ... 40
selecting default shared_buffers ... 1000
creating configuration files ... ok
creating template1 database in /var/postgresql/data/base/1 ... ok

And so on it goes successfully creating your initial DB.
I hope this helps someone else!

Share this post: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Slashdot
  • Technorati
  • Reddit
  • StumbleUpon
  • Facebook
  • Propeller
  • BlogMemes
  • Google
  • YahooMyWeb
  • NewsVine

Leave a Comment