You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ken Bowen <kb...@als.com> on 2009/01/15 23:20:02 UTC

PostgreSQL vs MySQL with Tomcat

Hi all (especially Chris -- very informative long post today on Tomcat/ 
MySQL):

For a several reasons (including the apparent infinite default for  
connection timeout), I'm contemplating switching one or two projects  
from MySQL to PostgreSQL.  I'd like to gather opinions on the  
tradeoffs, including:

Unfortunately, MySQL isn't really that tunable. On the other hand, MySQL
requires very little in the way of tuning!

I created a couple of proof-of-concept projects with PostgreSQL for  
someone about six months ago, and the only really puzzling thing what  
how to set up "sequences" corresponding to MySQL's AUTOINCREMENT (I'm  
not sure I've really wrapped head around it completely anyway).  For  
those small projects, it worked well, but there was no stress involved.

I'd like to hear about people's experiences and what they think are  
the strengths and weaknesses of each DBMS for use behind Tomcat.

Thanks much in advance,
Ken Bowen

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Resource Mixup when using AJP proxy (strange one)

Posted by Yuval Perlov <yu...@r-u-on.com>.
Setup:
For one of our projects we are using httpd in front of tomcat.
At the moment everything is routed via tomcat, static and dynamic  
content alike (except for one directory of images that resides outside  
the application).
We are using AJP proxy.

Symptoms:
After running for a while (day or two depending how much traffic we  
have) the web pages render "funny". It seems as if the wrong resources  
are being sent - when I go over the DOM I see that objects that have  
the right URL for background images etc. are dealt the wrong pictures.  
It seems as though the connection is not thread safe (this is just how  
it seems - I don't know if it is the actual problem).
This happens only on the https channel and does not affect the :80  
virtual host!

Versions (latest versions):
Redhat Fedora 10
Server version: Apache/2.2.10 (Unix)
Tomcat: 6.0.16

Config file:
<VirtualHost 216.139.214.167:443>
    ServerAdmin search@patentest.co.il  DocumentRoot 	/home/apache/www/ 
html/patentest.co.il
    ServerName www.patentest.co.il

    SSLEngine on
    SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW: 
+SSLv2:+EXP:+eNULL
    SSLCertificateFile certs/www.patentest.co.il.crt
    SSLCertificateKeyFile certs/www.patentest.co.il.key
    SSLCACertificateFile certs/gd_bundle.crt

    ErrorLog logs/patentest.co.il_ssl_error_log
    CustomLog logs/patentest.co.il_ssl_log common
    SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown

    Alias /ptimg/ home/images/images/
    ProxyPass /ipmaster !
    ProxyPass /ptimg !
    ProxyPass / ajp://localhost:8009/
</VirtualHost>


If anyone has seen this or has some ideas how to troubleshoot and  
isolate, I'd be most grateful.

Regards,
Yuval Perlov
www.r-u-on.com





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Resource Mixup when using AJP proxy (strange one)

Posted by Konstantin Kolinko <kn...@gmail.com>.
2009/1/18 Yuval Perlov <yu...@r-u-on.com>:
> Setup:
> For one of our projects we are using httpd in front of tomcat.
> At the moment everything is routed via tomcat, static and dynamic content
> alike (except for one directory of images that resides outside the
> application).
> We are using AJP proxy.
>
> Symptoms:
> After running for a while (day or two depending how much traffic we have)
> the web pages render "funny". It seems as if the wrong resources are being
> sent - when I go over the DOM I see that objects that have the right URL for
> background images etc. are dealt the wrong pictures. It seems as though the
> connection is not thread safe (this is just how it seems - I don't know if
> it is the actual problem).
> This happens only on the https channel and does not affect the :80 virtual
> host!
>
> Versions (latest versions):
> Redhat Fedora 10
> Server version: Apache/2.2.10 (Unix)
> Tomcat: 6.0.16
>
> Config file:
> <VirtualHost 216.139.214.167:443>
>    ServerAdmin search@patentest.co.il  DocumentRoot
>  /home/apache/www/html/patentest.co.il
>    ServerName www.patentest.co.il
>
>    SSLEngine on
>    SSLCipherSuite
> ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
>    SSLCertificateFile certs/www.patentest.co.il.crt
>    SSLCertificateKeyFile certs/www.patentest.co.il.key
>    SSLCACertificateFile certs/gd_bundle.crt
>
>    ErrorLog logs/patentest.co.il_ssl_error_log
>    CustomLog logs/patentest.co.il_ssl_log common
>    SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
>
>    Alias /ptimg/ home/images/images/
>    ProxyPass /ipmaster !
>    ProxyPass /ptimg !
>    ProxyPass / ajp://localhost:8009/
> </VirtualHost>
>
>
> If anyone has seen this or has some ideas how to troubleshoot and isolate,
> I'd be most grateful.
>

It reminds me of the thread entitled
"Apache/mod_jk serves random files from tomcat"

You can read it here:
http://marc.info/?t=121570480200006&r=1&w=2
http://marc.info/?t=121570480200006&r=2&w=2
or here:
http://www.nabble.com/Apache-mod_jk-serves-random-files-from-tomcat-td18385568.html


Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Resource Mixup when using AJP proxy (strange one)

Posted by Yuval Perlov <yu...@r-u-on.com>.
Setup:
For one of our projects we are using httpd in front of tomcat.
At the moment everything is routed via tomcat, static and dynamic  
content alike (except for one directory of images that resides outside  
the application).
We are using AJP proxy.

Symptoms:
After running for a while (day or two depending how much traffic we  
have) the web pages render "funny". It seems as if the wrong resources  
are being sent - when I go over the DOM I see that objects that have  
the right URL for background images etc. are dealt the wrong pictures.  
It seems as though the connection is not thread safe (this is just how  
it seems - I don't know if it is the actual problem).
This happens only on the https channel and does not affect the :80  
virtual host!

Versions (latest versions):
Redhat Fedora 10
Server version: Apache/2.2.10 (Unix)
Tomcat: 6.0.16

Config file:
<VirtualHost 216.139.214.167:443>
     ServerAdmin search@patentest.co.il  DocumentRoot 	/home/apache/ 
www/html/patentest.co.il
     ServerName www.patentest.co.il

     SSLEngine on
     SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW: 
+SSLv2:+EXP:+eNULL
     SSLCertificateFile certs/www.patentest.co.il.crt
     SSLCertificateKeyFile certs/www.patentest.co.il.key
     SSLCACertificateFile certs/gd_bundle.crt

     ErrorLog logs/patentest.co.il_ssl_error_log
     CustomLog logs/patentest.co.il_ssl_log common
     SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown

     Alias /ptimg/ home/images/images/
     ProxyPass /ipmaster !
     ProxyPass /ptimg !
     ProxyPass / ajp://localhost:8009/
</VirtualHost>


If anyone has seen this or has some ideas how to troubleshoot and  
isolate, I'd be most grateful.

Regards,
Yuval Perlov
www.r-u-on.com





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: PostgreSQL vs MySQL with Tomcat

Posted by Peter Crowther <Pe...@melandra.com>.
> From: Jonathan Mast [mailto:jhmast.developer@gmail.com]
> Sure we can argue about which DBMS has the fastest JOINs but
> nonetheless it
> remains that JOIN queries will always be computationally
> expensive compared to single table queries.

Depends what you do with the results of those single table queries :-).  I saw one application (mid-1990s) that used SELECT * FROM table to bring two 10M row tables into memory, then did O(n^2) comparisons between the keys to obtain data from both.  When asked, the developer said he didn't understand joins in the database so did it "the easy way".

I'd hope developers are aware of computational complexity, load on different components, and the reponse time and throughput constraints on the application, and that they code appropriately rather than following dogma of the form "X will always be expensive compared to Y".  I've been surprised (rather too many times) when the "will always be" has turned out to be false.

                - Peter

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: PostgreSQL vs MySQL with Tomcat

Posted by Jonathan Mast <jh...@gmail.com>.
Perhaps I should explain more about how my rewrite sans JOINs works:

The reports read from a log table with this schema:
PK | ref_PK1 | ref_PK2 | ref_PK3 | start_time | stop_time

Where ref_PK# is the primary key of another table.  These 3 other tables are
very shallow (row count < 100).  The log table is very deep (row count >
100,000).

The web app, when started, reads the 3 shallow tables into memory (3 hash
maps).

(And btw:  the database code is NOT intertwined with the Serlvet code, thank
you very much :)

To run a report: the user enters the start and stop times, along with some
other options.  The report sends the options to db accessor class which runs
a query that only references the log table.  The results (an array of Log
objects) are rendered as an HTML table (it also does Excel).  The ref_PK#
values are matched against their respective hashmaps to produce human
readable data.

This approach proved much faster than using the JOINs.  I'm not saying that
there is no place for using JOINs, just that you need to think about where
to place the processing load.  Our database is very busy with writes, all of
which have priority over reads, hence the desire to move as much load off of
it as possible.

Furthermore, the data in 3 shallow tables doesn't change once inserted.  But
in other projects where I employ caching, the caches Timeout after certain
periods of time.  Also these other caches load incremently (as needed)
instead of preloading, which is what the report app does.

Finally, I am very busy with other responisibilites at my job, and do not
have time to dig into heiroglyphics of database optimization which is very
vender specific and as such further binds your organization to that vendor.

thanks

On Fri, Jan 23, 2009 at 12:52 PM, Christopher Schultz <
chris@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Chris,
>
> Chris Wareham wrote:
> > By the way, if it's not static data your caching,
> > how's your messaging system? Without one how are you going to maintain
> > the integrity of your caches? Even with one, can you tolerate a race
> > condition between the data being modified in the database and the
> > notifications causing all your caches to be updated?
>
> Er... write-through cache? Presumably, Leon is talking about a one-box
> wonder.
>
> Before everyone starts yelling about how stupid everyone else's ideas
> are, maybe we should just let this one go in the interests of civility.
>
> - -chris
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iEYEARECAAYFAkl6A+UACgkQ9CaO5/Lv0PCWdACdH0d9og7mrxwSzfZyn5hmzzo+
> 9AsAoKmNOfAlMiX6jkRcbUof72goMM9T
> =nOJX
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: PostgreSQL vs MySQL with Tomcat

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chris,

Chris Wareham wrote:
> By the way, if it's not static data your caching,
> how's your messaging system? Without one how are you going to maintain
> the integrity of your caches? Even with one, can you tolerate a race
> condition between the data being modified in the database and the
> notifications causing all your caches to be updated?

Er... write-through cache? Presumably, Leon is talking about a one-box
wonder.

Before everyone starts yelling about how stupid everyone else's ideas
are, maybe we should just let this one go in the interests of civility.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkl6A+UACgkQ9CaO5/Lv0PCWdACdH0d9og7mrxwSzfZyn5hmzzo+
9AsAoKmNOfAlMiX6jkRcbUof72goMM9T
=nOJX
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: PostgreSQL vs MySQL with Tomcat

Posted by Chris Wareham <cw...@visitlondon.com>.
Leon Rosenberg wrote:
> On Fri, Jan 23, 2009 at 12:59 PM, Chris Wareham
> <cw...@visitlondon.com> wrote:
>> Reread my last message, and take a look at the internals of any half
>> decent RDBMS. Frequently accessed data will get cached in memory, and
>> the cost of many joins will be less than the cost of a hash table lookup
>> in Java. Not that caching at the application layer is relevant, because
>> you were talking about performing two queries in the place of one with a
>> join.
>>
> 
> It is relevant, because by executing the 'queries' in application
> layer, you are able to execute them on different way and cache.
> Preventing the DB from being the bottleneck is relevant.
> Alas the cost of a hashmap lookup in java is hard to beat :-)
> Especially if to beat it you have to go over net.
> 

