Re: pg_version_history

From: Ezequiel Tolnay <mail(at)etolnay(dot)com(dot)ar>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: pg_version_history
Date: 2005-05-02 04:52:49
Message-ID: d54bla$vfg$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

> I found a table pg_version_history in the public schema (which we don't
> use). Does anyone know where this table comes from and what is it for?
>
> Also I'd like to implement a code versioning for the functions. Is there
> a package or a software to do this kind of things, so we can recover
> from it a function in case it is deleted or overwritten with an old
> version?

It is a pretty dumb thing to reply to myself, but perhaps I can share
with the newsgroup readers the solution I found for this issue. Although
not as convenient as I was looking for, it does the job.

It requires the use of a cvs server, and some skills to set-up a new
folder in it. Windows users would require to use cygwin for the script,
with cron and cvs.

Create the following script somewhere:

#!/bin/bash
DB=<db-name>
USR=<db-admin-user>
PWD=<db-admin-pwd>
DUMP=<pg-bin-dir>/pg_dump
SCRIPT_PATH=<script-path>
SCRIPT=${DB}-schema.sql
pushd $SCRIPT_PATH
echo $PWD | $DUMP -sC -U $USR $DB > $SCRIPT 2> /dev/null && \
cvs commit -m "" $SCRIPT > /dev/null
popd

Replace the variable values with whatever you prefer and run the
command. It should fail to upload the script to the cvs server. Now
login to the cvs and create a new repository for this folder and add the
schema file generated.

Finally set-up a cron job to call the script once every hour, or as
often as it suits you.

The script will keep track of the changes in the schema file maintained
by the cvs. Not very efficient, since there will be no references as to
what has changed on each version, or who made the changes, but still
useful to recover accidentally deleted/modified functions or views and
so forth. I hope this is useful to anyone.

Regards,

Ezequiel Tolnay
etolnay(at)gbtech(dot)com(dot)au

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Gourish Singbal 2005-05-02 05:11:52 Re: measuring most-expensive queries
Previous Message Enrico Weigelt 2005-05-02 03:18:30 measuring most-expensive queries