Thread: [GENERAL] delete a file everytime pg server starts/crashes
Hi, I'm having a requirement to delete a file in system whenever pg server is started/crashed. Any idea? Thanks, Athi -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
On Thu, Oct 5, 2017 at 10:04 AM, athinivas <athinivas@gmail.com> wrote:
Hi,
I'm having a requirement to delete a file in system whenever pg server is
started/crashed. Any idea?
Thanks,
Athi
--
Sent from: http://www.postgresql-archive.org/PostgreSQL-general- f1843780.html
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
It would be nice to know your Operating System and PostgreSQL version().
That being said, have you looked at the documentation for "shared_preload_libraries" ?
--
Melvin Davidson
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.
On Thu, Oct 5, 2017 at 10:04 AM, athinivas <athinivas@gmail.com> wrote:Hi,
I'm having a requirement to delete a file in system whenever pg server is
started/crashed. Any idea?
Thanks,
Athi
If you’re running on Linux you can modify the init.d (or service) file and add a line to delete the file.
To remove on crash is likely to require some sort of ongoing monitoring service to see that the process is no longer running.
If you’re already using a service (such as monit) which brings an application back up after crash then adding a line to the init.d file may be sufficient.
—Ray
--
Raymond Cote, President
voice: +1.603.924.6079 email: rgacote@AppropriateSolutions.com skype: ray.cote
Schedule a meeting: https://calendly.com/ray_cote/60min/
That seems like an odd requirement and I don't think PostgreSQL can do it itself, because if postgresql should crash properly then the process that should write/remove that file would also crash The simplest way would be to write a cronjob that connects to the database and does a simple query to see if things are ok, and act accordingly. But cronjobs cannot be executed more than once a miunute so there would be a considerable delay. If you need faster responses you may need to write a custom deamon or use something like supervisord to manage a long polling script. I get the feeling there must be a more elegant solution to whatever your problem is though... On 2017-10-05 16:04, athinivas wrote: > Hi, > > I'm having a requirement to delete a file in system whenever pg server > is > started/crashed. Any idea? > > Thanks, > Athi > > > > -- > Sent from: > http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Look at inotify: https://github.com/rvoicilas/inotify-tools You can check for instance if postmaster.pid exists. -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Actually if the name of the file doesn't matter you could put it into $PGDATA/pg_stat and name it global.stat. When postgres stops (clean or because of failure), replaces the file with his own. So your content will be erased. I'm not sure it's completely safe but works in simple test. -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Hi, Thank you...will try it :) ...As of now, I'm creating the filename as pg_start_time so that, every time the server is up, a new file will be created. Regards, Athi -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
On Sun, Oct 8, 2017 at 8:33 AM, athinivas <athinivas@gmail.com> wrote:
Hi,
Thank you...will try it :) ...As of now, I'm creating the filename as
pg_start_time so that, every time the server is up, a new file will be
created.
Regards,
Athi
--
Sent from: http://www.postgresql-archive.org/PostgreSQL-general- f1843780.html
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
>... I'm creating the filename as pg_start_time...
Just an FYI, you do know that
SELECT pg_postmaster_start_time();
will return start time for postgres?
--
Melvin Davidson
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.
Yes, will take the epoch value from same and create a new file. Upon subsequent calls, will access with that filename...if it fails(incase if the postmaster is restarted), will create a new one. @Melvin Does this capture all failure scenarios?? Or you have any other better ways to do it. Your comments are much appreciated !! -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
On Sun, Oct 8, 2017 at 10:01 AM, athinivas <athinivas@gmail.com> wrote:
Yes, will take the epoch value from same and create a new file. Upon
subsequent calls, will access with that filename...if it fails(incase if the
postmaster is restarted), will create a new one.
@Melvin Does this capture all failure scenarios?? Or you have any other
better ways to do it. Your comments are much appreciated !!
--
Sent from: http://www.postgresql-archive.org/PostgreSQL-general- f1843780.html
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
athinivas,
This is covered in the documentation:
9.25. System Information Functions
pg_postmaster_start_time()
pg_postmaster_start_time()
It does not matter what caused the failure, it is the time Postgres is started again.
--
Melvin Davidson
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.