Sigh. That's irrelevant - you claimed two separate queries were faster
than one with a join. By the way, if it's not static data your caching,
how's your messaging system? Without one how are you going to maintain
the integrity of your caches? Even with one, can you tolerate a race
condition between the data being modified in the database and the
notifications causing all your caches to be updated? Is this all worth
the pain to avoid a join? (Maybe, but that doesn't make it a hard and
fast rule as you seem to think that "joins are bad, man").

>>>>> No query optimizer in the world can perform better than the develop,
>>>>> simply because it lacks the knowledge a good developer should have
>>>>> about the semantic of his application.
>>>>>
>>>> Yes, and occasionally I can produce "better" assembler code than my C
>>>> compiler. However, in your case you're ignoring the fact that any RDBMS
>>>> worth its salt is going to have cached a lot of data in memory, in a way
>>>> that is likely to be as fast to access if not faster than the same data
>>>> cached and accessed at the application layer.
>>> i highly doubt is, cause a local access to memory in the vm is
>>> 1.000.000 faster than an access over the net, even in the GBit
>>> network.
>>>
>> As pointed out above, memory access at the application layer is
>> irrelevant to a discussion where you had posited that two database
>> queries were less costly than one with a join.
> 
> Again, not if by splitting them i'm creating the possibility to substitute them.
> 
> Leon
> 

This has been a fun way to liven up a Friday, but I'm bailing at this
point - and I just hope I don't end up working on anything you've ever
written as I fear it would be rewrite time.

Chris
--
 
Chris Wareham
Senior Software Engineer
Visit London Ltd
6th floor,
2 More London Riverside, London SE1 2RR
 
Tel:  +44 (0)20 7234 5848
Fax: +44 (0)20 7234 5753

 
www.visitlondon.com





   
   
'Visit London Limited' is registered in England under No.761149;
Registered Office: Visit London, 2 More London Riverside, London SE1 2RR.
 

Visit London is the official visitor organisation for London. Visit London is partly funded by Partnership, the Mayor's London Development Agency and London Councils.
The information contained in this e-mail is confidential and intended for the named recipient(s) only.  If you have received it in error, please notify the sender immediately and then delete the message.  If you are not the intended recipient, you must not use, disclose, copy or distribute this email. The views expressed in this e-mail are those of the individual and not of Visit London. We reserve the right to read and monitor any email or attachment entering or leaving our systems without prior notice.
 
  Please don't print this e-mail unless you really need to.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: PostgreSQL vs MySQL with Tomcat

Posted by Leon Rosenberg <ro...@googlemail.com>.
On Fri, Jan 23, 2009 at 12:59 PM, Chris Wareham
<cw...@visitlondon.com> wrote:
>
> Reread my last message, and take a look at the internals of any half
> decent RDBMS. Frequently accessed data will get cached in memory, and
> the cost of many joins will be less than the cost of a hash table lookup
> in Java. Not that caching at the application layer is relevant, because
> you were talking about performing two queries in the place of one with a
> join.
>

It is relevant, because by executing the 'queries' in application
layer, you are able to execute them on different way and cache.
Preventing the DB from being the bottleneck is relevant.
Alas the cost of a hashmap lookup in java is hard to beat :-)
Especially if to beat it you have to go over net.

>>>> No query optimizer in the world can perform better than the develop,
>>>> simply because it lacks the knowledge a good developer should have
>>>> about the semantic of his application.
>>>>
>>> Yes, and occasionally I can produce "better" assembler code than my C
>>> compiler. However, in your case you're ignoring the fact that any RDBMS
>>> worth its salt is going to have cached a lot of data in memory, in a way
>>> that is likely to be as fast to access if not faster than the same data
>>> cached and accessed at the application layer.
>>
>> i highly doubt is, cause a local access to memory in the vm is
>> 1.000.000 faster than an access over the net, even in the GBit
>> network.
>>
>
> As pointed out above, memory access at the application layer is
> irrelevant to a discussion where you had posited that two database
> queries were less costly than one with a join.

Again, not if by splitting them i'm creating the possibility to substitute them.

Leon

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: PostgreSQL vs MySQL with Tomcat

Posted by Chris Wareham <cw...@visitlondon.com>.
Leon Rosenberg wrote:
> On Fri, Jan 23, 2009 at 12:36 PM, Chris Wareham
> <cw...@visitlondon.com> wrote:
>>>
>> So you perform two queries from the application layer? You are basically
>> doing a join by hand - the cost of those two round trips to the database
>> will lose to a single query with a join, unless you've not setup
>> adequate indexes and your tables have a huge number of rows in them.
> 
> two round trips to the database yes, in theory.
> The other side of the medal is that i can separate both data entities
> in different services (where they belong to),
> i can even hold them in different type of media, i can cache username
> to userid extremely efficient, which the db never could,
> and I don't depend on how this db implementation is tuned, and not bound to it.
> 

Reread my last message, and take a look at the internals of any half
decent RDBMS. Frequently accessed data will get cached in memory, and
the cost of many joins will be less than the cost of a hash table lookup
in Java. Not that caching at the application layer is relevant, because
you were talking about performing two queries in the place of one with a
join.

>>> No query optimizer in the world can perform better than the develop,
>>> simply because it lacks the knowledge a good developer should have
>>> about the semantic of his application.
>>>
>> Yes, and occasionally I can produce "better" assembler code than my C
>> compiler. However, in your case you're ignoring the fact that any RDBMS
>> worth its salt is going to have cached a lot of data in memory, in a way
>> that is likely to be as fast to access if not faster than the same data
>> cached and accessed at the application layer.
> 
> i highly doubt is, cause a local access to memory in the vm is
> 1.000.000 faster than an access over the net, even in the GBit
> network.
> 

As pointed out above, memory access at the application layer is
irrelevant to a discussion where you had posited that two database
queries were less costly than one with a join.

> 
>> In the system I currently work on, there was a gem of a code comment by
>> a previous developer that said something like "perform these queries
>> separately as the database cannot optimise them". Normalising the tables
>> meant the database could. If your joins are costing you so much
>> performance, then I'd humbly suggest your database design is screwed.
>>
>>> my 2 cent as an addition to Jonathan's 2, make it 4 against the joins :-)
>>>
>> Sadly your four cents aren't even legal tender here ;-)
> 
> 
> My 4 cent may be placed in the wrong place, but basically, from 10
> years online portals building (and i mean high-performance, 24/7, with
> millions of users) if your design relies on a join in the database in
> the production system, you've done something wrong.
> 

If we're into pointless dick swinging, then on the criteria you've just
described I win.

Chris
--
 
Chris Wareham
Senior Software Engineer
Visit London Ltd
6th floor,
2 More London Riverside, London SE1 2RR
 
Tel:  +44 (0)20 7234 5848
Fax: +44 (0)20 7234 5753

 
www.visitlondon.com





   
   
'Visit London Limited' is registered in England under No.761149;
Registered Office: Visit London, 2 More London Riverside, London SE1 2RR.
 

Visit London is the official visitor organisation for London. Visit London is partly funded by Partnership, the Mayor's London Development Agency and London Councils.
The information contained in this e-mail is confidential and intended for the named recipient(s) only.  If you have received it in error, please notify the sender immediately and then delete the message.  If you are not the intended recipient, you must not use, disclose, copy or distribute this email. The views expressed in this e-mail are those of the individual and not of Visit London. We reserve the right to read and monitor any email or attachment entering or leaving our systems without prior notice.
 
  Please don't print this e-mail unless you really need to.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: PostgreSQL vs MySQL with Tomcat

