Re: max_allowed_packet in PostgreSQL
- From: Bill Karwin <bill@xxxxxxxxxx>
- Date: Wed, 29 Mar 2006 10:43:21 -0800
yawnmoth wrote:
In MySQL, there's a limit on how big SQL queries can be. This limit
can be determined with the following query:
SHOW VARIABLES LIKE 'max_allowed_packet';
Is there a similar limit for PostgreSQL or any other DBMSs?
As of PostgreSQL version 7.1 (April 2001), they claim there is "no fixed limit on the length of a query string." Prior to that, the limit on SQL statements was an embarassing 8KB.
InterBase 6.0/Firebird had a limit of either 16KB or 32KB on a SQL statement. I could never find out for sure what it was. Subsequent versions of either product could have improved, I haven't used them since 2000.
Tip: if your SQL statements are long because of long character strings, try using parameterized queries. The fields in the SQL string are replaced by a single ? character, and then you can supply the length values when you execute the prepared query.
Also, is the following...
INSERT INTO a VALUES (1,23),(2,34),(4,33);
...faster than doing three seperate INSERTs? If so, is it pretty
universal or does it work on just a few DBMSs?
Yes, performance is improved by this form, where it is supported. According to "SQL Performance Tuning", only IBM DB2 and MySQL support the syntax (as of the time of this book's writing in 2003).
It helps to combine multiple statements into one, because there is naturally some amount of overhead per statement. Parsing, privilege checking, etc. When you are doing bulk inserts of thousands or millions of rows, this adds up!
Note that MySQL has another tuning parameter that affects bulk inserts. If you use MyISAM tables, see bulk_insert_buffer_size in the docs:
http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html
Also read these pages if you need to optimize bulk inserts:
http://dev.mysql.com/doc/refman/5.0/en/insert-speed.html
http://dev.mysql.com/doc/refman/5.0/en/innodb-insert-buffering.html
http://dev.mysql.com/doc/refman/5.0/en/innodb-tuning.html
Also if you are doing bulk inserts, instead of INSERT use LOAD DATA INFILE. It's much faster.
Regards,
Bill K.
.
- References:
- max_allowed_packet in PostgreSQL
- From: yawnmoth
- max_allowed_packet in PostgreSQL
- Prev by Date: Re: Theoy When Updating Linked Records
- Next by Date: Re: max_allowed_packet in PostgreSQL
- Previous by thread: max_allowed_packet in PostgreSQL
- Next by thread: Re: max_allowed_packet in PostgreSQL
- Index(es):
Relevant Pages
|