Postgresql – connecting to PostgreSQL fails with semctl … invalid argument

postgresqltruenas

I ran initdb, tried to create a new superuser with createuser -sdrP myuser

The error I'm getting is

createuser: could not connect to database postgres: FATAL: semctl(3342342, 3, SETVAL, 0) failed: Invalid argument

I can't find anything about this anywhere on the internet. I've tried deinstalling, removing the data directory, and trying again but no dice. I'm at my wits end.

I'm running inside a jail, which is running FreeBSD 9.2-RELEASE-p10. And yes, I've set allow.sysvipc=1

Best Answer

PostgreSQL is most likely not finding the semaphore it created previously. It is possible another (unrelated) process is deleting the semaphores (perhaps a script calling ipcrm).

Use ipcs -s to list sempahores immediately after starting PostgreSQL and then again when you experience the problem. Unless another process is actively deleting the semaphores faster than you can run the ipcs -s test after PostgreSQL startup, you should be able to determine if the PostgreSQL semaphores are in fact being deleted by comparing the two sempahore listings.

This doesn't tell you which (root) process is the culprit, but it does point you in the right direction. With any luck, the offending process is a script in which case you could search for root executed scripts that perform ipcrm calls.