Posted by Leon Rosenberg <ro...@googlemail.com>.
On Fri, Jan 23, 2009 at 12:36 PM, Chris Wareham
<cw...@visitlondon.com> wrote:
> Leon Rosenberg wrote:
>>
>> On Fri, Jan 23, 2009 at 11:45 AM, Chris Wareham
>> <cw...@visitlondon.com> wrote:
>>
>>> By it's very definition (see Codd or Date), an RDBMS should be capable
>>> of performing joins with good performance. MySQL often struggles to do
>>> so thanks to the poor optimiser, so you had to implement what should be
>>> core functionality of an RDBMS in your application layer.
>>
>> Sorry, but by the very definition JOINs are slow, and no database in
>> the world will ever be able to make them fast :-)
>> Avoiding JOINs is often a good architectural advice (taking in account
>> a previous post of the contrary).
>>
>> For example if you need all orders by user with name Chris, you will
>> ALWAYS be faster if you first retrieve the userid, and than the orders
>> of the userid.
>>
>
> So you perform two queries from the application layer? You are basically
> doing a join by hand - the cost of those two round trips to the database
> will lose to a single query with a join, unless you've not setup
> adequate indexes and your tables have a huge number of rows in them.

two round trips to the database yes, in theory.
The other side of the medal is that i can separate both data entities
in different services (where they belong to),
i can even hold them in different type of media, i can cache username
to userid extremely efficient, which the db never could,
and I don't depend on how this db implementation is tuned, and not bound to it.

>
>> No query optimizer in the world can perform better than the develop,
>> simply because it lacks the knowledge a good developer should have
>> about the semantic of his application.
>>
>
> Yes, and occasionally I can produce "better" assembler code than my C
> compiler. However, in your case you're ignoring the fact that any RDBMS
> worth its salt is going to have cached a lot of data in memory, in a way
> that is likely to be as fast to access if not faster than the same data
> cached and accessed at the application layer.

i highly doubt is, cause a local access to memory in the vm is
1.000.000 faster than an access over the net, even in the GBit
network.


>
> In the system I currently work on, there was a gem of a code comment by
> a previous developer that said something like "perform these queries
> separately as the database cannot optimise them". Normalising the tables
> meant the database could. If your joins are costing you so much
> performance, then I'd humbly suggest your database design is screwed.
>
>> my 2 cent as an addition to Jonathan's 2, make it 4 against the joins :-)
>>
>
> Sadly your four cents aren't even legal tender here ;-)


My 4 cent may be placed in the wrong place, but basically, from 10
years online portals building (and i mean high-performance, 24/7, with
millions of users) if your design relies on a join in the database in
the production system, you've done something wrong.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: PostgreSQL vs MySQL with Tomcat

Posted by Chris Wareham <cw...@visitlondon.com>.
Leon Rosenberg wrote:
> On Fri, Jan 23, 2009 at 11:45 AM, Chris Wareham
> <cw...@visitlondon.com> wrote:
> 
>> By it's very definition (see Codd or Date), an RDBMS should be capable
>> of performing joins with good performance. MySQL often struggles to do
>> so thanks to the poor optimiser, so you had to implement what should be
>> core functionality of an RDBMS in your application layer.
> 
> Sorry, but by the very definition JOINs are slow, and no database in
> the world will ever be able to make them fast :-)
> Avoiding JOINs is often a good architectural advice (taking in account
> a previous post of the contrary).
> 
> For example if you need all orders by user with name Chris, you will
> ALWAYS be faster if you first retrieve the userid, and than the orders
> of the userid.
> 

So you perform two queries from the application layer? You are basically
doing a join by hand - the cost of those two round trips to the database
will lose to a single query with a join, unless you've not setup
adequate indexes and your tables have a huge number of rows in them.

> No query optimizer in the world can perform better than the develop,
> simply because it lacks the knowledge a good developer should have
> about the semantic of his application.
> 

Yes, and occasionally I can produce "better" assembler code than my C
compiler. However, in your case you're ignoring the fact that any RDBMS
worth its salt is going to have cached a lot of data in memory, in a way
that is likely to be as fast to access if not faster than the same data
cached and accessed at the application layer.

In the system I currently work on, there was a gem of a code comment by
a previous developer that said something like "perform these queries
separately as the database cannot optimise them". Normalising the tables
meant the database could. If your joins are costing you so much
performance, then I'd humbly suggest your database design is screwed.

> my 2 cent as an addition to Jonathan's 2, make it 4 against the joins :-)
> 

Sadly your four cents aren't even legal tender here ;-)

Chris
--
 
Chris Wareham
Senior Software Engineer
Visit London Ltd
6th floor,
2 More London Riverside, London SE1 2RR
 
Tel:  +44 (0)20 7234 5848
Fax: +44 (0)20 7234 5753

 
www.visitlondon.com





   
   
'Visit London Limited' is registered in England under No.761149;
Registered Office: Visit London, 2 More London Riverside, London SE1 2RR.
 

Visit London is the official visitor organisation for London. Visit London is partly funded by Partnership, the Mayor's London Development Agency and London Councils.
The information contained in this e-mail is confidential and intended for the named recipient(s) only.  If you have received it in error, please notify the sender immediately and then delete the message.  If you are not the intended recipient, you must not use, disclose, copy or distribute this email. The views expressed in this e-mail are those of the individual and not of Visit London. We reserve the right to read and monitor any email or attachment entering or leaving our systems without prior notice.
 
  Please don't print this e-mail unless you really need to.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: PostgreSQL vs MySQL with Tomcat

Posted by Peter Crowther <Pe...@melandra.com>.
Leon, it's rare for me to disagree with you, but...

> From: Leon Rosenberg [mailto:rosenberg.leon@googlemail.com]
> For example if you need all orders by user with name Chris, you will
> ALWAYS be faster if you first retrieve the userid, and than the orders
> of the userid.

... I disagree and can produce at least one counterexample.

Performing two queries from the application layer requires two parses, two optimise steps, at least two more context switches on a single-core machine, two sets of serialisation of query and results, potentially more network traffic and latency... all extra cycles and resource utilisation that are avoided if the combined query is sent to the DBMS and executed there.  Against those, you have to balance more complex parse and optimise times for the single query, plus the extra time to locate the data (which may or may not be in cache at the server).

Back in 1992, I had exactly this situation on a Sybase 4.2 server on a SPARCstation 1 running SunOS.  I profiled both implementations, and the single query case came back about 30% faster (I was only concerned about wallclock time so didn't check memory or CPU).  That was with Sybase's relatively primitive optimiser.  With a good query optimiser plus query plan caching and data caching, a modern SQL Server can do better and can find the savings in more cases.

I suggest losing the dogma and profiling it with *your* data in *your* environment :-).  You might be surprised.

                - Peter

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: PostgreSQL vs MySQL with Tomcat

Posted by Jim Cox <sh...@gmail.com>.
On Fri, Jan 23, 2009 at 6:23 AM, Leon Rosenberg <
rosenberg.leon@googlemail.com> wrote:

> On Fri, Jan 23, 2009 at 11:45 AM, Chris Wareham
> <cw...@visitlondon.com> wrote:
>
> > By it's very definition (see Codd or Date), an RDBMS should be capable
> > of performing joins with good performance. MySQL often struggles to do
> > so thanks to the poor optimiser, so you had to implement what should be
> > core functionality of an RDBMS in your application layer.
>
> Sorry, but by the very definition JOINs are slow, and no database in
> the world will ever be able to make them fast :-)
> Avoiding JOINs is often a good architectural advice (taking in account
> a previous post of the contrary).
>
> For example if you need all orders by user with name Chris, you will
> ALWAYS be faster if you first retrieve the userid, and than the orders
> of the userid.
>
> No query optimizer in the world can perform better than the develop,
> simply because it lacks the knowledge a good developer should have
> about the semantic of his application.
>
> my 2 cent as an addition to Jonathan's 2, make it 4 against the joins :-)
>

I'm hoping this is an attempt at sarcasm or humor (or even trolling), but
part of me fears that it isn't...

Re: PostgreSQL vs MySQL with Tomcat

Posted by Leon Rosenberg <ro...@googlemail.com>.
On Fri, Jan 23, 2009 at 11:45 AM, Chris Wareham
<cw...@visitlondon.com> wrote:

> By it's very definition (see Codd or Date), an RDBMS should be capable
> of performing joins with good performance. MySQL often struggles to do
> so thanks to the poor optimiser, so you had to implement what should be
> core functionality of an RDBMS in your application layer.

Sorry, but by the very definition JOINs are slow, and no database in
the world will ever be able to make them fast :-)
Avoiding JOINs is often a good architectural advice (taking in account
a previous post of the contrary).

For example if you need all orders by user with name Chris, you will
ALWAYS be faster if you first retrieve the userid, and than the orders
of the userid.

No query optimizer in the world can perform better than the develop,
simply because it lacks the knowledge a good developer should have
about the semantic of his application.

my 2 cent as an addition to Jonathan's 2, make it 4 against the joins :-)

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: PostgreSQL vs MySQL with Tomcat

Posted by Chris Wareham <cw...@visitlondon.com>.
Christopher Schultz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Chris,
> 
> Chris Wareham wrote:
>> I am particularly wary of MySQL because of the way missing features
>> have been disingenuously described as unnecessary, and broken
>> features as the MySQL developers knowing better than everyone else.
> 
> Not to pick a fight, here, but I presume you are talking about your
> previous comment about foreign key constraints. The old documentation
> suggesting that developers were responsible for referential integrity
> wasn't, I think, meant to suggest that this was a cosmic truth. Instead,
> I think it was meant to indicate that, when using MySQL, it was simply
> the only way developers could operate.
> 
> - -chris
> 

