Re: serverlog rotation/functions

From: Andreas Pflug <pgadmin(at)pse-consulting(dot)de>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: serverlog rotation/functions
Date: 2004-07-16 08:19:01
Message-ID: 40F78F75.6010401@pse-consulting.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Bruce Momjian wrote:
> Andreas Pflug wrote:
>
>>>You do something that splits the value into directory name and file name
>>>and removes every letter after %.
>>>
>>> /var/log
>>> postgresql.log.%-%-%_%%%
>>>
>>>Another idea is to allow filename wildcards in the listing so it
>>>becomes:
>>>
>>> SELECT *
>>> FROM dir_listing('/var/log/postgresql.log.*-*-*_***') AS dir
>>>
>>>While that is nice, it doesn't match the functionality of opendir so we
>>>are perhaps better with one that doesn't handle wildcards and we just do
>>>the wildcard processing in the WHERE clause.
>>
>>Uh, this looks ugly.
>>
>>How about
>>pg_logfile_list() RETURNS setof timestamp -- to list available logfiles
>>pg_logfile_filename(timestamp) to return filename for that logfile
>
>
> I don't see the need to return timestamps. If you select any empty
> directory, you can just return the file names. The only reason you
> might need a pattern is to distinguish pg log files from other log
> files. If you want, create a server-side function that returns the file
> name with the strftime() patterns converted to '*'.
>
>
>>and generic
>>pg_dir(wildcard_text)
>
>
> Maybe pg_dir_ls().
>
> OK, it would be nice if we could do a sed operation like:
>
> sed 's/%./*/g'
>
> but I don't know a way to do that without defining a function or pulling
> in a procedural language, but if we could do it we could do:
>
> pg_dir(echo log_destination | sed 's/%./*/g')
>

Argggg.... ever used sed on win32?!? And how should the timestamp be
represented in client tools? Date/time interpretation is always a source
of problems, so *please* let the server do that.

Rethinking all this, I'd like the pg_logfile_list to return a complex type:

CREATE TYPE pg_logfile_list AS (
filedate timestamp,
filename text,
backendpid int,
inuse bool)

and

pg_logfile_list() RETURNS SETOF pg_logfile_list

which would enable

SELECT filename,
pg_file_unlink(filename)
FROM pg_logfile_list()
WHERE filedate < current_timestamp - '3 months'::interval
AND NOT inuse

In-use check is easy for the backend, if the syslog process publishes
the current logfile's timestamp in sharedmem.

We can use a GUC variable for the log_directory (not log_destination);
anyway, I'd like the filenames to be selected by the server.

Regards,
Andreas

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Magnus Hagander 2004-07-16 08:50:19 Re: [HACKERS] Weird new time zone
Previous Message Simon Riggs 2004-07-16 07:40:44 Re: Point in Time Recovery

Browse pgsql-patches by date

  From Date Subject
Next Message Magnus Hagander 2004-07-16 09:07:51 Re: initdb authentication
Previous Message Simon Riggs 2004-07-16 07:40:44 Re: Point in Time Recovery