need to delete postmaster.pid file. automate it?
need to delete postmaster.pid file. automate it?
От:
mlaks <mlaks@bellatlantic.net>
Дата:
Hii! I am using Postgresql 7.2.1 on Redhat Linux 7.3 as the database that supports another application. At bootup, the other application checks whether or not Postgresql is running and if Postgresql is not running, it fails. The system has been quite stable and has run for almost nonstop for many months. However, ocassionally something goes wrong and the application fails because Postgresql goes down. I believe it is usually when the there is a power surge in the Hospital where these machines reside. This application failure seems to be due to an improper shutdown of Postgresql. Sometimes when the database backed application fails it can be restarted by simply rebooting the machine. Postgresql gets restarted and then the application can get started during normal bootup. However, sometimes Postgresql won't start. When I intervene manually, and attempt to run pg_ctl stop, I get an error that there is not any postgresql process, and then when I run pg_ctl start, the message says something about memory being reserved (I don't really remember the exact message- but whatever - Postgresql nicely tells me to proceed to delete the file /var/lib/pgsql/data/ostmaster.pid. I do that and then all is fine. I can then restart Postgresql with pg_ctl start and then the application needing Postgresql starts nicely. I would like to automate this process of deleting postmaster.pid if postgresql is not running and would like to ask my question . What risk is there in automating the process (say via perl or shell script). Also advice on how to do it. So I would start my application, if that fails, check if postgresql is running (? perhaps with ps -aux|grep postgresql ) then restart postgresql, check for an error, and if that fails, delete postmaster.pid and restart pg_ctl start, and then start up the database backed application. Are there any pitfalls that I am not aware of? Thank you, Mitchell Laks
Re: need to delete postmaster.pid file. automate it?
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
mlaks writes: > I would like to automate this process of deleting postmaster.pid if > postgresql is not running and would like to ask my question . It is safe (and probably a good idea) to delete postmaster.pid in a shell script that runs *ONLY DURING BOOTUP*. Do *not* put such a command into a script that you might run as a means of manually restarting the postmaster --- because if you do, you just lost your interlock against starting two postmasters for the same database. Which, trust me, is not an interlock you want to lose. There are quite a few other standard daemons, for instance sendmail, that have similar issues with leftover lockfiles after a system crash. If you dig around in your boot scripts you may find one that's already designed to remove unwanted lockfiles at system boot. That'd be the place to add "rm /var/lib/pgsql/data/postmaster.pid". But do not put it into anything that could be triggered after initial system startup, unless you enjoy the sensation of shooting yourself in the foot. regards, tom lane