No, the MySQL developers claimed they had "better paradigms". For
instance, they first claimed transactions weren't necessary, eventually
they said they would come up with something called "atomic operations",
but still advocated table locks instead. If you were performing inserts,
updates or deletes across a number of tables, then the first thing you
had to do was lock them *all* at the table level. To state the obvious,
locking at the table level means concurrent write access is going to be
very slow.

On foreign keys and referential integrity in general, the manual had
this to say:

"FOREIGN KEY is sometimes used as a constraint check, but this check is
unnecessary in practice if rows are inserted into the tables in the
right order."

Part of a database engine's job is to ensure data integrity - it
shouldn't rely on the application coder getting things perfectly right
every time, because they wont. Without referential integrity, failures
on the part of the coder to "do the right thing" are going to be hard to
catch. Without transactions, it becomes even harder to catch and to
recover from.

MySQL is optimised for read access, features to enforce data integrity
or optimise write access have always been low on the priority list. For
proof, read the MySQL manual's section on "Missing Features".

Chris
--
 
Chris Wareham
Senior Software Engineer
Visit London Ltd
6th floor,
2 More London Riverside, London SE1 2RR
 
Tel:  +44 (0)20 7234 5848
Fax: +44 (0)20 7234 5753

 
www.visitlondon.com





   
   
'Visit London Limited' is registered in England under No.761149;
Registered Office: Visit London, 2 More London Riverside, London SE1 2RR.
 

Visit London is the official visitor organisation for London. Visit London is partly funded by Partnership, the Mayor's London Development Agency and London Councils.
The information contained in this e-mail is confidential and intended for the named recipient(s) only.  If you have received it in error, please notify the sender immediately and then delete the message.  If you are not the intended recipient, you must not use, disclose, copy or distribute this email. The views expressed in this e-mail are those of the individual and not of Visit London. We reserve the right to read and monitor any email or attachment entering or leaving our systems without prior notice.
 
  Please don't print this e-mail unless you really need to.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: PostgreSQL vs MySQL with Tomcat

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chris,

Chris Wareham wrote:
> I am particularly wary of MySQL because of the way missing features
> have been disingenuously described as unnecessary, and broken
> features as the MySQL developers knowing better than everyone else.

Not to pick a fight, here, but I presume you are talking about your
previous comment about foreign key constraints. The old documentation
suggesting that developers were responsible for referential integrity
wasn't, I think, meant to suggest that this was a cosmic truth. Instead,
I think it was meant to indicate that, when using MySQL, it was simply
the only way developers could operate.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkl53TEACgkQ9CaO5/Lv0PDU8wCfbq5mb2c5CvVWDCnMmRISlFb+
fNwAoLc5yKt9MG1jRZjf6x2+9DD1/jXF
=k4CY
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: PostgreSQL vs MySQL with Tomcat

Posted by Peter Stavrinides <P....@albourne.com>.
>when they hit this kind of problem
>they assume it's a limitation of the kind of tools they are using
Exactly, mostly its a suboptimal implementation of these technologies

Our core business is reporting with complex risk modeling, we do intensive risk calculations on raw data using complex joins on millions of rows of data using page long SQL queries at time, and they do just fine on Postgres (milliseconds to a few seconds at worst). Occasionally we use some C functions when speed is an issue, but SQL joins are *hardley a bottleneck.

Peter  

----- Original Message -----
From: "Chris Wareham" <cw...@visitlondon.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Friday, 23 January, 2009 12:45:58 GMT +02:00 Athens, Beirut, Bucharest, Istanbul
Subject: Re: PostgreSQL vs MySQL with Tomcat

Jonathan Mast wrote:
> Perhaps the discussion should move back towards how Tomcat interacts with
> databases.
> 

It would be more on topic, but a well architected web application will
have a data access layer that is not dependent on the Servlet API, both
for testability and reusability. While a data source may be configured
in Tomcat, the correct use of dependency injection would mean that the
data access layer shouldn't be concerned where the data source comes
from. To reiterate, database interaction is an architectural issue, not
a web container one.

> This thread seems to be damning MySQL for not having super advanced
> features, some of which should perhaps not even be in the purview of the
> database layer, but more appropriately belong at the application layer (ie.
> Tomcat).
> 

No, many people damn MySQL for it's lack of standards conformance and
idiosyncracies that make it harder to maintain data integrity. I am
particularly wary of MySQL because of the way missing features have been
disingenuously described as unnecessary, and broken features as the
MySQL developers knowing better than everyone else.

> For example, I rewrote a report generator for my company.  The existing
> generator, a PHP + MySQL setup, was insanely slow and difficult to maintain
> being that it consisted of 1 php page containing hundreds of lines of code.
> I rewrote it in jsp + POJO and the new version runs much faster, because it
> doesn't have a single query with a JOIN clause in it.  The old generator had
> super complex queries that took forever to run and placed an enormous amount
> of load on the database server.  I achieved that same result of a JOIN by
> pushing that functionality up to the Java layer.
> 
> Sure we can argue about which DBMS has the fastest JOINs but nonetheless it
> remains that JOIN queries will always be computationally expensive compared
> to single table queries.
> 
> Well thats my 2 cents :)
> 

By it's very definition (see Codd or Date), an RDBMS should be capable
of performing joins with good performance. MySQL often struggles to do
so thanks to the poor optimiser, so you had to implement what should be
core functionality of an RDBMS in your application layer. Great. Did you
try explaining those queries to find out if reordering the joins would
give the performance you were looking for? Or is MySQL the only database
you are familiar with? This is the problem with much of the LAMP crowd -
they've never tried anything else, so when they hit this kind of problem
they assume it's a limitation of the kind of tools they are using, not
of the specific tools themselves.

Chris
--
 
Chris Wareham
Senior Software Engineer
Visit London Ltd
6th floor,
2 More London Riverside, London SE1 2RR
 
Tel:  +44 (0)20 7234 5848
Fax: +44 (0)20 7234 5753

 
www.visitlondon.com





   
   
'Visit London Limited' is registered in England under No.761149;
Registered Office: Visit London, 2 More London Riverside, London SE1 2RR.
 

Visit London is the official visitor organisation for London. Visit London is partly funded by Partnership, the Mayor's London Development Agency and London Councils.
The information contained in this e-mail is confidential and intended for the named recipient(s) only.  If you have received it in error, please notify the sender immediately and then delete the message.  If you are not the intended recipient, you must not use, disclose, copy or distribute this email. The views expressed in this e-mail are those of the individual and not of Visit London. We reserve the right to read and monitor any email or attachment entering or leaving our systems without prior notice.
 
  Please don't print this e-mail unless you really need to.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: PostgreSQL vs MySQL with Tomcat

Posted by Chris Wareham <cw...@visitlondon.com>.
Jonathan Mast wrote:
> Perhaps the discussion should move back towards how Tomcat interacts with
> databases.
> 

It would be more on topic, but a well architected web application will
have a data access layer that is not dependent on the Servlet API, both
for testability and reusability. While a data source may be configured
in Tomcat, the correct use of dependency injection would mean that the
data access layer shouldn't be concerned where the data source comes
from. To reiterate, database interaction is an architectural issue, not
a web container one.

> This thread seems to be damning MySQL for not having super advanced
> features, some of which should perhaps not even be in the purview of the
> database layer, but more appropriately belong at the application layer (ie.
> Tomcat).
> 

No, many people damn MySQL for it's lack of standards conformance and
idiosyncracies that make it harder to maintain data integrity. I am
particularly wary of MySQL because of the way missing features have been
disingenuously described as unnecessary, and broken features as the
MySQL developers knowing better than everyone else.

> For example, I rewrote a report generator for my company.  The existing
> generator, a PHP + MySQL setup, was insanely slow and difficult to maintain
> being that it consisted of 1 php page containing hundreds of lines of code.
> I rewrote it in jsp + POJO and the new version runs much faster, because it
> doesn't have a single query with a JOIN clause in it.  The old generator had
> super complex queries that took forever to run and placed an enormous amount
> of load on the database server.  I achieved that same result of a JOIN by
> pushing that functionality up to the Java layer.
> 
> Sure we can argue about which DBMS has the fastest JOINs but nonetheless it
> remains that JOIN queries will always be computationally expensive compared
> to single table queries.
> 
> Well thats my 2 cents :)
> 

By it's very definition (see Codd or Date), an RDBMS should be capable
of performing joins with good performance. MySQL often struggles to do
so thanks to the poor optimiser, so you had to implement what should be
core functionality of an RDBMS in your application layer. Great. Did you
try explaining those queries to find out if reordering the joins would
give the performance you were looking for? Or is MySQL the only database
you are familiar with? This is the problem with much of the LAMP crowd -
they've never tried anything else, so when they hit this kind of problem
they assume it's a limitation of the kind of tools they are using, not
of the specific tools themselves.

Chris
--
 
Chris Wareham
Senior Software Engineer
Visit London Ltd
6th floor,
2 More London Riverside, London SE1 2RR
 
Tel:  +44 (0)20 7234 5848
Fax: +44 (0)20 7234 5753

 
www.visitlondon.com





   
   
'Visit London Limited' is registered in England under No.761149;
Registered Office: Visit London, 2 More London Riverside, London SE1 2RR.
 

