148 points · by subleq · 10y ago · 114 comments
I love psql and tab completion, it's magic, in fact it spoiled me, I know have a hard time to work on any other DB.
Not mention in the article, but I love how the postgres dev keep up with modern SQL. Again it makes it really hard to go back on a SQL 92 compliant system.
Now, the vacuum business, that's horrible. I've run into so many case where "vacuum full" just solve the weirdest problems. One very recently where I use postgres as a queue (because it was easy and works across platform/clouds) nad it became slow and horrible even though I had dropped a bunch of schemas. "vacuum full;" oh wow!
The replications story is ugly. You can make it work, but it's literally a craft and you end up having to babysit it.
One the author missed, lots of weird performance issue, got my answer from the uber post. The rule #1 of adding indices is to only use column that you really really need, because otherwise you're going to slow down your writes. Well, it turns out not on postgres, all indices for the table you're writing to are being updated! I'm pretty sure very few people were aware of that before uber told us.
The more I use the postgres front end (psql, SQL) the more I love it, but the backend (performance, replication) is starting to taste more and more sour.
With pgsql, I can get a clear concise explain and if I disagree with what's happening (because I know exactly what my hardware is capable of) I can tune any query to be decently performant.
With mysql, you get... I mean explain is ok, but I wouldn't put it above that. "EXPLAIN ANALYZE" is my gold standard forever and ever. I even liked it more than SQL Server's equivalent; which is also fantastic.
In my experience, MySQL had the worst query optimizer of the three. By A LOT. Basically, anything but a simple select could suck very unnecessarily. Even for simple selects, MySQL messes up.
I've fixed more than performance issue by changing SELECT * FROM users WHERE key1 = 0 OR key2 = 5 into two queries and concatenating the results.
I've seen this cause MySQL query authors to use various workarounds that end up impacting the query performance negatively.
commitfest: https://commitfest.postgresql.org/10/775/
email thread: https://www.postgresql.org/message-id/CABOikdMNy6yowA%2BwTGK...
SELECT int_col_1, int_col_2 FROM table1
SELECT varchar_1, varchar_2, int_col_2 FROM table2
In pgsql if the columns are the same type and number then we can use a union, otherwise the suggested alternative seems to be to just make 2 queries.
I have no issue with putting logic in your database. In many cases it's the ideal solution...but your example is something I've never even heard mentioned in 15 years much less advocated for or used as criticism for not being available.
Thereafter, the application didn't communicate with the database until it was time to save the record. The disconnected data set was small enough to store in shared session store, or even in a cookie (encrypted, naturally).
This architecture had a number of interesting knock-on effects. The entire state of a client's conversation with the server was tiny and entirely encapsulated by this disconnected data set, so you could record and play back each request to recreate a bug.
It didn't have to use multiple result sets from the stored procedure, but it did save a bunch of round trips.
I won't comment on anything else because I don't know the case, but you should never put user data in cookies. Even with encryption you are exposing it unnecessarily, not to mention you have to double check data integrity... Why? Cookies are not meant for this.
Beyond that, my other gripes about PGSQL are all surrounding the fact that it's simply not as polished or as widely used as SQL Server. I can't just drop PG in at some business site and expect the IT staff to be able to handle maintenance.
The Postgres GUI tools are extremely lackluster compared to the standard Microsoft SQL Server tools. Even the third party apps like Navicat are simply not as robust or as trustworthy as SQL Server Management Studio and the SQL Server Profiler. And there is literally nothing out that that compares with SQL Server Data Tools.
If the two commands have nothing to do with each other then yes that's usually the best option. That does open you up to understanding transaction semantics if you want to ensure both see exactly the same snapshot.
Another option is to use JSON as the great normalizer. Any row can be converted to JSON via row_to_json(...) or manually via the more low level functions. That allows you to "stack" multiple, distinct, JSON responses atop each other. Probably a bad idea 99% of the time to use something like that but it can come in handy that one time you want to jam things through in one query.
The only real argument I've ever seen against it has to do with "Separation of Concerns". Some people don't want any logic in their database. However, there's never any reason why.
(I bet you've UPDATEd multiple tables in one query though.)
Reasons are often given, sure...but they're almost never based on that persons experience because PGSQL users don't have this feature. So, they'll never know just how awesome it is to have real stored procedures like TSQL has.
Anyway, it's not about "jamming" things into one query. It's about composability and PGSQL is lacking it.
It's a bad idea for the same reason that having a function that returns back multiple values is a bad idea. Yes it's useful sometimes but on the whole it ends up being confusing. From a result set processing perspective it's also a pain in the ass as your app code is now tied to handling multiple results in a particular order, i.e., more/tighter coupling.
> (I bet you've UPDATEd multiple tables in one query though.)
You'd win that bet. There are a lot of ways to do this and it's a legit operation because you want N things to change at once (where N isn't in the same table).
> Reasons are often given, sure...but they're almost never based on that persons experience because PGSQL users don't have this feature. So, they'll never know just how awesome it is to have real stored procedures like TSQL has.
> Anyway, it's not about "jamming" things into one query. It's about composability and PGSQL is lacking it.
What's your goto "killer example" of what this could be used for?
I've used SQL Server quite a bit[1] and while it's not a terrible database, on the whole I don't like it. Rattling off at random: lack of MVCC (sure they have it now but it's not the default and still has warts), explicit locking that drives you nuts, defaulting to case insensitive string comparison, lack of built in functions. The inane licensing options don't help either.
I'd take Postgres over SQL Server any day of the week and twice on Sundays (i.e. side projects).
[1]: Officer I swear! It was already like that when I got there!
The Django project fixed it by adding canonical links to all the docs, see for example view-source:https://docs.djangoproject.com/en/1.9/ref/models/querysets/ (Has a <link rel="canonical" href="https://docs.djangoproject.com/en/1.10/ref/models/querysets/...)
The postgres project really needs to do that. It's a mess.
From skimming through, I'd say the vast majority. Not sure about the PDF doc link issues as I only use the online HTML Docs but the overall generation of the docs is still a black art.
But my experience is very limited, so take that with a grain of salt.
Reviewing and pulling things in is always hard, though. In other software I highly recommend always breaking up big things into smaller changes if possible, but I don't know if that works well for the conservative release cycles for DBs.
Though maybe the conservative release cycle is what's wrong? Having to do a refactor to implement a feature doesn't mean that you need to do both at once.
grant usage on *.* to 'bob'@'localhost'
identified by 'itsasecret';
Meanwhile, PostgreSQL had the extremely straightforward "createuser" command line tool, and the "create user" SQL statement. (MySQL got "create user" and "alter user" around 2006 or so.)Having to edit pg_hba.conf to allow network connections was always an annoyance for me, but at least the error message you get if it's set up wrong tells you to edit that file, which is also very straightforward and contains documentation out of the box.
Not allowing external access by default is arguably a security practice, though I always thought distro maintainers ought to have erred on the side of usability by enabling localhost access by default.
Unfortunately, I'm pretty new to postgres and can't write it myself.
https://www.youtube.com/watch?v=knUitQQnpJo
It isn't quite what you ask for, but should be enough to get you high-level overview of major systems and contains solid practical advices (on vacuuming, mvcc, replication, backups, etc…), so you know what to google for deeper understanding.
If anyone here knows of a good source, I'd love to see it :D (If you use the word "just" or link me the docs, you're dead to me).
https://www.postgresql.org/docs/current/static/different-rep...
It describes the various methods that are available, it lists implementations of each, it explains the tradeoffs involved, and so on. Table 25-1 summarizes the information.
Regardless of the database system being used, replication is just inherently complex. There isn't really a one-size-fits-all solution. The method to use depends on the requirements and context of a given implementation.
It starts with a comparison of the different ways available for replication.
For example, if you run with streaming replication — the recommended approach for most setups — then you can decide to enable WAL logs or not. If you only want replication, and not point-in-time recovery, then just running with WAL-less streaming replication is extremely simple and straightforward.
Why do people do this?
If I then put them on the internet, I may not bother editing them to make the more "internet friendly".
Instead, you press "Right" or "PgDn" or what have you. So I would expect the converse button ("Left" or "PgUp") to go back a slide as well (which it presumably does).
That leaves the browser's Back button to go back to the previous web page.
Everybody's happy!
Why approach 10+ slides as "a single page"?
If you consider them as 10 web pages, the back button makes sense to go back one page. Same for the left button, given the "presentation" use case.
And if they were actually designed as webpages, with html links taking you to slide2.html, slide3.html etc., that's exactly what you would get.
So if anything, whether this is a SPA or not, this is more in tune with how the internet works, and how it was designed to work.
This has worked in 99.9999% of presentations uploaded on the internet and posted on HN.
It's also very intuitive to try, since this is how it is in any presentation desktop app too.
"Time immemorial"? Damn, I remember pretty clearly what life was like before Web 2.0, and I'm still in my 20s. The first time I encountered one of these presentations I was confused as hell, at least this one has the decency to put arrows to click in the bottom right corner, a lot of presentations don't.
Liked the animations too. Not too much, but looks good.
Pollutes browser history(or if you click too fast, doesn't even have any), not convenient to browse at your own pace, no way to jump to a specific slide(visually)
The formatting is really good too and would probably work great as an article format but you're stuck reading tidbits, going back and forth.
In what way browser history, usually full of tons of random items and webpages one has opened, should not be polluted? It's just a log, not some kind of organised curated list of webpages.
>not convenient to browse at your own pace
How so? I can click left/right and go wherever I want at whatever pace I like.
>no way to jump to a specific slide(visually)
That, I give you.
It's the way ANY slideshow works, on desktop and online form. And it's a trivial thing to try, even when not told to. Not to mention by now there have been around 1000 such slideshows posted on HN.
It's amazing that in 2016 people still don't fall back gracefully in the absence of JavaScript and/or CSS.
But this presentation is just a bunch of text with navigation. This is what the web was written for, and it should work no matter whether you have CSS or JavaScript on, and it should use progressive enhancement to add on the useful features. That means using hyperlinks for navigation and CSS that doesn't hide all the content until your JS loads (which seems to be the problem with Chrome. The page actually is readable in Lynx).
Nothing amazing about it. At this point those are given prerequisites.
It's like websites are not catering for a fallback for lack of internet access or electricity.
It seems that new paradigms like R and RAM-only key values system are just simpler, faster and cheaper in programmer time. Loading everything in RAM and do a search seems like a huge saving of time and just works for most cases. Usually if you have more complex needs, you need to adapt your solution, and databases don't seem like a silver bullet.
Database queries seem like a solution to the problem of storing data on disk when RAM was too expensive. So today it's still used as some sort of standard, but when you can have 16GB of ram, I think you better teach yourself what sort of algorithm and data structures a database use to be faster, use the ones you like and need and solve your problem case by case.
The example of how reddit store its data is pretty demonstrative that ultimately, you should not let a database system do all the work. Databases are just a file format to me, but the way it tries to work for you at a lower level will respond to basic cases, but when you increase complexity it's not relevant anymore.
Especially today when you have big data and machine learning, everyone should just learn to understand data manipulation. Not saying to teach yourself C all over again, but having a decent idea of the math of what indexing is really about. Forcing yourself to use a database because the company always used it isn't appealing to me.
It's like one of those things when a programmer had an idea which is based on a constraint, everyone starts using it, several products are made, but nobody really remember the original idea of the inventor of that paradigm.
"Any sufficiently complicated NoSQL program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of a decent RDMS."
Or maybe: "Those who do not learn history are doomed to repeat it"
The use a formal, mathematical abstraction (relational algebra), even if somewhat crapily implemented by particular RDBMS, to facilitate saving data, relationships between data, and queries, while at the same time assuring certain properties (e.g. ACID) and doing so in a platform/programming language neutral format and with a consistent and industry standard query interface.
NoSQLs, key-stores and the like are not newer developments -- they predate databases. They were found to be a bad fit for what we wanted in enterprise use, and RDBS caught on.
For uses with huge data (Google and such scale) a denormalised approach might be more practical for performance reasons, in which case developers and ad-hoc programs get to re-implement all the functionality and assurances of a RDBMS in an ad-hoc way on top of rawer stores. (And all this could be alleviated with a properly optimised RDBMS for such purposes the still respects relational algebra).
In a conventional enterprise setting on the other hand, a DB trumps NoSQL etc solutions any day of the week.
>Database queries seem like a solution to the problem of storing data on disk when RAM was too expensive. So today it's still used as some sort of standard, but when you can have 16GB of ram, I think you better teach yourself what sort of algorithm and data structures a database use to be faster, use the ones you like and need and solve your problem case by case.
The whole idea is to free the data from being tied to a particular language, data structures and algorithms.
Back in 2000-2007 it was all about XML, and how we should store data in XML format and get them back with XQUERY, XPATH and the like. A lot of people bought into the hype and the resulting products. Then it was about JSON -- and we now have JSON stores. In 10 years, it will be something else, again ad-hoc.
Meanwhile SQL has worked for the past 3+ decades, and is based on a solid mathematical abstraction (relational algebra).
>It's like one of those things when a programmer had an idea which is based on a constraint, everyone starts using it, several products are made, but nobody really remember the original idea of the inventor of that paradigm.
You'd be surprised. Or rather you're exactly right -- few "really remember the original idea of the inventor of that paradigm", and that's why we're moving in circles with ad-hoc technologies re-implemented 30+ years after they were discarded. Or why people jumped enthusiastically to Mongo to return crying back to PostgreSQL.
Read a little around here for example:
http://www.dbdebunk.com/2015/07/the-sql-and-nosql-effects-wi...
http://www.allanalytics.com/author.asp?section_id=2386&doc_i...
http://www.dbdebunk.com/2015/11/moving-in-circles-sql-for-no...
Of course, SQL has a nice efficiently-implementable algebra of set comprehensions, which may or may not be interesting for your particular use-case.
It's not the tables that make SQL what it is, it's the relations.
Heck, it could even not have any types at all (a la dyamic languages or Sqlite), and relational algebra as an abstraction would still hold.
For a data warehouse yes people are still using RDBMS like Teradata.
But in enterprise environments most are now ingesting this data into Hadoop based data lakes and using NoSQL systems to drive the core analytics.
Also, RDBMS do constraint enforcement for you and that's absolutely critical when you work with any sufficiently big database (I work on a 100GB DB with a team of 6 people, changing here and there and I can't tell you how crucial the constraints are to maintain the data quality in face of bugs, misjudgment, etc.). And no, it's not for lack of testing. When you work on millions of super complex records, you always miss some corner cases (unless you're NASA and have a huge budget to test thoroughly)