I’ve long had issues with PostgreSQL 8.3 and now 8.4 refusing to start on my laptop which is really a pain for live demonstrations of ERDAS Apollo. I’m not sure if anyone else has similar problems, but I believe (or rather have a hunch) that it is something to do with “ungraceful” shutdowns of the db when you may lose power or consistently go to sleep. Its only ever occured on my laptop, so luckily postgres on a server is still stable as hell.
If you are getting something like the following in postgresql.log on Windows or are just tearing your hair out wondering why the service that was working before is no longer starting …
2009-12-04 09:05:37 WSTLOG: database system is ready to accept connections
FATAL: could not reattach to shared memory (key=240, addr=02690000): 487
2009-12-04 09:05:38 WSTLOG: autovacuum launcher started
2009-12-04 09:05:38 WSTLOG: background writer process (PID 9712) exited with exit code 1
2009-12-04 09:05:38 WSTLOG: terminating any other active server processes
2009-12-04 09:05:38 WSTLOG: all server processes terminated; reinitializing
2009-12-04 09:05:48 WSTFATAL: pre-existing shared memory block is still in use
2009-12-04 09:05:48 WSTHINT: Check if there are any old server processes still running, and terminate them.
To reliably fix things for me anyway,
- Delete postmaster.opts or postmaster.pid (if they exist) in your postgres data dir
- Kill the pg_ctl.exe process (if running)
- Start the postgres service
Success!

Related posts:
Chris,
I use PostgreSQL 8.4 on Windows (Vista x64) I confirm it never auto-starts properly. It was so annoying that I reconfigured the service to start it manually only and I hit “Start Server” option from PostgreSQL menu after every boot. I didn’t try to investigate it, manual startup seems to work quite well, but still sometimes I have try 1-3 times until it starts properly.
Did my suggestions work for you Mateusz? Good to know its not just me!
Thanks man! You saved my ass. I owe you a beer!
Chris, I haven’t actually checked your suggestion. I’ll do it tomorrow and report back.
Hey Iwo, beer is always welcome
Chris, I tried your trick and it’s been working for me for a day, however the logs still show the “reattach to shared memory” message from time to time.
Chris, the hack does not help, with time I’m getting more and more the reattach… messages and eventually the server disconnects all connections or goes down, so I have to restart.
Sorry to hear that Mateusz. I cant say mine is behaving like that at all ..
I made a slight typo in the original post, i said postmaster.opts or postmaster.pid when it should have read “and” not or. Although i doubt this will make any difference for you unfortunately
Yes, I remove correct files. Anyway, I boot my computer, I start PostgreSQL manually, and it works this way, more or less
Thanks!