473,387 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Tracking structural changes from psql

Hi everyone.

I'm searching for a quick and dirty way to have psql record the
SQL statements that I enter, especially those related to the database
structure.

My main motivation is to help keep what will probably be a production
server up-to-date with my development server. I've thought a little
about replication, but the current options for that seem like overkill
for the relatively small database that I have. I'm particularly
interested in tracking data-definition related statements, which I
mostly tend to run through psql. (eg. Creating and altering objects,
plus the occasional insert and update thrown in.)
psql supports a couple of output-to-file options, but apparently not
really for what I want. eg. \o will output query results to a file,
and \w will save the current query buffer to a file.

What I'd really like is to have the commands that I execute logged to a
file semi-automatically as I execute them, without having to remember to
save it afterwards prior to closing psql. The occasional inconsistency
won't be too important because I'll probably review it before actually
using it, but simply having an output file that contains a history of
sql statements, perhaps with commented datestamps, would be quite useful.

If anyone with some experience could point me to a simple way to do
this, I'd appreciate it. Have I overlooked anything in particular?
It also occurs to me that an even more useful utility might be one that
stores the structural state of the database at a particular time (such
as when I last updated the production server), and then generate a diff
of SQL statements to update it to the current structural state. I don't
suppose this already exists anywhere, does it?
Thanks for any help.
Mike.
Nov 23 '05 #1
7 1777

Mike McGavin <je****@NOSPAM.mcsnospam.vuw.acNOSPAM.nz> writes:
Hi everyone.

I'm searching for a quick and dirty way to have psql record the SQL
statements that I enter, especially those related to the database structure.
Well the server logs all that information.
log_statement = true

IIRC in CVS this has even been separated into two options for ddl and dml.
It also occurs to me that an even more useful utility might be one that stores
the structural state of the database at a particular time (such as when I last
updated the production server), and then generate a diff of SQL statements to
update it to the current structural state. I don't suppose this already exists
anywhere, does it?


You can pg_dump -s the two and diff them. You'll find the OIDs in SQL comments
which throw off the diff. I have a little sed line that strips them out.

And the objects are printed in creation order, so if you created the objects
in different orders on the two servers you'll get spurious differences.

I believe both of these issues are improved in the current CVS tree. You
should be able to build from CVS and use that pg_dump against your current
server though.

Alternatively you could look at Alzabo which I understand can do schema diffs
and generate scripts to sync schemas. Haven't tried it though.

--
greg
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #2

Mike McGavin <je****@NOSPAM.mcsnospam.vuw.acNOSPAM.nz> writes:
Hi everyone.

I'm searching for a quick and dirty way to have psql record the SQL
statements that I enter, especially those related to the database structure.
Well the server logs all that information.
log_statement = true

IIRC in CVS this has even been separated into two options for ddl and dml.
It also occurs to me that an even more useful utility might be one that stores
the structural state of the database at a particular time (such as when I last
updated the production server), and then generate a diff of SQL statements to
update it to the current structural state. I don't suppose this already exists
anywhere, does it?


You can pg_dump -s the two and diff them. You'll find the OIDs in SQL comments
which throw off the diff. I have a little sed line that strips them out.

And the objects are printed in creation order, so if you created the objects
in different orders on the two servers you'll get spurious differences.

I believe both of these issues are improved in the current CVS tree. You
should be able to build from CVS and use that pg_dump against your current
server though.

Alternatively you could look at Alzabo which I understand can do schema diffs
and generate scripts to sync schemas. Haven't tried it though.

--
greg
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #3
Mike McGavin <je****@NOSPAM.mcsnospam.vuw.acNOSPAM.nz> writes:
It also occurs to me that an even more useful utility might be one
that stores the structural state of the database at a particular time
(such as when I last updated the production server), and then generate
a diff of SQL statements to update it to the current structural state.
I don't suppose this already exists anywhere, does it?


You might want to try:

http://zongle.sourceforge.net/
http://pgdiff.sourceforge.net/
http://gborg.postgresql.org/project/...rojdisplay.php

--
Daniel Vérité - daniel at manitou dash mail dot org
Nov 23 '05 #4
Mike McGavin <je****@NOSPAM.mcsnospam.vuw.acNOSPAM.nz> writes:
It also occurs to me that an even more useful utility might be one
that stores the structural state of the database at a particular time
(such as when I last updated the production server), and then generate
a diff of SQL statements to update it to the current structural state.
I don't suppose this already exists anywhere, does it?


You might want to try:

http://zongle.sourceforge.net/
http://pgdiff.sourceforge.net/
http://gborg.postgresql.org/project/...rojdisplay.php

--
Daniel Vérité - daniel at manitou dash mail dot org
Nov 23 '05 #5
Check out your .psql_history file and \s <filename> from within psql.

Robert Treat