Visit London is the official visitor organisation for London. Visit London is partly funded by Partnership, the Mayor's London Development Agency and London Councils.
The information contained in this e-mail is confidential and intended for the named recipient(s) only.  If you have received it in error, please notify the sender immediately and then delete the message.  If you are not the intended recipient, you must not use, disclose, copy or distribute this email. The views expressed in this e-mail are those of the individual and not of Visit London. We reserve the right to read and monitor any email or attachment entering or leaving our systems without prior notice.
 
  Please don't print this e-mail unless you really need to.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: PostgreSQL vs MySQL with Tomcat

Posted by Jonathan Mast <jh...@gmail.com>.
Perhaps the discussion should move back towards how Tomcat interacts with
databases.

This thread seems to be damning MySQL for not having super advanced
features, some of which should perhaps not even be in the purview of the
database layer, but more appropriately belong at the application layer (ie.
Tomcat).

For example, I rewrote a report generator for my company.  The existing
generator, a PHP + MySQL setup, was insanely slow and difficult to maintain
being that it consisted of 1 php page containing hundreds of lines of code.
I rewrote it in jsp + POJO and the new version runs much faster, because it
doesn't have a single query with a JOIN clause in it.  The old generator had
super complex queries that took forever to run and placed an enormous amount
of load on the database server.  I achieved that same result of a JOIN by
pushing that functionality up to the Java layer.

Sure we can argue about which DBMS has the fastest JOINs but nonetheless it
remains that JOIN queries will always be computationally expensive compared
to single table queries.

Well thats my 2 cents :)

On Thu, Jan 22, 2009 at 7:39 AM, Jim Cox <sh...@gmail.com> wrote:

> When creating tables with referential integrity in MySQL you still get gems
> like, e.g.:
>
>  mysql> create table jimtest ( colA  varchar(32) NOT NULL, CONSTRAINT fk1
> FOREIGN KEY(colA) REFERENCES jimtest2(colA) ON DELETE CASCADE );
> ERROR 1005 (HY000): Can't create table './test/jimtest.frm' (errno: 150)
>
> Same indecipherable error for non-existent referenced table, or column type
> mismatch, or a missing index. Admittedly, you learn what to look for after
> a
> while, but the error message sucks.
>
>
> On Wed, Jan 21, 2009 at 11:06 PM, Christopher Schultz <
> chris@christopherschultz.net> wrote:
>
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > Rusty,
> >
> > Rusty Wright wrote:
> > > I think the biggest gripe I've had with mysql is the problem where I
> was
> > > violating a unique constraint and it was giving me some generic
> > > (completely useless) error; HY001 I think.
> >
> > I've always found the error messages themselves very informative. For
> > instance, if I attempt to insert a record into a table with an FK that
> > doesn't match, MySQL's command-line interface gives me this message:
> >
> > ERROR 1452 (23000): Cannot add or update a child row: a foreign key
> > constraint fails (`database/target_table`, CONSTRAINT
> > `name_of_foreign_key_constraint` FOREIGN KEY (`column_name`) REFERENCES
> > `source_table` (`column_name`))
> >
> > Perhaps Connector/J doesn't give quite such useful error messages, but I
> > seem to recall something nice like "Foreign key constraint check failed".
> >
> > I have found that every database has stupid error codes and you
> > basically have to code your app around tables of db-specific error codes
> > if you want to give your users (or log files) anything better than the
> > driver-supplied error messages.
> >
> > - -chris
> > -----BEGIN PGP SIGNATURE-----
> > Version: GnuPG v1.4.9 (MingW32)
> > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> >
> > iEYEARECAAYFAkl38NUACgkQ9CaO5/Lv0PCwAgCggKgAfu/ZZ+ClRAGtEuM4+xyK
> > e7EAn0R/4fyPgBfhxSB51um5ZW63jZzL
> > =xo6L
> > -----END PGP SIGNATURE-----
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
> >
>

Re: PostgreSQL vs MySQL with Tomcat

Posted by Jim Cox <sh...@gmail.com>.
When creating tables with referential integrity in MySQL you still get gems
like, e.g.:

  mysql> create table jimtest ( colA  varchar(32) NOT NULL, CONSTRAINT fk1
FOREIGN KEY(colA) REFERENCES jimtest2(colA) ON DELETE CASCADE );
ERROR 1005 (HY000): Can't create table './test/jimtest.frm' (errno: 150)

Same indecipherable error for non-existent referenced table, or column type
mismatch, or a missing index. Admittedly, you learn what to look for after a
while, but the error message sucks.


On Wed, Jan 21, 2009 at 11:06 PM, Christopher Schultz <
chris@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Rusty,
>
> Rusty Wright wrote:
> > I think the biggest gripe I've had with mysql is the problem where I was
> > violating a unique constraint and it was giving me some generic
> > (completely useless) error; HY001 I think.
>
> I've always found the error messages themselves very informative. For
> instance, if I attempt to insert a record into a table with an FK that
> doesn't match, MySQL's command-line interface gives me this message:
>
> ERROR 1452 (23000): Cannot add or update a child row: a foreign key
> constraint fails (`database/target_table`, CONSTRAINT
> `name_of_foreign_key_constraint` FOREIGN KEY (`column_name`) REFERENCES
> `source_table` (`column_name`))
>
> Perhaps Connector/J doesn't give quite such useful error messages, but I
> seem to recall something nice like "Foreign key constraint check failed".
>
> I have found that every database has stupid error codes and you
> basically have to code your app around tables of db-specific error codes
> if you want to give your users (or log files) anything better than the
> driver-supplied error messages.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iEYEARECAAYFAkl38NUACgkQ9CaO5/Lv0PCwAgCggKgAfu/ZZ+ClRAGtEuM4+xyK
> e7EAn0R/4fyPgBfhxSB51um5ZW63jZzL
> =xo6L
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: PostgreSQL vs MySQL with Tomcat

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Rusty,

Rusty Wright wrote:
> I think the biggest gripe I've had with mysql is the problem where I was
> violating a unique constraint and it was giving me some generic
> (completely useless) error; HY001 I think.

I've always found the error messages themselves very informative. For
instance, if I attempt to insert a record into a table with an FK that
doesn't match, MySQL's command-line interface gives me this message:

ERROR 1452 (23000): Cannot add or update a child row: a foreign key
constraint fails (`database/target_table`, CONSTRAINT
`name_of_foreign_key_constraint` FOREIGN KEY (`column_name`) REFERENCES
`source_table` (`column_name`))

Perhaps Connector/J doesn't give quite such useful error messages, but I
seem to recall something nice like "Foreign key constraint check failed".

I have found that every database has stupid error codes and you
basically have to code your app around tables of db-specific error codes
if you want to give your users (or log files) anything better than the
driver-supplied error messages.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkl38NUACgkQ9CaO5/Lv0PCwAgCggKgAfu/ZZ+ClRAGtEuM4+xyK
e7EAn0R/4fyPgBfhxSB51um5ZW63jZzL
=xo6L
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: PostgreSQL vs MySQL with Tomcat

Posted by Rusty Wright <ru...@gmail.com>.
It's a rewrite of an app I did awhile ago in php.

I think the biggest gripe I've had with mysql is the problem where I was violating a unique constraint and it was giving me some generic (completely useless) error; HY001 I think.

In various ways, which I can't articulate, MySQL just feels to me more amateurish compared to PostgreSQL.  With MySQL things are changed on an apparently ad-hoc basis and I've heard that they've broken backwards compatibility more than once.

I realize that SQL isn't exactly the most widely adhered to standard, but MySQL seems to be more divergent than [most of] the others.  When I had that HYwhatever error, I was completely stumped, so in order to troubleshoot it I copied the database to an MS SQL Server that I'd been using for something else. I remember having read somewhere that SQL Server is reasonably close to the SQL standard and I was amazed at how much work it took to translate my ddl and sql from MySQL to SQL Server.  (Apache DdlUtils and Hibernate could have helped with the ddl.)

I can't remember all of the various problems I've had with MySQL but here's one that seems typical; I started using it back when it was (or at least it seemed to me) more typical to edit user permissions by updating the mysql.users table, rather than using the GRANT command.  So I have these various sql files that insert stuff in the  mysql.users, mysql.db, and mysql.hosts tables and they have lots of 'y' and 'n' entries.  At some point they changed things and they had to be uppercase.  Previously I think they converted them to Y and N, but suddenly a newer version  accepted the lower case with no complaints but didn't convert them, and they didn't work (it was as if the ys were Ns); I could have been inserting any random letter or digit apparently.  That took some head scratching to figure out.

I had forgotten that Sun bought MySQL so it should be interesting to see how that plays out.  I heard that they're doing a major rewrite, starting from scratch, but going to keep it backwards compatible.


Christopher Schultz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Rusty,
> 
> Rusty Wright wrote:
>> I'm in the process of migrating a MySQL database to PostgrSQL.
> 
> Is this to cool-off your DBA's ears? ;)
> 
> Seriously, if you could explain why you've decided to switch, I think it
> would help a lot of readers understand some of the differences between
> these two RDBMSs.
> 
> - -chris
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iEYEARECAAYFAklyBnIACgkQ9CaO5/Lv0PCuvgCfdZ9j+2Z5cGuk3aQsYFg7VaAO
> msIAnR8r+ZmyYeJz2T3Sbzbk9hCEDGlU
> =26DN
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: PostgreSQL vs MySQL with Tomcat

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Rusty,

Rusty Wright wrote:
> I'm in the process of migrating a MySQL database to PostgrSQL.

Is this to cool-off your DBA's ears? ;)

