Postgres Demystified
speakerdeck.com
speakerdeck.com
(Hey Craig! ;))
- url - If all schemes are allowed, this is almost equivalent to "does it include :// after the first word". I'm not sure why it should be included.
- phone - Around the world this is equivalent to: does it contain digits. And maybe also + # and star. And maybe also letters for internal voip phones. And....
- zip - Every country has its own. There is no common format. It can have letters, numbers, symbols, ... anything.
- email - This actually could work if it allowed all possible formats.
If done right, I can see those being useful. I agree that it can be overdone, though.
For example, the boolean type in PostgreSQL will accept TRUE, 'true', 't', '1', 'on', 'y' and 'yes' (case insensitive) for truthful values and the equivalents for false values. It's hard to state how much better this is than Oracle, to take my work environment as an example.
My point is that I imagine that when the PostgreSQL team get around to these types, they will address them with the same care and forethought as they have for everything else. I trust them because their feature plans are not based on maximising shininess.
But does it support 'affirmative', 'correct', 'aye' (http://thedailywtf.com/Articles/Are-You-Sure.aspx) or 'YOUBET', 'YEP', 'NOWay', 'YEAH', 'NOPE', 'Maybe' (http://thedailywtf.com/Articles/The-Object-Test,-a-New-PI,-a...) ?
Note the mapping of 'Maybe' to a boolean through '__TIME__[7]&1'!
Also, I quote: "It's Postgres or Postgres-Que-Ell, not Postgre-Es-Que-Ell". And then a slide shows "PostgresQL" while http://postgresql.org shows "PostgreSQL". That pronounciation makes no sense to me if the slide is correct.
[1]: http://www.postgresql.org/docs/9.2/static/datatype-datetime....
(Yes I know the perfect dbadmin can make the perfect indexes. But I expect the database to figure it out itself and rarely be wrong.)
Note that you don't actually need strong AI. Look at what MongoDB does http://docs.mongodb.org/manual/core/read-operations/#query-o...
Essentially it is dumb in that it tries multiple query plans concurrently, figuring out which was most efficient and using that in the future, monitoring its expected performance and trying all candidates again when it deviates.
With modern systems having such a surplus or CPU, RAM and storage a dumb system could try multiple indexing strategies, and work out which worked best.
This is the most fundamental mutation operation on dictionary, in all programming languages, denoted by:
map[key] = value
It's truly mystifying how something so basic could be missing from something that is supposed to be a better system for storing data.
It also doesn't even fully implement the SQL standards, missing for example the MERGE statement in SQL 2003 standard, which is also utterly baffling.
Note that all databases have catastrophic issues like these, it's just ridiculous how they can be in this terrible state.
It would be like a commercial RDBMS lacking boolean and serial types, necessitating reams and reams of repetitive, error-prone boilerplate constraints and insert/update triggers.
https://gist.github.com/paul/855efdecaaa2ec4deec7
You can also use it to perform a "find or insert" as a single atomic action:
That's really simplistic but I don't know the use case.
If we have one transaction running delete and then insert concurrently with one transaction doing a normal update then the update will find zero rows to update if it is ran after the delete+insert. The inserted row will be invisible to the update while the old row will be locked. This means the update will wait until the other transaction is committed and then find neither the old nor the new row.
A correct REPLACE implementation would make sure the UPDATE would UPDATE the replaced row.
The above is assuming READ COMMITTED isolation level.
There is no direct substitute in PostgreSQL, but there are case by case alternatives AND as far as any use cases I can dream up right now, they have better (As in they are easier to debug, easier to observe and easier to tune - MySQL necessarily hides the update operation from you) semantics.
However MySQL doesn't. I've just tried it, and MySQL blocks the UPDATE until the first transaction (DELETE, INSERT) is finished (like PostgreSQL), but after the commit, the UPDATE statement updates the newly inserted row.
It seems MySQL firstly searches the table for the row and then attempts to acquire a lock on it (thus waits for the DELETE, INSERT to finish, as it's locked the row being DELETEd), and, after the lock has been acquired, searches the table again for rows matching the query in order to perform it.
Did you run MySQL in READ COMMITTED or REPEATABLE READ? And would it matter?
PostgreSQL is one of the few databases that supports SQL and can actually be less painful to scale than MySQL. Also, the recent versions have enormous performance boost that can silence the SQL critics, IMO.
If you are interested in testing out PostgreSQL for your project, you might want to develop on the WAPP stack and give it a shot:
Disclaimer:
I was a mongoDB developer too and I loved it so much. I loved the fact that I could skip running db migrations on my rails app and I can focus on just coding, instead of worrying about scaling. But, it was a terrible trade off. First of all, you can't use NoSQL for everything. It was a very painful lesson that I learned the wrong way. 99% of the time, you want to use SQL, because most use cases can be executed perfectly with SQL db's. Next, some db's have a terrible architecture and design decisions under the hood, mainly to improve their benchmarks (seriously!). For example, turning off write-safe by default... :cough: :cough: Last but not the least, SQL for the wrong use case complicates things and ends up adding redundancy into the database (like storing User details inside multiple collections, un-avoidable, especially when you are against embedding documents). The worst trade-off using a NoSQL database is the analytics part - "Hey db, show me the list of users who are from the United States and who have subscribed to Plan X and who are the highest paying customers and who love chocolate pie" SQL - "Here you go." NoSQL - "Sorry sir, not possible. Possible, but possibly a nightmare."
If you want to build a 'scalable' app for your next big thing and don't want the scaling hassles of MySQL, which actually scales extremely well already[3], you can use PostgreSQL.
Cheers
[1]Scaling is hard. Don't let anyone else tell you otherwise!
[2] http://blog.engineering.kiip.me/post/20988881092/a-year-with...
[3] http://www.quora.com/Quora-Infrastructure/Why-does-Quora-use...
Can you expand on this? All that I'm aware of, in the scaling department, is their basic replication introduced recently.
Also, here's some more inks to research about: http://stackoverflow.com/search?tab=votes&q=postgresql%2...
Again, I don't say using PostgreSQL is a magical solution for your next app. Just that in my opinion it is better than MySQL.
[1]http://www.enterprisedb.com/products-services-training/produ...
Meanwhile, MySQL have had multi-master replication "forever" because they took the easy way out of "simply" logging statements, and streaming those to slaves, and add a mechanism for adding offsets and step sizes to sequences. It's a bit of a hack, and vulnerable (if you do clashing updates, replication will fail), but in real life usage it gave MySQL a massive advantage for some types of scenarios for a long time (e.g. back in 2006 I ran a cluster of 16 MySQL servers spread over two sites; configuration was trivial while doing the same with Postgres at the time was a massive PITA).
It's a philosophical difference that means that while I'd be more comfortable about trusting our payroll data to Postgres, for a web app where major scalability is a concern, I'd be prepared to consider MySQL in situations where I'd consider Postgres a no-go because of the hassle.
Postgres feels like it has a more theoretically sound foundation, and is catching up feature-wise, though.
A few more iterations on the replication support, and extensions like https://code.google.com/p/plv8js/wiki/PLV8 (run Javascript in Postgres via V8, which also instantly gives nice JSON support to rival many of the no-sql solutions) and it's eating it's way into both the no-sql space and the space held by MySQL.
Sorry, but citation needed. Most of the (relevant) stack overflow results are pointing to articles citing 4.1 and earlier MySQL versions, or pure FUD opinion pieces.
MySQL and PostgreSQL are within the same order of magnitude (depending on workload and how much time you're willing to spend optimizing queries) for a single server, so to say that PostgreSQL is better requires some backing up with actual numbers or techniques.
http://mxcl.github.com/homebrew/
its a package manager, but more than that it has scripts to handle the mac's strange edge cases.
so many packages wasted so many hours of my life before homebrew took over.
Also, if you're not aware of it you'll probably be interested in Fabian Pascal's Database Debunking's site [1].
http://labs.spotify.com/tag/postgresql/
And MySQL Cluster is a cohesive, built-in, well supported version for scaling MySQL. PostgreSQL has no equivalent.
But the PostgreSQL team are doing their usual slow, stepwise refinement approach to implementing these features from the primitives and moving up. I expect that in a few versions they'll be at sufficient feature parity with MySQL on this front that anyone who cares enough is the sort of person who decides between Oracle RAC and Teradata.
While that will be good and I look forward to it, I will miss seeing you turn up in these threads like a bad penny.
My position is that there a lot of different products out there that cater for different needs and there is no "one size fits all" solution. I can scale Cassandra out to a hundred nodes in minutes on EC2 with no configuration changes. I also have queries in MongoDB that are literally 50x faster than on a SQL database.
I think that for any case where you might be building a new system based on a relational backend, it's basically true (modulo local constraints like "we're an Oracle shop"). The chances that you will need to run a website that needs 100 Cassandra servers any time soon is ... well it's unlikely.
PostgreSQL is a stable, proven workhorse. That's why I like it. My point of view is that you should start with high safety and features and relax those constraints as circumstances demand.
And I comment on lots of different things but have a stronger interests in Apple and Database. So sue me I guess.
"Later came Postgres 9 and with it the excellent streaming replication and hot standby functionality. One of the most important database clusters at Spotify, the cluster that stores user credentials (for login), is a Postgres 9 cluster."
Hum, your link kind of defeat your point. That or I did not understand the point you were trying to make.
SQL databases start off difficult but pay dividends on the back end. NoSQL databases start of easy but begin to extract their costs later.
Similarly, a well-normalised database is tuned to write-and-store performance, but the cost of joins can crush you at query time.
What's usually missing from discussions like these is highlighting the difference between OLTP and OLAP.
You favour one or the other. TANSTAAFL.
Funny - I feel it is the other way around : NoSQL yield scalability to the high end but I find SQL incredibly more convenient because the database does most of the work for me... We all have our bias and mine is thinking in a relational way.
If you don't, apparently, the NoSQL databases will work fine, but so would SQL databases that you tell "here's a binary blob". AFAIK, neither would support querying those binary blobs, though.
You can use (and should use) a NoSQL database when you have data that benefits from being non-relational and storing it in a relational db will actually cause you trouble.
For example, let's assume this function:
f(x){
return someHeavyComputationThatRequiresALotOfTime(x);
}
Let's say your specific use case requires that for well-defined inputs of the function f(x), you want the outputs immediately and processing this function for each request will cost you a LOT of resources (think CPU, RAM, etc.). So, in such cases, if and only if it makes business sense, you can store the inputs ranging from 0 to x and corresponding computed outputs in a NoSQL database and access it when needed, instead of actually computing it everytime.so, your data would look something like:
{"input": 0, "output": 143532.3434}
{"input": 1, "output": 22342424.0934}
{"input": 2, "output": 33242423.2423}
{"input": 3, "output": 346324634.4546}
{"input": 4, "output": 321144563.2457}
{"input": 5, "output": 536573462.5646}
and so on..Actually my example is bad because you can store the same thing on SQL db's too, but unless there is a very specific advantage[1] that these NoSQL db's have (multitudes faster read speed, lower memory consumption, etc.) you want to stay away from them.
If you are evaluating a good NoSQL db for your project, then I suggest you check out Voldemort DB[2] by LinkedIn, which is actually pretty good and has some positive feedback from people running it at scale[3] without much of the marketing layer that Mongo has.
[1] http://www.slideshare.net/nurkiewicz/projekt-voldemort-when-...
[2] http://www.project-voldemort.com/voldemort/
[3] http://engineering.linkedin.com/voldemort/voldemort-collecti...
SQLite might be the vim of databases.
Actually, BDB hash files.
(I'll just see myself out...)
[1] http://stackoverflow.com/questions/12593080/heroku-hosted-po...
- http://www.youtube.com/watch?v=3yhfW1BDOSQ (Christophe Pettus "PostgreSQL when it's not your job.")
Make sure to check the "Postgres Guide" [3] which is a recent addition and is excellent to get you started quickly.
The quick intro by Packt Publishing [4] looks useful and concise as well, but is not as good as the Postgres Guide.
Since you're familiar with the RDBMS concepts I would suggest you take a look at the nice "PostgreSQL 9 Admin Cookbook"[5] which has a solid collection of recipes that you can use to learn the specifics of the DB and a bunch of nice features.
[1] http://www.postgresql.org/docs/9.2/static/tutorial.html
[2] http://wiki.postgresql.org/wiki/Microsoft_SQL_Server_to_Post...
[3] http://www.postgresguide.com/
[4] http://www.packtpub.com/article/introduction-to-postgresql-9
[5] http://www.amazon.com/dp/1849510288/
edit: fixed the link to postgres guide.