logfile subprocess and Fancy File Functions

From: Andreas Pflug <pgadmin(at)pse-consulting(dot)de>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org>
Subject: logfile subprocess and Fancy File Functions
Date: 2004-07-17 19:56:34
Message-ID: 40F98472.1060205@pse-consulting.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

The attached patch and additional src/backend/postmaster/syslogger.c
implements the logfile subprocess as discussed.

TODO:
- documentation
- win32 code (forkexec) is included, but not tested (no build env)

Functions (all are superuser only):

int4 pg_reload_conf()
Sends SIGHUP to postmaster

bool pg_logfile_rotate()
initiates logfile rotation, same does SIGUSR1 to the syslogger
subprocess; returns true if logging is enabled

setof record pg_logfiles_ls()
lists all available logfiles, should we have a view as well?
CREATE VIEW pg_logfiles AS
SELECT ts, pid, fn
FROM pg_logfiles_ls()
AS pgls(ts timestamp, pid int4, fn text)

int8 pg_file_length(filename_text)
returns length of file, or -1 if non existent (no ERROR)

text pg_file_read(filename_text, startpos_int6, length_int8)
reads file

int8 pg_file_write(filename_text, data_text, append_bool)
writes file. creates or appends
to create, file must not exist, to append, file may exist.

bool pg_file_rename(filename_old_text, filenamenew_text)
rename file

bool pg_file_unlink(filename_text)
unlinks file. returns true/false if done (no ERROR)

bool pg_file_rename(filename_old_text,
filename_new_text, filename_archive_text)
chain rename: new->archive, old->archive, example:

It should be quite safe to do

pg_file_write('postgresql.conf.tmp',
'.....some stuff...', false);
pg_file_unlink('postgresql.conf.bak');
pg_file_rename('postgresql.conf.tmp',
'postgresql.conf', 'postgresql.conf.bak');
pg_reload_conf();

Regards,
Andreas

Attachment Content-Type Size
syslogger.c text/x-csrc 13.1 KB
logfile.diff text/x-patch 24.7 KB

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2004-07-17 20:15:21 Re: [HACKERS] Point in Time Recovery
Previous Message Tom Lane 2004-07-17 19:22:17 Re: Subtransaction documentation