Re: [sqlalchemy] obtaining pid of forked process
On Feb 11, 2010, at 18:58 , Faheem Mitha wrote: sqlalchemy forks a process when it calls the db No, it does not. The reason for this is that I want to plot a memory graph of the postgresql process, so it is handy to have the pid for this. PostgreSQL forks a new backend process when a connection is established, however. It sounds like that's what you want. Do SELECT pg_backend_pid() to get the PID of the backend process serving your connection. That and other stat functions are documented here: http://www.postgresql.org/docs/current/static/monitoring-stats.html -- Alex Brasetvik -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] How to diagnose a transaction hang problem?
On Jan 29, 2010, at 15:01 , 一首诗 wrote: What might cause this kind of problem? Possibly waiting on locks. Do you have any concurrent transactions modifying the same data? When the problem appears, run `select * from pg_stat_activity` to see whether there are locking issues. To see the locks involved, run `select * from pg_locks`. -- Alex Brasetvik -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Expressing UPDATE...SET column = column + 1
On 12/20/09 13:31 , Igor Katson wrote: I want to increment a column by 1 with UPDATE table SET column = column + 1 WHERE id = %(id)s, This is covered here: http://www.sqlalchemy.org/docs/06/sqlexpression.html however, when writing instance.column += 1 in python, it translates it to UPDATE table SET column = OLD_VALUE + 1 That's because instance.column returns the integer value. If you do table.c.column + 1, however, that will return a _BinaryExpression. So, what you want, is something like table.update(where_clause, dict(column=table.c.column + 1) Hope this helps. -- Alex Brasetvik -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Multi-column primary key with autoincrement?
On Dec 16, 2009, at 09:32 , Adrian von Bidder wrote: sqlite is convenient for development though Except when it *adds* complexity? ;-) -- Alex Brasetvik -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] performance issues
On Dec 15, 2009, at 16:30 , Antoine Pitrou wrote: I've got some scripts which take quite a bit of time and I wanted to investigate why they were so long. (..) I should point out that this particular script doesn't manipulate that many objects (a few thousands of them perhaps), and the queries aren't complex at all. It would be good to know whether there are well known techniques to help reduce the overall overhead of SQLAlchemy [...] It would probably help if you showed us your current approach first. :-) -- Alex Brasetvik -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Re: how to make a transaction fail for testing?
On Dec 14, 2009, at 22:28 , iain duncan wrote: I guess for integration tests one could also monkey patch it to override the commit method? Some of the mocking frameworks will help you with that as well. :-) -- Alex Brasetvik -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Postgres INHERITS and concrete table inheritance
On Dec 15, 2009, at 17:59 , Michael Bayer wrote: My understanding is that INHERITS is usually used in practice to provide transparent sharding of table data and not necessarily to express class hierarchies, but this is strictly anecdotal knowledge. Agreed. The PostgreSQL documentation[1] mentions many caveats with INHERITS, most notably: A serious limitation of the inheritance feature is that indexes (including unique constraints) and foreign key constraints only apply to single tables, not to their inheritance children. This is true on both the referencing and referenced sides of a foreign key constraint. For those reasons it is also actively *discouraged* for expressing class hierarchies. To put that into context, consider the following: CREATE TABLE vehicle ( id integer NOT NULL, owner_id integer, price integer, primary key (id) -- I added this ); CREATE TABLE vehicle_bus ( passengers integer ) INHERITS (vehicle); CREATE TABLE vehicle_whatever( id integer primary key references vehicle(id), whatever text ); INSERT INTO vehicle_bus VALUES (1, 1, 42, 123); SELECT * FROM vehicle; id | owner_id | price +--+--- 1 |1 |42 (1 row) SELECT * FROM vehicle_bus; id | owner_id | price | passengers +--+---+ 1 |1 |42 |123 (1 row) INSERT INTO vehicle_whatever VALUES (1, 'but clearly this is in vehicle, no?'); ERROR: insert or update on table vehicle_whatever violates foreign key constraint vehicle_whatever_id_fkey DETAIL: Key (id)=(1) is not present in table vehicle. ~ [1] http://www.postgresql.org/docs/8.4/static/ddl-inherit.html -- Alex Brasetvik -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] how to make a transaction fail for testing?
On Dec 13, 2009, at 22:25 , iain duncan wrote: Hey folks, I'm wondering how I can make a transaction fail deliberately for testing how my transaction handling code is working. Is there some simple mechanism for making sure a section in a try block with session.commit() raises an exception without altering the code? Mock the session/connection. There are several mocking libraries for Python - http://www.google.com/search?q=python+mock+objects Personally, I prefer Mocker, which supports patching which is handy in this case --- http://labix.org/mocker#head-83d80b643ee8544628ee7a8301a72443ac51a173 If you are unfamiliar with the technique, this looks like a decent introduction: http://agiletesting.blogspot.com/2009/07/python-mock-testing-techniques-and.html Hope this helps. :-) Regards, Alex Brasetvik -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] why this script lead to memory error?
On Dec 10, 2009, at 05:50 , Feng wrote: Hi all, when I query into a big table, it lead to memory error. (...) for record in al_records: #there are 18 million records in the table variation pass This is loading every record into memory before even starting processing the first one. See the discussion at http://groups.google.com/group/sqlalchemy/browse_thread/thread/a32916af437cc366 With the new OurSQL-dialect and #1619 this should hopefully improve. -- Alex Brasetvik -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] how to change a database
On Dec 3, 2009, at 13:37 , Peter wrote: Lets suppose I created an engine on database 'foo' and I want to create a database 'bar' and then do my work on 'bar'. What is the recommended way to do this ? Establish a new connection to bar. -- Alex Brasetvik -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.