I have a MySQL database that I am migrating to PostgreSQL (due to GIS features).
Many of the tables contain hundreds of thousands of rows, so I need to remember performance.
My problem is that PostgreSQL seems awfully slow ...
For example, if I make a simple SELECT * FROM [table] in a particular table in a MySQL database, say that it has 113,000 rows, the query takes about 2 seconds to return the data. In PostgreSQL, an exact query in the same table takes almost 10 seconds.
Similarly, I have another table with fewer rows (88,000), and this is worse! MySQL takes 1.3 seconds, PostgreSQL takes 30 seconds!
Is this what I can expect from PostgreSQL, or is there something I can do to make it better?
My OS is XP and I am running 2.7ghz dual code with 3GB of RAM. The MySQL database is version 5.1 using the standard standard. The PostgreSQL database is version 8.4, and I edited the configuration as follows: shared_buffers = 128 MB effective_cache_size = 512 MB
Thanks!
Here is the structure of the second table, which contains about 88,000 rows:
CREATE TABLE nodelink ( nodelinkid serial NOT NULL, workid integer NOT NULL, modifiedbyid integer, tabulardatasetid integer, fromnodeid integer, tonodeid integer, materialid integer, componentsubtypeid integer, crosssectionid integer, "name" character varying(64) NOT NULL, description character varying(256) NOT NULL, modifiedbyname character varying(64) NOT NULL,
I played a little with the select statement. If I just do "Select NodeLinkID from NodeLink", the request will be much faster - less than a second to get 88,000 rows. If I do "Select NodeLinkID generated from NodeLink", the request will take a long time - about 8 seconds. Does this shed light on what I'm doing wrong?
Other findings:
CREATE INDEX nodelink_lengthIDX on nodelink (length);
analyze nodelink
- Query execution: SELECT * FROM nodelink WHERE Length BETWEEN 0 AND 3.983 Total query execution time: 3109 ms. Found 10,000 rows.
- Query execution: SELECT nodelinkID FROM nodelink WHERE Length BETWEEN 0 AND 3.983 Total query execution time: 125 ms. Found 10,000 rows.
In MySQL, the first query is executed in approximately 120 ms, the second is executed in approximately 0.02ms.
Resolution of the issue:
Well guys, it looks like it was a storm in a cup ...
mjy is correct:
"How did you measure these timings - in your application or the corresponding command line interfaces?"
To test this theory, I put together a simple console application that ran the same query in MySQL db and the PGSQL database. Here is the result:
Running MySQL query: [SELECT * FROM l_model_ldata] MySQL duration = [2.296875] Running PGSQL query: [SELECT * FROM nodelink] PGSQL duration = [2.875]
Thus, the results are comparable. It seems that the pgadmin tool that comes with postgreSQL is pretty slow. Thanks to everyone for their suggestions and help!
mjy, if you want to post the answer, I can mark it as the correct answer for future reference.