Re: [GENERAL] delete a file everytime pg server starts/crashes

2017-10-08 Thread Melvin Davidson
On Sun, Oct 8, 2017 at 10:01 AM, athinivas  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:*


*https://www.postgresql.org/docs/9.6/static/functions-info.html
*

*9.25. System Information Functions*
*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.


Re: [GENERAL] delete a file everytime pg server starts/crashes

2017-10-08 Thread athinivas
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


Re: [GENERAL] delete a file everytime pg server starts/crashes

2017-10-08 Thread Melvin Davidson
On Sun, Oct 8, 2017 at 8:33 AM, athinivas  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.


Re: [GENERAL] delete a file everytime pg server starts/crashes

2017-10-08 Thread athinivas
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


Re: [GENERAL] delete a file everytime pg server starts/crashes

2017-10-06 Thread pinker
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


Re: [GENERAL] delete a file everytime pg server starts/crashes

2017-10-06 Thread pinker
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


Re: [GENERAL] delete a file everytime pg server starts/crashes

2017-10-06 Thread vinny
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


Re: [GENERAL] delete a file everytime pg server starts/crashes

2017-10-05 Thread Ray Cote
>
> On Thu, Oct 5, 2017 at 10:04 AM, athinivas  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: rgac...@appropriatesolutions.com skype:
ray.cote
Schedule a meeting: https://calendly.com/ray_cote/60min/


Re: [GENERAL] delete a file everytime pg server starts/crashes

2017-10-05 Thread Melvin Davidson
On Thu, Oct 5, 2017 at 10:04 AM, 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
>

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" ?

*https://www.postgresql.org/docs/9.6/static/runtime-config-client.html
*

-- 
*Melvin Davidson*
I reserve the right to fantasize.  Whether or not you
wish to share my fantasy is entirely up to you.


[GENERAL] delete a file everytime pg server starts/crashes

2017-10-05 Thread athinivas
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