On Sat, 2004-05-01 at 23:53, Mike McGavin wrote:
Hi everyone.

I'm searching for a quick and dirty way to have psql record the
SQL statements that I enter, especially those related to the database
structure.

My main motivation is to help keep what will probably be a production
server up-to-date with my development server. I've thought a little
about replication, but the current options for that seem like overkill
for the relatively small database that I have. I'm particularly
interested in tracking data-definition related statements, which I
mostly tend to run through psql. (eg. Creating and altering objects,
plus the occasional insert and update thrown in.)
psql supports a couple of output-to-file options, but apparently not
really for what I want. eg. \o will output query results to a file,
and \w will save the current query buffer to a file.

What I'd really like is to have the commands that I execute logged to a
file semi-automatically as I execute them, without having to remember to
save it afterwards prior to closing psql. The occasional inconsistency
won't be too important because I'll probably review it before actually
using it, but simply having an output file that contains a history of
sql statements, perhaps with commented datestamps, would be quite useful.

If anyone with some experience could point me to a simple way to do
this, I'd appreciate it. Have I overlooked anything in particular?
It also occurs to me that an even more useful utility might be one that
stores the structural state of the database at a particular time (such
as when I last updated the production server), and then generate a diff
of SQL statements to update it to the current structural state. I don't
suppose this already exists anywhere, does it?
Thanks for any help.
Mike.

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)


--
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #6
Check out your .psql_history file and \s <filename> from within psql.

Robert Treat

On Sat, 2004-05-01 at 23:53, Mike McGavin wrote:
Hi everyone.

I'm searching for a quick and dirty way to have psql record the
SQL statements that I enter, especially those related to the database
structure.

My main motivation is to help keep what will probably be a production
server up-to-date with my development server. I've thought a little
about replication, but the current options for that seem like overkill
for the relatively small database that I have. I'm particularly
interested in tracking data-definition related statements, which I
mostly tend to run through psql. (eg. Creating and altering objects,
plus the occasional insert and update thrown in.)
psql supports a couple of output-to-file options, but apparently not
really for what I want. eg. \o will output query results to a file,
and \w will save the current query buffer to a file.

What I'd really like is to have the commands that I execute logged to a
file semi-automatically as I execute them, without having to remember to
save it afterwards prior to closing psql. The occasional inconsistency
won't be too important because I'll probably review it before actually
using it, but simply having an output file that contains a history of
sql statements, perhaps with commented datestamps, would be quite useful.

If anyone with some experience could point me to a simple way to do
this, I'd appreciate it. Have I overlooked anything in particular?
It also occurs to me that an even more useful utility might be one that
stores the structural state of the database at a particular time (such
as when I last updated the production server), and then generate a diff
of SQL statements to update it to the current structural state. I don't
suppose this already exists anywhere, does it?
Thanks for any help.
Mike.

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)


--
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #7
Hi everyone.

Mike McGavin wrote:
I'm searching for a quick and dirty way to have psql record the
SQL statements that I enter, especially those related to the database
structure.


I just wanted to say thanks for the responses that I had to this query,
both in the newsgroup and email. They've been very helpful.

Mike.
Nov 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: LC | last post by:
hi, i worry about people doing something they shouldn't to my db and I would like to track any structural changes (who and which)to my db. I am using oracle 8.0.6.0.0 and 9.2.0.2.0. regards,...
4
by: CSN | last post by:
Is there a way to have p/k sequences get automatically set to max(id)+1 after COPY's like the following? copy table1 (id,name) from stdin; 1 abc 2 def 3 fhi \.
3
by: johnny boy | last post by:
Hi, Is there any simple or easy way to track changes in Access in between saving access files? I think the answer is probably no but maybe someone can help. John
1
by: Muddassir | last post by:
hi everybody I am writing an application for tracking files and directory changes I used FindFirstChangeNotification FindNextChangeNotification FindCloseChangeNotification...
4
by: Glenn Owens | last post by:
I have a DataGrid web control which I've dynamically populated with template columns to be used for bulk-editting. Generally, all of the columns are textbox and/or dropdownlist child controls. ...
1
by: fred tate via .NET 247 | last post by:
I'm working on a project that will track a great deal of data forindividuals and will keep track of users for a very long time (5- 10) years. I'm looking for options as far as tracking anddisplaying...
0
by: Mike McGavin | last post by:
Hi everyone. I'm searching for a quick and dirty way to have psql record the SQL statements that I enter, especially those related to the database structure. My main motivation is to help...
2
by: Graville | last post by:
All, OK wasn't sure where to post this one but this should hopefully be ok. I am looking for a way to streamline some of the process within our dev team. One of the areas that often takes time...
4
by: tagg3rx | last post by:
Hi all, hoping someone can point me towards a version tracking system for .net development. My projects are starting to get kind of large and my bosses want me to implement some form of version...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.