593 points · by teoruiz · 13y ago · 239 comments
I'm using the AWS stack for http://www.soundslice.com/ and I've been using MySQL instead of Postgres, purely because my hatred for MySQL is less than my hatred for being a sysadmin. It was a tradeoff, and I miss Postgres dearly every time I use MySQL.
This new Amazon offering solves that.
I wrote a little more about my AWS setup here: http://www.holovaty.com/writing/aws-notes/
Last time I badmouthed Heroku on here I got a reply from one of their employees asking me to fill out support tickets for errors I was getting in their apps......
O_o they're watching.
FYI, it doesn't look your payment modal works on smaller browser windows: https://www.monosnap.com/image/UvJbxMQEwkzqLH5btNJ7a9G6Q ... no visible pay button, and the modal itself scrolls when you scroll the page.
Does it make sense to migrate to PostgreSQL, I don't have a lot of data as I'm in the early stage? What are the primary advantages that PostgreSQL provides over MySQL? Any advise/pointers is appreciated.
Perhaps you mistakenly insert "2013-10-32" into a date column. MySQL will silently convert this to "0000-00-00" (!!). Postgres will raise an error.
Perhaps you make an error in a transaction. MySQL lets you keep doing subsequent things in the transaction. Postgres treats the transaction as invalid and forces you to start over.
Perhaps you want to add a column to a table that has millions of rows. With MySQL, you'll be waiting a looooong time (see http://stackoverflow.com/questions/463677/alter-table-withou...). With Postgres, it takes about a second.
Of course, there are things you can do to make MySQL less horrible, and this is a generalization. But Postgres is just more respectful and more solid.
Oh, and PostGIS (Postgres' geo add-on) is by far the best open-source geospatial database. If you're doing anything with geographic queries, you need to be using it. MySQL's stuff is laughable in comparison.
Context: I've dealt extensively with both databases, both from the perspective of a framework author (Django) and a developer making products. I've used both databases on and off since 2001.
The thing that kills me with MySQL (technically it's with InnoDB-based storage enginges in MySQL) are the subtle quirks. Like the thing where it insists on writing temporary tables to disk if you do a query that selects TEXT or BLOB fields. Even if they could have easily fit in memory, it's not smart enough to be able to determine that with variable length fields. A very non-obvious performance killer unless you're specifically looking for it.
> Perhaps you mistakenly insert "2013-10-32" into a date column.
Only with ALLOW_INVALID_DATES sql mode set. As of 5.0.2, the server requires by default that month and day values be legal, and not merely in the range 1 to 12 and 1 to 31.[1]
> Perhaps you make an error in a transaction. MySQL lets you keep doing subsequent things in the transaction.
If you care about transactions you should have STRICT_TRANS_TABLES on.[2]
[1] - http://dev.mysql.com/doc/refman/5.6/en/server-sql-mode.html#...
[2] - http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#...
Understand, MySQL-ers, I know that your DB has been patched A LOT over the last decade, but running with something that did not support ROLLBACK (nor isolation), nor foreign key constraints???
That the MySQL team even thought they could call such a thing a database terrified me, and made me quite scared to ever trust their judgement. (viewing the comments for this article suggest to me that playing those odds was the right thing to do, as well, rather than simply "prejudice")
That, and at the time, PostGreSQL was supporting stored functions that fit anywhere in SQL statement syntax that the return type matched the needed expression type (scalar, vector/row, matrix/table), and could be written in a PL/SQL work-alike OR alternate loadable languages, while MySQL had no stored procedures at all.
That, and at the time (already), PostGreSQL supported OOP-ish "extension" tables that extended other tables with extra, specialized, columns. Rows in the specialized, subclass, table would show up in the generalized, superclass, table (sans extra columns), but the subclass table would only show the relevant specialized type rows, with non-null columns where needed. Other DBs required you to join 2 tables and manage joins and a view to do this.
Putting SQL syntax on top of an ISAM engine just makes it dBase with awkward syntax, and that's not an environment I wish to revisit. (I know that InnoDB is constantly twiddled to suck less, but that back-end was extra back in the day, yes?)
I think the biggest advantages are trust and flexibility.
Trust, because PostgreSQL language semantics are cleaner, closer to the SQL standard, and less likely to surprise you. And postgresql just has a good reputation for traditional engineering quality.
Flexibility, because it offers a lot of APIs and features that can be very useful to adapt your application as needs change. You don't have to go crazy with features, but even simple apps can benefit a lot from prudent use of them -- a trigger here, a foreign table there, or LISTEN/NOTIFY (for cache invalidation) can just save you a huge amount of work and make the system more robust overall. The extension mechanism is very powerful.
Before making any big decisions, do a trial migration and see what you think.
- More robust, fewer crashes, less corruption of data
- More features (JSON data type, partial indexes, function/expression indexes, window functions, CTEs, hstore, ranges/sequences/sets, too many to list)
- More disciplined (doesn't do things like auto-truncate input to get it to fit into a column)
- Not owned by Oracle, it's actively developed, regular major release schedule, etc.
- Better Python driver (don't know about other languages)
- Choice of languages for database functions/procedures (Python, JS, etc.)
- Better partitioning support
- Better explain output, explain analyze, buffers
- Multiple indexes allowed per table in a query
My group is developing all new applications in PostgreSQL and we would like to migrate our legacy apps away from MySQL.
http://dev.mysql.com/doc/refman/5.0/en/index-merge-optimizat...
The basic answer is (from what I can tell) that postgres ships with sane defaults. Lots of little gotchas exist in mysql that experienced mysql dbas know to deal with and avoid. On the more sophisticated side, pgSQL seems to have a focus on being "Really Awesome For Experts" where MySQL seems to be focusing on "Being Easy to Get Started".
I've been using pgSQL for my side project and for my "personal tooling" at work, and I can honestly say that it's just as easy for me as MySQL was for the same sort of things.
If MySQL works for you, there is no reason to change. Some people have quite a dependency on Postgres (hstore, JSON, transactional DDL, pubsub, PLPGSQL etc.)
I think there are two times when it makes sense to consider a DB migration: (1) early on, when it's easy; (2) if you are in major trouble with your existing DB.
Our dependency on Postgres is more to do with it being a lot safer with our data. It doesn't silently fail, the transactions have a better failure mode, and as previously pointed out it handles ALTER in production a LOT better than MySQL.
The combination of safety, speed/efficiency in schema/index alteration, and its increasingly good performance are why we depend on it. The rest is just gravy.
Do some search and give it a try one weekend.. Trying it is loving it.
RDS removes remarkably little of the pain of running a database instance (most of the pain that's removed is just the up front setup), and ends up adding a lot of inconveniences for your day-to-day operations.
Also don't count on their replication as your backup.
OK. That's two suggestions, but I think it's OK.
This statement seems like a complete non-sequitur: does anyone credible recommend replication as a backup strategy? It's like dinging a server vendor because you can't rely on RAID as a backup plan.
Also, you can't take advantage of replication (aside from their own read replicas within other RDS instances) or binary backups. Anything that requires access to the machine itself is impossible except through Amazon's support channels.
Its gotten better than it was, but it's still a headache to monitor and manage as a DBA.
The guide does mention using a read replica to replicate from, an intermediate RDS instance between your offsite, but I've had no trouble replicating directly from the master instance.
One thing they don't cover is replication over SSL. AWS has failed to mention this shortcoming in the docs last time I checked. To have MySQL replicate over SSL, the master and slave both need an SSL certificate signed by the same CA, which would require you to obtain a cert+key signed by the AWS RDS CA.
Of course you have the option of tunneling the replication connection into a haproxy or stunnel running on an ec2 instance, but that has it's other shortcomings. You can't use the ELBs, since you can't register the RDS instance with an ELB.
With needing a DBA, even if you're still on RDS? I don't see what that has to do with PCI compliance.
With RDS only removing the up-front setup pain, at the cost of ongoing maintenance... as someone who is also familiar with PCI (and HIPPA, and DOD) compliance, I respectfully disagree with your disagreement (well, if you're working with DOD, AWS isn't even an option to begin with).
Given the choice to run my own instance of a DB on a AWS instance (which carries the same certifications as RDS), and use RDS, I will run my own instance every time. The setup just isn't onerous enough to justify the daily productivity cost.
I disagree with the notion that RDS removes remarkably little of the pain of running a database instance.
Yes, there are projects where RDS is not a great solution, but it definitely simplifies a lot of stuff. The notion that it "only removes up-front setup pain" is silly. If you manage your databases correctly, up-front setup pain should be the vast majority of all your basic admin operations. The "at the cost of ongoing maintenance" part is a real head scratcher for me. RDS basically gives you everything you'd have with a DB on an AWS instance except a local login, which one tries to avoid using like the plague anyway.
You need to be running dedicated instances inside of VPC with your own DB install.
Administering databases is a full-time type of responsibility. Yes, you can get pretty sane defaults, and up and running without much difficulty with MS-SQL, and mySQL has been a defacto standard in the LAMP stack. That said PostreSQL has been a rock solid RDBMS. The commercial extensions for replication have been cumbersome and expensive. Here's hoping that AWS will grow/expand the replications options/features, and that they'll grow to include JS procs as that feature stabilizes.
> Database updates are made concurrently on the primary and standby resources to prevent replication lag.
Makes me feels better for setting up my own pg cluster on EC2 a week ago, which does allow reads from the replication slave. Plus, I can provision <1000 IOPS (provisioned IOPS is damn expensive with AWS), and get to use ZFS.
I don't actually know whether Heroku can failover across an AZ failure.
By default our followers and HA is automatically cross AZ. You also have an ability to create followers across region, but we do not automatically failover on those due to latency.
Heroku's solution is 2 to 4 times more expensive for the same type of DB, and RDS even allows for reserved instances to further lower the bill.
Did you add disk? People seldom do, I can attest it's a big part of the bill...
> I don't actually know whether Heroku can failover across an AZ failure.
"Followers" have preferred another AZ for quite some time -- almost since the beginning -- and Heroku Postgres HA is based on similar technology. So, yes.
So pricing wise both double if you go multi-AZ.
I didn't claim to have done a detailed price comparison but a quick look at the small sizes which are currently the ones relevant to me.
Last I heard Heroku is hosted on top of AWS. Does anyone know if Heroku's cheapest Postgres plan is hosted on a dedicated AWS Micro instance, or do they buy large AWS instances and host multiple databases on each box thereby potentially providing more IO performance?
Not all Pl are available, and it misses the PL/V8 and PL/Python at least.
And it seems that all fdw (Foreign Data Wrapper) extensions are missing.
But it's a great start, I'm looking forward to try.
If anybody know if we can still access the WAL log then it will be very useful
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_P...
EDIT: you are right, PL/Python is supported as well. I only read the "Language Extensions :PL/Perl, PL/pgSQL, PL/Tcl" part at the top.
But I was surprise to not see PL/V8 which is sandboxed
Here is a related whitepaper if you still want to setup PostgreSQL yourself: http://media.amazonwebservices.com/AWS_RDBMS_PostgreSQL.pdf
Edit: It does, see http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_P...
Now, comparing to Amazon, their '1.7 GB memory Small DB, 1-year reserved, multi-region' is around $28/month (with storage & transfer for my app no more $35/ month). The equivalent Heroku plan, Tengu (1.7 GB mem) STARTS at $350/month!!! Wow, not I'm really rethinking my hosting platform.... Amazon looks more attractive, even if I have to do a bit of sys admin for my web server/cloud server.
I expect this helps you.
If/when a Heroku RDS plugin for Postgresql arrives, competing benchmarks, a cost calculator, pros and cons would be very interesting, indeed.
Heroku pricing: https://addons.heroku.com/heroku-postgresql
Amazon pricing: http://aws.amazon.com/rds/postgresql/
Though it was free test version, I surprised to see my database is living together with many other people. (`\l`)
Your database is available publicly, and you have only minimal security.
This is awesome news! I hope we can move to it at work!
It's a form of vendor lock-in and you shouldn't support it.
Without replication it's impossible to migrate out of RDS without taking downtime (I've been through this and it was painful).
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/MySQL....
You're paying for the "as a service" part of PaaS, IaaS, SaaS, *aaS.
A lot of people talk about how poor the storage performance on AWS is - but this seems to offer provisioned IOPS up to 30,000 IOPS.
I'm curious what sort of hardware/setup that translates to in the real world? Do you find your own dedicated setups have more throughput?
And there doesn't seem to be much info on the network bandwidth between RDS and EC2 either.
PostgreSQL RDS micro instance falls to $0.009 per hour when reserved, while MySQL falls to $0.016 per Hour.
If it isn't a typo, Postgres reserved instances are 1/5 of the on-demand price, which doesn't seem correct.
In PG 9.2 there were only two json functions[1], but 9.3 introduced more[2]
[1]http://www.postgresql.org/docs/9.2/static/functions-json.htm... [2]http://www.postgresql.org/docs/9.3/static/functions-json.htm...
The MySQL startups tended to say "We love MySQL. We've gotten in the habit of taking an hour or two of downtime in the middle of the night every week to run all of our schema migrations, and we've had to build our process around that, but one we had it in place, everything's been fine."
The PostgreSQL startups said "We love PostgreSQL. We run schema migrations in real-time during the middle of our workday, and we don't have any problems."
Over the years, Postgres has made up those shortcomings, so it retains its respect among database wonks and now other people can easily use it too, so you see a lot of people adopting it over the past few years.
But in overall usage numbers, I would be surprised if it were anywhere near MySQL. It takes a long time to overcome that kind of inertia.
There's still a bit to do on the auto-failover front, but that may end up being more of a third party undertaking. Postgres has failover facilities included, they just have to be driven by something external right now.
I would say that if you are just starting out and you already know MySQL and you are proving out your MVP, MySQL is still relevant.
Once you have a stable product and you need a better database, PostgresSQL is a good move up.
Strategically, because PostgreSQL is not just trying to be a free database checking off features. It's trying to be something better -- lots of innovation that is having a bigger impact on what developers and DBAs can do.
I recognize I'm used to MySQL but I was under the impression that because PostgreSQL has a similar syntax (SQL) it wouldn't take too long to pickup.
I've had better luck learning how to use the psql command/shell than mess with pgAdmin, at least in certain cases. To take your example of displaying tables, psql in and type: \dt
The rest is just a search away.
Postgres is very powerful and can do a lot. I think I just need a good tutorial and some time to get used to it.
And even though I love PostgreSQL (and was working with all major databases), I still think that the real winner is sqlite :)
I never really understood why you'd want to use a separate dbms if it couldn't do proper constraints, triggers, transactions and materialized views for you -- then it starts to feel like a lot of wasted effort.
So for many of the use-cases where MySQL might have been appropriate, we now have sqlite, mongodb, memcache/redis and a few others.
Personally I don't really see any reasonable use-cases for mongodb, just as I didn't see many reasonable use-cases for mysql -- not that you couldn't build stuff on top of it, just that it wasn't a very good idea.
5.6 had some pretty critical improvements, especially to the query planner.
Safety is annoying. Safer system usually generate more errors to prevent accidental mistakes. Extremely safe system prohibits even booting up the product if it's not been properly configured. It simply has much more annoying safety net. If you care the safety, this kind of annoying errors are good sign to you. But if you're newbie, this is just a big obstacle, which makes stiff learning cube.
Really. We still see many people who hate to use safety belt. Because it's annoying. And everybody did before benefits of safety belt were widely known and accepted.
Also, number of users says nothing about how well the product works. Usually, cheapest product takes biggest user-base. MySQL is cheapest to start due to lack of safety. Search this thread for the name "natural219". And see why he chose MySQL over PostgreSQL. I believe that's why most people started MySQL at first.
And surprisingly, there're so many people really don't care data safety. (maybe not that much surprise. we always see those people in TV…)
Plus Wordpress has a hard requirement for MySQL, and like it or not a huge number of projects still use it as a framework.
Every time I try to install PostgreSQL it fails. Every time I install MySQL it installs successfully with no problems. Actually, that's the extent of my experience with it, and I guess I'm fine dealing with a database that doesn't validate date formats strictly if I can use the damn database without hassle. I am totally fine using Postgres at a company or with another DB developer who knows how to set up databases properly, but if I am starting a new project, I am going to use MySQL, period.
If you're on a Mac and don't want a menubar icon (I decided this recently), `brew install postgres`, and then write yourself some functions to make starting and stopping easier:
https://github.com/jclem/dotfiles/blob/master/zsh/functions/... https://github.com/jclem/dotfiles/blob/master/zsh/functions/...
Postgres.app is nice when it works. When you install the latest version the psql tool it bundles and exposes in the menu assumes you have a db that matches your user name, which, of course, doesn't exist, so you can't connect to the Postgres :-)
It also doesn't work that great if you already have another version setup running on the default port.
`lunchy start postgres`
The most utterly infuriating part of a new Postgres install is getting authentication set up. I shouldn't have to expressly edit a freaking INI file for basic user access, damnit!
With the tentative upsert changes made in 9.4's commitfest, the initial user config problems are my last major problem with Postgres...
Also, why don't you use Heroku PostgreSQL app which is just one-click starting self-contained app?
If you're on FreeBSD/Linux desktop, how can you fail to install? Of course it doesn't work just right after install, and it needs manual initial configuration for security. But that shouldn't be hard to any Unix family server developer.
If you're on Windows desktop, why don't you run your own FreeBSD/Linux server VM instance for your own development?
If you're using Windows server… with MySQL… Hmm then I am sorry. I have no more idea.
Makes it very easy if you are Mac, Debian based shop --- or if you just use vagrant.
Currently this looks like: 1. Make sure we have the version of ruby we want (if not use rvm to install) 2. Make sure our db is installed (if not installed use brew (make sure we have brew) to install it) 3. Create our database and users on the new db server 3. Run rake db:setup
sudo apt-get install postgresql
Windows: Next, Next, ... Finish.Who could install this nonsense??