Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many of you have gone from MySQL to Postgresql? Was it worth it?

I'm thinking about moving from MySQL to Postgres for Rails development and I just want to hear what other developers that made the move have to say about it.

I'm looking for personal experiences, not a Mysql v Postgres shootout, just the pros and cons that you yourself have arrived at. Stuff that folks might not necessarily think.

Feel free to explain why you moved in the first place as well.

like image 351
concept47 Avatar asked Jun 03 '10 07:06

concept47


People also ask

Is it easy to migrate from MySQL to PostgreSQL?

To connect MySQL to PostgreSQL through Foreign Data Wrapper, you must take note of the following as this is what will be required to create the connection: CREATE EXTENSION command to create a MySQL Foreign Data Wrapper extension to the PostgreSQL host. CREATE SERVER command to define a connection to the MySQL Server.

Is PostgreSQL better than MySQL?

PostgreSQL is perceived as a go-to solution for performing complicated, high-volume data operations. That's because when it comes to PostgreSQL vs MySQL, the former is better at handling extraordinary database situations. PostgreSQL has more features than other database management systems (users attest to this).

Is it possible to migrate from MySQL to PostgreSQL?

MySQL-to-PostgreSQL is a program to migrate MySQL databases to PostgreSQL server. Option to filter data using SELECT-queries, synchronization mode, command line support. FromMySqlToPostgreSql migration tool by Anatoly Khaytovich, provides an accurate migration of table data, indices, PKs, FKs...

Is PostgreSQL harder to learn than MySQL?

To put this in perspective, PostgreSQL is a feature-rich Database that can handle complex queries, while MySQL is a far simpler Database that is relatively simpler to set up, and manage and is fast, reliable, and easy to understand.


2 Answers

I made the switch and frankly couldn't be happier. While Postgres lacks a few things of MySQL (Insert Ignore, Replace, Upsert stuff, and Load Data Infile for me mainly), the features it does have MORE than make up. Its stored procedures are so much more powerful and it's far easier to write complex functions and aggregates in Postgres.

Performance-wise, if you're comparing to InnoDB (which is only fair because of MVCC), then it feels at least as fast, possibly faster - we weren't able to do some real measurements here due to some constraints, but there certainly hasn't been a performance issue. The complex queries with several joins are certainly faster, MUCH faster.

I find you're more likely to get the correct answer to your issue from the Postgres community. Everybody and their grandmother has 50 different ways to do something in MySQL. With Postgres, hit up the mailing list and you're likely to get lots of very very good help.

Any of the syntax and the like differences are a bit trivial.

Overall, Postgres feels a lot more "grown-up" to me. I used MySQL for years and I now go out of my way to avoid it.

like image 75
rfusca Avatar answered Oct 23 '22 04:10

rfusca


Oh dear, this could end in tears.

Speaking from personal experience only, we moved from MySQL solely because our production system (Heroku) is running PostgreSQL. We had custom-built-for-MySQL queries which were breaking on PostgreSQL. So I guess the morale of the story here is to run on the same DBMS over everything, otherwise you may run into problems.

We also sometimes needs to insert records Über-quick-like. For this, we use PostgreSQL's built-in COPY function, used similarly to this in our app:

query = "COPY users(email) FROM STDIN WITH CSV"
values = users.map! do |user|
  # Be wary of the types of the objects here, they matter.
  # For instance if you set the id to a string it will error.

  %Q{#{user["email"]}}
end.join("\n")

raw_connection.exec(query)
raw_connection.put_copy_data(values)
raw_connection.put_copy_end

This inserts ~500,000 records into the database in just under two minutes. Around about the same time if we add more fields.

Another couple of nice things PostgreSQL has over MySQL:

  • Full text searching
  • Geographical querying (PostGIS)
  • LIKE syntax is like this email ~ 'hotmail|gmail', NOT LIKE is like email !~ 'hotmail|gmail'. The | indicates an or.

In summary: PostgreSQL is like bricks & mortar, where MySQL is Lego. Go with whatever "feels" right to you. This is only my personal opinion.

like image 40
Ryan Bigg Avatar answered Oct 23 '22 06:10

Ryan Bigg