Seriously, if you could explain why you've decided to switch, I think it
would help a lot of readers understand some of the differences between
these two RDBMSs.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAklyBnIACgkQ9CaO5/Lv0PCuvgCfdZ9j+2Z5cGuk3aQsYFg7VaAO
msIAnR8r+ZmyYeJz2T3Sbzbk9hCEDGlU
=26DN
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: PostgreSQL vs MySQL with Tomcat

Posted by Rusty Wright <ru...@gmail.com>.
Regarding MySQL's autoincrement type, it looks like PostgreSQL has something similar:

http://www.postgresql.org/docs/8.3/interactive/datatype-numeric.html#DATATYPE-SERIAL

I'm in the process of migrating a MySQL database to PostgrSQL.


Christopher Schultz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Ken,
> 
> Ken Bowen wrote:
>> Unfortunately, MySQL isn't really that tunable. On the other hand, MySQL
>> requires very little in the way of tuning!
> 
> This was my comment, and that's the gist I got from reading Zawodny's
> and Balling's "High Performance MySQL" from O'Reilly. There are /some/
> things you can tune, but not much. It's like an auto-adjusting clutch.
> Sure, you can adjust it, but it's going to do a pretty good job on its own.
> 
>> I created a couple of proof-of-concept projects with PostgreSQL for
>> someone about six months ago, and the only really puzzling thing what
>> how to set up "sequences" corresponding to MySQL's AUTOINCREMENT (I'm
>> not sure I've really wrapped head around it completely anyway).  For
>> those small projects, it worked well, but there was no stress involved.
> 
> I have no experience with PostgreSQL, but I was always irritated by lack
> of support (in previous JDBC specifications) for the AUTOINCREMENT
> fields (fixed, of course, in JDBC 1.4 when Statement.getGeneratedKeys
> was added). Oracle-style SEQUENCES always made more sense to me --
> although they require an additional query to be issued every time you
> want a new id, you can use them for anything; not just record PKs.
> 
> I think PostgreSQL has Oracle-style sequences. There are no
> auto-incrementing PKs or anything like that: you first SELECT the next
> value from the sequence, then use that as the PK for your INSERT that
> you issue immediately afterward. If you don't need to capture the new id
> from the code, you could probably even do this:
> 
> INSERT INTO my_table (id, ...)
> VALUES ((SELECT next FROM my_sequence), ...)
> 
> I have no idea if that would even work. Give it a try!
> 
>> I'd like to hear about people's experiences and what they think are the
>> strengths and weaknesses of each DBMS for use behind Tomcat.
> 
> MySQL has always had super good performance for me, especially using
> MyISAM tables. The addition of InnoDB tables was great because you got
> the relatively fast speed of MySQL (compared to, say, Oracle) with the
> integrity you really expect from a production-quality RDBMS.
> 
> Since I'm not a DBA, I'm appreciated the fact that MySQL can often be a
> fire-and-forget kind of service. It just doesn't need much care and
> feeding. I remember my first job out of college required new engineering
> hires to go through their one-box-wonder runbooks to make sure we
> "understood how installs went and how the pieces fit together".
> Installing Apache Jserv (yeah!), httpd, and most everything else took
> about one or two printed pages of documentation. The rest of the runbook
> was Oracle install and configuration. Install. Run the command-line
> tool. Quit the command-line tool. Edit a config file. Re-run the
> command-line tool. Create the database. Quit the command-line tool.
> Change the rollback segment size. Etc. etc. etc. I never even understood
> anything I was doing, and neither did the folks that were supervising
> our execution of these tasks. These were just instructions that probably
> worked for someone in the past, so they wrote them down and nobody ever
> bothered to figure out if there were any better options. I was one of
> the first engineers who used MySQL in a project that went to production
> (and I had to implement my own pre-innodb manual rollback logic -- yikes!).
> 
> MySQL supports a lot of functions that are, of course, outside the SQL
> standard, but are nonetheless useful. Here is what my MySQL driver
> (Connector/J 5.0.8) reports for the functions available to the client
> (server version is 5.0.70):
> 
> Supported functions:
> Numeric:
> ABS,ACOS,ASIN,ATAN,ATAN2,BIT_COUNT,CEILING,COS,COT,DEGREES,EXP,FLOOR,LOG,LOG10,MAX,MIN,MOD,PI,POW,POWER,RADIANS,RAND,ROUND,SIN,SQRT,TAN,TRUNCATE
> String:
> ASCII,BIN,BIT_LENGTH,CHAR,CHARACTER_LENGTH,CHAR_LENGTH,CONCAT,CONCAT_WS,CONV,ELT,EXPORT_SET,FIELD,FIND_IN_SET,HEX,INSERT,INSTR,LCASE,LEFT,LENGTH,LOAD_FILE,LOCATE,LOCATE,LOWER,LPAD,LTRIM,MAKE_SET,MATCH,MID,OCT,OCTET_LENGTH,ORD,POSITION,QUOTE,REPEAT,REPLACE,REVERSE,RIGHT,RPAD,RTRIM,SOUNDEX,SPACE,STRCMP,SUBSTRING,SUBSTRING,SUBSTRING,SUBSTRING,SUBSTRING_INDEX,TRIM,UCASE,UPPER
> System:
> DATABASE,USER,SYSTEM_USER,SESSION_USER,PASSWORD,ENCRYPT,LAST_INSERT_ID,VERSION
> Time/Date:
> DAYOFWEEK,WEEKDAY,DAYOFMONTH,DAYOFYEAR,MONTH,DAYNAME,MONTHNAME,QUARTER,WEEK,YEAR,HOUR,MINUTE,SECOND,PERIOD_ADD,PERIOD_DIFF,TO_DAYS,FROM_DAYS,DATE_FORMAT,TIME_FORMAT,CURDATE,CURRENT_DATE,CURTIME,CURRENT_TIME,NOW,SYSDATE,CURRENT_TIMESTAMP,UNIX_TIMESTAMP,FROM_UNIXTIME,SEC_TO_TIME,TIME_TO_SEC
> 
> Some stuff is a bit far-fetched (SOUNDEX? come on...) but others are
> very useful (like the statistical functions, regular expressions, etc.).
> 
> I definitely make use of these functions in my apps, even though they
> are MySQL-specific (I just make sure to say something in the code
> comments!).
> 
> I don't make heavy use of stored procedures, so I cannot comment on
> those but you may make your decision based upon only that (supported
> languages, spec compliance, etc.).
> 
> I do know that triggers have only recently made an appearance and I
> tried playing with them once: my initial experience was that they did
> not meet my needs. All I wanted to do was check some stuff and then
> throw an error if some conditions weren't met: essentially a complex
> CONSTRAINT that MySQL wasn't able to do with a regular DDL constraint.
> Apparently, this version of MySQL (5.0?) doesn't allow you to simply say
> "fail right now". Instead, I had to do a SELECT from a table that didn't
> exist, but had an informative name (like "SELECT bogus FROM
> your-record-is-bad").
> 
> That's about it. MySQL has been very good to me, in spite of the
> strangeness with which I've had to deal for almost a decade, now.
> 
> I'd love to hear others' experiences.
> 
> Hope that helps,
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iEYEARECAAYFAklvxlIACgkQ9CaO5/Lv0PCtFwCgm10RxhfqVfZLaQuJ7atsXIZq
> 3Y4AnjjrSUA6E16dYpg3th5ka+1ueprY
> =hHWo
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: PostgreSQL vs MySQL with Tomcat

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ken,

Ken Bowen wrote:
> Unfortunately, MySQL isn't really that tunable. On the other hand, MySQL
> requires very little in the way of tuning!

This was my comment, and that's the gist I got from reading Zawodny's
and Balling's "High Performance MySQL" from O'Reilly. There are /some/
things you can tune, but not much. It's like an auto-adjusting clutch.
Sure, you can adjust it, but it's going to do a pretty good job on its own.

> I created a couple of proof-of-concept projects with PostgreSQL for
> someone about six months ago, and the only really puzzling thing what
> how to set up "sequences" corresponding to MySQL's AUTOINCREMENT (I'm
> not sure I've really wrapped head around it completely anyway).  For
> those small projects, it worked well, but there was no stress involved.

I have no experience with PostgreSQL, but I was always irritated by lack
of support (in previous JDBC specifications) for the AUTOINCREMENT
fields (fixed, of course, in JDBC 1.4 when Statement.getGeneratedKeys
was added). Oracle-style SEQUENCES always made more sense to me --
although they require an additional query to be issued every time you
want a new id, you can use them for anything; not just record PKs.

I think PostgreSQL has Oracle-style sequences. There are no
auto-incrementing PKs or anything like that: you first SELECT the next
value from the sequence, then use that as the PK for your INSERT that
you issue immediately afterward. If you don't need to capture the new id
from the code, you could probably even do this:

INSERT INTO my_table (id, ...)
VALUES ((SELECT next FROM my_sequence), ...)

I have no idea if that would even work. Give it a try!

> I'd like to hear about people's experiences and what they think are the
> strengths and weaknesses of each DBMS for use behind Tomcat.

MySQL has always had super good performance for me, especially using
MyISAM tables. The addition of InnoDB tables was great because you got
the relatively fast speed of MySQL (compared to, say, Oracle) with the
integrity you really expect from a production-quality RDBMS.

Since I'm not a DBA, I'm appreciated the fact that MySQL can often be a
fire-and-forget kind of service. It just doesn't need much care and
feeding. I remember my first job out of college required new engineering
hires to go through their one-box-wonder runbooks to make sure we
"understood how installs went and how the pieces fit together".
Installing Apache Jserv (yeah!), httpd, and most everything else took
about one or two printed pages of documentation. The rest of the runbook
was Oracle install and configuration. Install. Run the command-line
tool. Quit the command-line tool. Edit a config file. Re-run the
command-line tool. Create the database. Quit the command-line tool.
Change the rollback segment size. Etc. etc. etc. I never even understood
anything I was doing, and neither did the folks that were supervising
our execution of these tasks. These were just instructions that probably
worked for someone in the past, so they wrote them down and nobody ever
bothered to figure out if there were any better options. I was one of
the first engineers who used MySQL in a project that went to production
(and I had to implement my own pre-innodb manual rollback logic -- yikes!).

MySQL supports a lot of functions that are, of course, outside the SQL
standard, but are nonetheless useful. Here is what my MySQL driver
(Connector/J 5.0.8) reports for the functions available to the client
(server version is 5.0.70):

Supported functions:
Numeric:
ABS,ACOS,ASIN,ATAN,ATAN2,BIT_COUNT,CEILING,COS,COT,DEGREES,EXP,FLOOR,LOG,LOG10,MAX,MIN,MOD,PI,POW,POWER,RADIANS,RAND,ROUND,SIN,SQRT,TAN,TRUNCATE
String:
ASCII,BIN,BIT_LENGTH,CHAR,CHARACTER_LENGTH,CHAR_LENGTH,CONCAT,CONCAT_WS,CONV,ELT,EXPORT_SET,FIELD,FIND_IN_SET,HEX,INSERT,INSTR,LCASE,LEFT,LENGTH,LOAD_FILE,LOCATE,LOCATE,LOWER,LPAD,LTRIM,MAKE_SET,MATCH,MID,OCT,OCTET_LENGTH,ORD,POSITION,QUOTE,REPEAT,REPLACE,REVERSE,RIGHT,RPAD,RTRIM,SOUNDEX,SPACE,STRCMP,SUBSTRING,SUBSTRING,SUBSTRING,SUBSTRING,SUBSTRING_INDEX,TRIM,UCASE,UPPER
System:
DATABASE,USER,SYSTEM_USER,SESSION_USER,PASSWORD,ENCRYPT,LAST_INSERT_ID,VERSION
Time/Date:
DAYOFWEEK,WEEKDAY,DAYOFMONTH,DAYOFYEAR,MONTH,DAYNAME,MONTHNAME,QUARTER,WEEK,YEAR,HOUR,MINUTE,SECOND,PERIOD_ADD,PERIOD_DIFF,TO_DAYS,FROM_DAYS,DATE_FORMAT,TIME_FORMAT,CURDATE,CURRENT_DATE,CURTIME,CURRENT_TIME,NOW,SYSDATE,CURRENT_TIMESTAMP,UNIX_TIMESTAMP,FROM_UNIXTIME,SEC_TO_TIME,TIME_TO_SEC

Some stuff is a bit far-fetched (SOUNDEX? come on...) but others are
very useful (like the statistical functions, regular expressions, etc.).

I definitely make use of these functions in my apps, even though they
are MySQL-specific (I just make sure to say something in the code
comments!).

I don't make heavy use of stored procedures, so I cannot comment on
those but you may make your decision based upon only that (supported
languages, spec compliance, etc.).

I do know that triggers have only recently made an appearance and I
tried playing with them once: my initial experience was that they did
not meet my needs. All I wanted to do was check some stuff and then
throw an error if some conditions weren't met: essentially a complex
CONSTRAINT that MySQL wasn't able to do with a regular DDL constraint.
Apparently, this version of MySQL (5.0?) doesn't allow you to simply say
"fail right now". Instead, I had to do a SELECT from a table that didn't
exist, but had an informative name (like "SELECT bogus FROM
your-record-is-bad").

That's about it. MySQL has been very good to me, in spite of the
strangeness with which I've had to deal for almost a decade, now.

I'd love to hear others' experiences.

Hope that helps,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAklvxlIACgkQ9CaO5/Lv0PCtFwCgm10RxhfqVfZLaQuJ7atsXIZq
3Y4AnjjrSUA6E16dYpg3th5ka+1ueprY
=hHWo
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: PostgreSQL vs MySQL with Tomcat

Posted by Ognjen Blagojevic <og...@etf.bg.ac.rs>.
In our company we used MySQL and Postgres for several projects. Both 
DBMSs are mature and stable, and they are used worldwide for large-scale 
projects. Performance-wise we measured some differences, but they were 
not so big to notice them in the real-life loads. In other words, having 
some experience with both DBMSs, I couldn't recommend either one being 
definitely better than the other.

That said, the most important consideration for us was the license. 
MySQL uses dual licensing model (GPL+commercial), while Postgres uses 
BSD license. That was the main selection criteria for us.

Regards,
Ognjen


Ken Bowen wrote:
> Hi all (especially Chris -- very informative long post today on 
> Tomcat/MySQL):
> 
> For a several reasons (including the apparent infinite default for 
> connection timeout), I'm contemplating switching one or two projects 
> from MySQL to PostgreSQL.  I'd like to gather opinions on the tradeoffs, 
> including:
> 
> Unfortunately, MySQL isn't really that tunable. On the other hand, MySQL
> requires very little in the way of tuning!
> 
> I created a couple of proof-of-concept projects with PostgreSQL for 
> someone about six months ago, and the only really puzzling thing what 
> how to set up "sequences" corresponding to MySQL's AUTOINCREMENT (I'm 
> not sure I've really wrapped head around it completely anyway).  For 
> those small projects, it worked well, but there was no stress involved.
> 
> I'd like to hear about people's experiences and what they think are the 
> strengths and weaknesses of each DBMS for use behind Tomcat.
> 
> Thanks much in advance,
> Ken Bowen
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: PostgreSQL vs MySQL with Tomcat

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jonathan,

Jonathan Mast wrote:
> * Postgre has more features (sequences and triggers) but also an enormous
> amount of complexity
> * MySQL has much finer authorization control, but lacks some of the big-boy
> features such as triggers
> ** of course a lot has changed in the newer versions of both of these DBMS

N.B. MySQL does have triggers in MySQL 5.0.2 and upward. A sequence can
be implemented using a table with a single AUTOINCREMENT field. Kind of
a hack, but if you /require/ Oracle-style sequence behavior, you can get it.

I totally agree that some "big boy features" seem to be missing from
MySQL. Over the years, they have played quite a good game of catch-up.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAklvxvgACgkQ9CaO5/Lv0PBmxwCfWDH0u/pU4JhsRICqhs0UCgZR
vq4AnRN1oJVRiIwcX05efqqtQUfEMz+o
=vHzs
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: PostgreSQL vs MySQL with Tomcat

Posted by Jonathan Mast <jh...@gmail.com>.
Our organization has products backed by both databases and we are almost
entirely shielded from the database details in Tomcat.  I don't really see
how it should matter in terms of Tomcat (or any Web container).  I'm
thinking this is more a Java issue than a Tomcat issue.

The main differences we've encountered is that the MySQL implementation of
JDBC requires some extra parameters to be passed along when connections are
made, otherwise the ResultSet will fail on particular conditions.  But this
is an database layer issue, and the db layer exists independently of the web
apps.

Our observation of the MySQL vs Postgre debate is this: (btw we use versions
5.0 and 8.1 respectively)
* Postgre has more features (sequences and triggers) but also an enormous
amount of complexity
* MySQL has much finer authorization control, but lacks some of the big-boy
features such as triggers
** of course a lot has changed in the newer versions of both of these DBMS


On Thu, Jan 15, 2009 at 5:20 PM, Ken Bowen <kb...@als.com> wrote:

> Hi all (especially Chris -- very informative long post today on
> Tomcat/MySQL):
>
> For a several reasons (including the apparent infinite default for
> connection timeout), I'm contemplating switching one or two projects from
> MySQL to PostgreSQL.  I'd like to gather opinions on the tradeoffs,
> including:
>
> Unfortunately, MySQL isn't really that tunable. On the other hand, MySQL
> requires very little in the way of tuning!
>
> I created a couple of proof-of-concept projects with PostgreSQL for someone
> about six months ago, and the only really puzzling thing what how to set up
> "sequences" corresponding to MySQL's AUTOINCREMENT (I'm not sure I've really
> wrapped head around it completely anyway).  For those small projects, it
> worked well, but there was no stress involved.
>
> I'd like to hear about people's experiences and what they think are the
> strengths and weaknesses of each DBMS for use behind Tomcat.
>
> Thanks much in advance,
> Ken Bowen
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: PostgreSQL vs MySQL with Tomcat

Posted by Chris Wareham <cw...@visitlondon.com>.
Ken Bowen wrote:
> Hi all (especially Chris -- very informative long post today on 
> Tomcat/MySQL):
> 
> For a several reasons (including the apparent infinite default for 
> connection timeout), I'm contemplating switching one or two projects 
> from MySQL to PostgreSQL.  I'd like to gather opinions on the tradeoffs, 
> including:
> 
> Unfortunately, MySQL isn't really that tunable. On the other hand, MySQL
> requires very little in the way of tuning!
> 

Not true, unless your needs are very modest. The InnoDB engine has a
large number of tunable parameters - however, they are poorly and
incompletely documented in the MySQL manual, while changing them may
cause your indexes to be silently dropped when you restart MySQL. The
MyISAM engine also has a number of tunable parameters, but I would only
use this engine in preference to InnoDB if you need full text indexing,
and only for the specific tables that require full text indexes.

> I created a couple of proof-of-concept projects with PostgreSQL for 
> someone about six months ago, and the only really puzzling thing what 
> how to set up "sequences" corresponding to MySQL's AUTOINCREMENT (I'm 
> not sure I've really wrapped head around it completely anyway).  For 
> those small projects, it worked well, but there was no stress involved.
> 

Where you would use an AUTO_INCREMENT column in MySQL, use a SERIAL
column in PostgreSQL which creates a sequence for you. There's a good
description in the PostgreSQL manual:

http://www.postgresql.org/docs/8.3/static/datatype-numeric.html#DATATYPE-SERIAL

> I'd like to hear about people's experiences and what they think are the 
> strengths and weaknesses of each DBMS for use behind Tomcat.
> 

PostgreSQL is not perfect, but it has proven to be faster and far more
reliable than MySQL in the projects where I have tested both. The full
text indexing in PostgreSQL is far more sophisticated, although at the
cost of slightly more complexity to use. Tuning is generally
straightforward, and far less of a black art than it is with MySQL.
Finally, I spend far less time analysing query plans and optimising by
hand when using PostgreSQL rather than MySQL, as the former handles
joins across more than one table far better.

> Thanks much in advance,
> Ken Bowen
> 

Chris
--
 
Chris Wareham
Senior Software Engineer
Visit London Ltd
6th floor,
2 More London Riverside, London SE1 2RR
 
Tel:  +44 (0)20 7234 5848
Fax: +44 (0)20 7234 5753

 
www.visitlondon.com





   
   
'Visit London Limited' is registered in England under No.761149;
Registered Office: Visit London, 2 More London Riverside, London SE1 2RR.
 

Visit London is the official visitor organisation for London. Visit London is partly funded by Partnership, the Mayor's London Development Agency and London Councils.
The information contained in this e-mail is confidential and intended for the named recipient(s) only.  If you have received it in error, please notify the sender immediately and then delete the message.  If you are not the intended recipient, you must not use, disclose, copy or distribute this email. The views expressed in this e-mail are those of the individual and not of Visit London. We reserve the right to read and monitor any email or attachment entering or leaving our systems without prior notice.
 
  Please don't print this e-mail unless you really need to.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: PostgreSQL vs MySQL with Tomcat

Posted by Jim Cox <sh...@gmail.com>.
As far as schemas in Postgres go, a normal way to handle them is to create
schema-specific users with an appropriately-set default schema, e.g.
something like:
  CREATE SCHEMA company_a ;
  CREATE USER company_a_user PASSWORD 'foo' ;
  ALTER USER company_a_user SET search_path TO company_a, public ;
  GRANT USAGE ON SCHEMA company_a TO company_a_user ;
  --  ...or (I think) GRANT ALL PRIVILEGES ON SCHEMA company_a TO
company_a_user


On Fri, Jan 16, 2009 at 3:28 PM, Rusty Wright <ru...@gmail.com>wrote:

> That may be true about the public schema being used when one isn't
> specified.  But when I use their pgAdmin gui tool and open the query window
> and try to run the tiger sample from the Jailer tutorial it blows up on the
> table creates, saying:
>
>  ERROR:  no schema has been selected to create in
>
>  ********** Error **********
>
>  ERROR: no schema has been selected to create in
>  SQL state: 3F000
>
> I wonder if iBatis is adding the public schema automatically for you?  Or
> maybe when I set up my db account I didn't do something I should have?  Or I
> changed something and don't remember.
>
> And you've prompted me to remember another reason why I thought schemas are
> required.
>
> When our DBA set up PostgreSQL he didn't do much tweaking and the public
> schema had odd permissions; if I remember correctly it allowed me to create
> tables in the databases of other users in their public schema.  I didn't try
> dropping their tables in their public schema but it may have allowed that as
> well.
>
> On my test db the sql for the public schema is
>
> CREATE SCHEMA public
>  AUTHORIZATION postgres;
> GRANT ALL ON SCHEMA public TO postgres;
> COMMENT ON SCHEMA public IS 'Standard public schema';
>
> Just after I installed postgres it had another grant line which I think was
> (or similar to) "GRANT ALL ON SCHEMA public TO public;" which I deleted (and
> in my usual boneheaded fashion, forgot to document my change, but it's my
> personal test database).
>
>
>
> Ingmar Lötzsch wrote:
>
>> Some comments (and answers to Christopher and Rusty) on PostgreSQL:
>>
>> ...
>>
>> This isn't true. You can (and perhaps should) always omit the schema.
>> The default schema "public" is used in this case. You can execute
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: PostgreSQL vs MySQL with Tomcat

Posted by Rusty Wright <ru...@gmail.com>.
That may be true about the public schema being used when one isn't specified.  But when I use their pgAdmin gui tool and open the query window and try to run the tiger sample from the Jailer tutorial it blows up on the table creates, saying:

  ERROR:  no schema has been selected to create in

  ********** Error **********

  ERROR: no schema has been selected to create in
  SQL state: 3F000

I wonder if iBatis is adding the public schema automatically for you?  Or maybe when I set up my db account I didn't do something I should have?  Or I changed something and don't remember.

And you've prompted me to remember another reason why I thought schemas are required.

When our DBA set up PostgreSQL he didn't do much tweaking and the public schema had odd permissions; if I remember correctly it allowed me to create tables in the databases of other users in their public schema.  I didn't try dropping their tables in their public schema but it may have allowed that as well.

On my test db the sql for the public schema is

CREATE SCHEMA public
  AUTHORIZATION postgres;
GRANT ALL ON SCHEMA public TO postgres;
COMMENT ON SCHEMA public IS 'Standard public schema';

Just after I installed postgres it had another grant line which I think was (or similar to) "GRANT ALL ON SCHEMA public TO public;" which I deleted (and in my usual boneheaded fashion, forgot to document my change, but it's my personal test database).



Ingmar Lötzsch wrote:
> Some comments (and answers to Christopher and Rusty) on PostgreSQL:
> 
> ...
>
> This isn't true. You can (and perhaps should) always omit the schema.
> The default schema "public" is used in this case. You can execute

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: PostgreSQL vs MySQL with Tomcat

Posted by Ingmar Lötzsch <il...@asci-systemhaus.de>.
Some comments (and answers to Christopher and Rusty) on PostgreSQL:

In 2004 our team decided to use PostgreSQL instead of the well-known
MySQL (current version 4). The main reasons where

- real referential integrity
- real transactions
- support for UTF-8 enoding
- better compliance with the SQL standard

> The one warning I can think of with PostgreSQL is that you have to use
> schemas; you either have to set the schema after you connect, and I
> think I couldn't figure out how to do that with jdbc, or you specify it
> as part of every table name; "create table schema_name.table_name ...;
> select whatever from schema_name.table_name;".  Schemas are quite cool,
> so don't take this as a criticism.

This isn't true. You can (and perhaps should) always omit the schema.
The default schema "public" is used in this case. You can execute

CREATE TABLE foo
(
	id serial NOT NULL PRIMARY KEY,
	description text NOT NULL
);

>NOTICE:  CREATE TABLE will create implicit sequence "foo_id_seq" for
serial column "foo.id"
>NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index
"foo_pkey" for table "foo"

INSERT INTO foo (description) VALUES ('foo');
SELECT * FROM foo;

>1;"foo"

SELECT currval('foo_id_seq');

>1

In the persistende layer we have switched from JDBC to iBATIS.

There you have the SQL statements organized in XML files. One approach
for INSERT is

<insert id="insert" parameterClass="com.asci.Foo" >
	<selectKey keyProperty="id" resultClass="int" type="pre">
		SELECT nextval('foo_id_seq')
	</selectKey>
	INSERT INTO foo (id, description)
    	VALUES
	(
    		#id:INTEGER#,
    		#description:VARCHAR#
	)
</insert>

In the DAO implementation you have

public Integer insert(Foo foo)
{
	Integer id = (Integer) getSqlMapClientTemplate().insert("foo.insert", foo);
	return id;
}

or simply

public void insert(Foo foo)
{
	getSqlMapClientTemplate().insert("foo.insert", foo);
}

After the call the Foo instance contains the generated ID in both cases.

We didn't need much support for PostgreSQL. The documentation is
comprehensive. The installation under Windows is easy. The installation
unter UNIX systems can have some difficulties.

Ingmar

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: PostgreSQL vs MySQL with Tomcat

Posted by Rusty Wright <ru...@gmail.com>.
I've found MySQL's error messages particularly worthless in some situations; I had a foreign constraint and it was giving me some generic error when I was violating that foreign constraint.  Say MySQL around our DBA and steam starts coming out of his ears.

The one warning I can think of with PostgreSQL is that you have to use schemas; you either have to set the schema after you connect, and I think I couldn't figure out how to do that with jdbc, or you specify it as part of every table name; "create table schema_name.table_name ...; select whatever from schema_name.table_name;".  Schemas are quite cool, so don't take this as a criticism.


Ken Bowen wrote:
> Hi all (especially Chris -- very informative long post today on 
> Tomcat/MySQL):
> 
> For a several reasons (including the apparent infinite default for 
> connection timeout), I'm contemplating switching one or two projects 
> from MySQL to PostgreSQL.  I'd like to gather opinions on the tradeoffs, 
> including:
> 
> Unfortunately, MySQL isn't really that tunable. On the other hand, MySQL
> requires very little in the way of tuning!
> 
> I created a couple of proof-of-concept projects with PostgreSQL for 
> someone about six months ago, and the only really puzzling thing what 
> how to set up "sequences" corresponding to MySQL's AUTOINCREMENT (I'm 
> not sure I've really wrapped head around it completely anyway).  For 
> those small projects, it worked well, but there was no stress involved.
> 
> I'd like to hear about people's experiences and what they think are the 
> strengths and weaknesses of each DBMS for use behind Tomcat.
> 
> Thanks much in advance,
> Ken Bowen
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org