News for hackers. Stuff that matters.
Re:Recursive Postgres Queries by btilly on Monday June 24, 2013 @10:02PM (#5937042)
Use case for you based on a real example. Early Monday morning, your site goes down under load. You really want a DBA to be able to hop on it, identify that the cause is, for instance, a poorly executing query, and lock a decent query plan in place.

Oracle lets DBAs do that, but I've not seen a database migration tool that knows how to understand/express that.

Secondly when it comes time to update your schema, the easiest solution is to simply lock tables and do updates. However locking the table can involve a forced outage. If, however, you limit yourself to very specific kinds of updates, then you can update your schema without major outages. Now rolling forward is cheap. Rolling it back is very, very expensive. Tools generally just try to do what you asked, and don't know how to say, "Really?"

If you pay attention to this, then you want to be able to just roll forward. And you want to be able to roll your database forward independently of the web server. Now you have the option of rolling the database forward, then rolling out a new version of the web server code. Should you have an emergency problem, roll the web server code back, and leave the database on the new version. (This only works if the database is "dumb".)

One strategy to support this is to let the DBAs be in charge of the schema, separately from your development tree. Developers are allowed to create patches that alter the database on dev, and will submit those patches to the DBAs. If the DBAs do not object to the change, they are in charge of putting it on QA or production. (If the DBA does object, of course, it goes nowhere.)

And now the pattern is that DBAs maintain the official definition of the database. DBAs are willing to apply proven patches to production, and can make QA a clone of production whenever they want. In emergencies, DBAs can fix problems directly on production. (You try to have this happen as little as possible.) All developer changes to the database schema have to be blessed by DBAs. Database patches need to be applied in production separately from and strictly before release.

I've seen a number of different strategies for handling database schemas and code. This is the one that, in my opinion, worked best in practice.

Re:Recursive Postgres Queries by joevandyk on Tuesday June 25, 2013 @03:50AM (#5938107)
Oracle lets DBAs do that, but I've not seen a database migration tool that knows how to understand/express that.

I'm assuming that Oracle lets you do this via some sort of a sql file/script? I'd think the process would be:

1. Create SQL file that locks the query plan

2. Test it

3. Check into version control

4. Using migration tool, apply to production database

PostgreSQL lets you do all sorts of updates without locks, fwiw, and that's what I'm most experienced with. And all postgresql administration can be done via text files that can be checked into version control.

Re:Recursive Postgres Queries by btilly on Tuesday June 25, 2013 @01:05PM (#5940865)
I'm assuming that Oracle lets you do this via some sort of a sql file/script?

Not that I know of. When I took the SQL tuning class where I learned about it, they had an interactive admin panel for tracking down, identifying, and fixing query plans.

But I'm not a DBA, I haven't used Oracle in a few years, and I do not know what all is available there.

Re:Recursive Postgres Queries by just_hobbyst on Tuesday June 25, 2013 @08:19AM (#5938877)
That would be interesting - but I wonder if it makes sense.

@btilly: what is the name of the thing with locking queries you referred to?

Re:Recursive Postgres Queries by btilly on Tuesday June 25, 2013 @01:11PM (#5940918)
Any upgrade script that does certain operations will lock tables as it goes. See your database documentation for details. This can include rebuilding indexes, removing columns, modifying existing columns, etc. Furthermore when you've got both stored procedures and tables changing, you have to get the order of operations correct. I'm not aware of any automated tool that can figure out the dependencies and do so correctly. (Mind you I have not looked recently.)