News for hackers. Stuff that matters.
Re:PostgreSQL 11 Released by enraged_camel on Thursday October 18, 2018 @09:52AM (#18248286)
Serious question: when you need a relational database, are there any technical reasons why you would use anything other than Postgres these days?
Re:PostgreSQL 11 Released by mrcarruthers on Thursday October 18, 2018 @10:09AM (#18248426)
One thing that Postgres does not do well is row churn. If you have a table that have rows that are constantly added/deleted/updated, Postgres tends to bloat pretty quickly because of the way they handle updates. Say what you will about using a relational db for that kind of data, but if you need to, Postgres isn't a great choice.
Re:PostgreSQL 11 Released by pgaddict on Thursday October 18, 2018 @10:32AM (#18248600)
That really depends.

You're right UPDATEs may be an issue (because we handle them essentially as DELETE+INSERT). Generally speaking, row churn in the table alone is not an major issue - it's easy to clean up by vacuum, and it will be reused for new data. And you can limit the amount of bloat by tweaking the autovacuum parameters.

What's more painful is bloated indexes (e.g. due to UPDATEs that modify indexed columns), because that's much harder / more expensive to get rid of.

The thing is - this is part of the MVCC design, and it has some significant advantages too. It's not like the alternative approaches have no downsides.

Re:PostgreSQL 11 Released by emddudley on Thursday October 18, 2018 @04:35PM (#18251880)
In some applications, at least, vacuuming is not sufficient to deal with row churn.

I use PostgreSQL in an embedded device. There is a high insertion rate, and eventually when the disk starts to get full I need to get rid of old rows.

Using plain DELETE and VACUUM does not work. The deletes aren't fast enough to keep up with the inserts, and vacuuming reduces performance to the point that I have to drop data that is waiting to be inserted. This is on a high performance SSD and I've tuned postgresql.conf. (Bigger/better hardware is not possible in my application).

Instead, I think partitions with DROP PARTITION are the only way to handle high volume row churn. Dropping a partition is practically instant and incurs no vacuum penalty.

Re:PostgreSQL 11 Released by pgaddict on Thursday October 18, 2018 @07:21PM (#18253182)
Yeah, DROP PARTITION is definitely going to be much more efficient than DELETE + cleanup. No doubt about that.

Not sure what postgresql.conf tuning you've tried, but in general we recommend making autovacuum more frequent, but performing the cleanup in smaller chunks. Also, batching inserts usually helps a lot. But maybe you've already tried all that. There's definitely a limit - a balance between ingestion and cleanup.

Re:PostgreSQL 11 Released by panarky on Thursday October 18, 2018 @07:32PM (#18253229)
> eventually when the disk starts to get full

Don't wait until the disk gets full.

Autovacuum works great for most small to moderate sized databases. And it works great for larger databases with a few tweaks.

Re:PostgreSQL 11 Released by pella on Thursday October 18, 2018 @10:41AM (#18248672)
Re:PostgreSQL 11 Released by twic on Thursday October 18, 2018 @02:42PM (#18250975)
That's very interesting.

At the moment, PostgreSQL keeps all versions of all tuples in its heap files. Inserts, updates, and deletes all result in addition of new tuples to the heap, and the engine keeps track of which transactions can see which tuples. The vacuum process deletes tuples which are no longer needed, but in the meantime, there is bloat.

zheap would keep only the latest version of each tuple in its heap files. When a tuple got updated or deleted, the engine would move the old version into separate storage, the "undo" log. A vacuum process would need to clean up the undo log, but the heap would remain unbloated.

This is obviously very practical. But it's a shame that it introduces an asymmetry, where some transactions will be reading tuples from the heap, and some will need to root around in the undo log.

I note that this is the approach that Oracle has always used - as explained in this fine article by the same chap who wrote the blog post about zheap above:

https://www.enterprisedb.com/blog/databases-different-approa...

Re:PostgreSQL 11 Released by Fergi on Thursday October 18, 2018 @11:59AM (#18249411)
We are about to release an open-source extension for PostgreSQL that will help with the bloat problem you mentioned here, at least for continuous updates like high volume aggregation (see: pipelinedb.com). PipelineDB will be refactored as a standard PostgreSQL extension this month. Continuous aggregation can help with the bloat problem for use cases where you only need aggregated / summary data, like realtime reporting & monitoring.
Re:PostgreSQL 11 Released by panarky on Thursday October 18, 2018 @10:19AM (#18248491)
What databases do you recommend to handle frequent updates?

How does their design differ?

What are the tradeoffs to consider?

Re:PostgreSQL 11 Released by zzzcpan on Thursday October 18, 2018 @12:04PM (#18249459)
LSM-tree, fractal tree, B-epsilon tree or similar ideas based stuff for on disk storage is what solves the problem. Pretty much no tradeoffs compared to classic approaches, these things are just better.
Re:PostgreSQL 11 Released by dhd415 on Thursday October 18, 2018 @01:07PM (#18250080)
LSM trees are good for frequent updates on recent data. Frequent updates of old data are much worse on LSM trees since they trigger merges on the oldest (and typically largest) levels of the tree.

Some storage engines allow for in-place updates of records if the fields are fixed-length or if the updated variable-length value fits in the existing space. I've used some of those (e.g., MS SQL Server) to good effect in high-update scenarios.

Re:PostgreSQL 11 Released by zzzcpan on Thursday October 18, 2018 @03:06PM (#18251182)
Depends on your implementation of course, but updates shouldn't be triggering merges on the largest levels. They should be accumulated until there is enough of them to merge or there is some other reason to merge things, like scrabbing. Either way, it's still more efficient.
Re:PostgreSQL 11 Released by jeltz on Thursday October 18, 2018 @10:23AM (#18248538)
Only in some cases of churn plus there are plenty of workarounds where you sacrifice some performance and/or usability to avoid the bloat so I would still recommend PostgreSQL since few databases consist only, or almost only, of the bad cases for bloat.

I used to work in online gambling where we had plenty of row churn and not much bloat at all without having to use any of the workarounds.

Re:PostgreSQL 11 Released by jeltz on Thursday October 18, 2018 @10:00AM (#18248350)
I can only think of three cases:

1) You need an embedded relational database with a small foot print. Here PostgreSQL cannot compete with SQLite.

2) You have an application which does not support PostgreSQL.

3) You have petabytes worth of data. Here you want to look into something like Greenplum, a PostgreSQL fork.

Re:PostgreSQL 11 Released by truth_seeker on Thursday October 18, 2018 @01:11PM (#18250120)
PG works okay with Peta Bytes of data. Various types of indexes, Table partitioning and parallel query computation can help.

Citus and other community extensions can help if you want to go distributed and fault tolerant

Re:PostgreSQL 11 Released by jacques_chester on Thursday October 18, 2018 @11:41PM (#18254095)
Worth noting that the Greenplum team are working to converge back to mainline.
Re:PostgreSQL 11 Released by benmmurphy on Thursday October 18, 2018 @11:44AM (#18249279)
some people have problems with they way MVCC is implemented. like Mysql using rollback segments so it doesn't have issues with vacuuming [tho, there is tradeoffs with doing it that way as well]. the vacuuming issues are really scary and basically involve losing write access to the whole database. have a look at stuff like this: https://www.joyent.com/blog/manta-postmortem-7-27-2015 . i believe postgres have made a bunch of changes to reduce the risk of vacuums blowing things up.

this MVCC implementation couple with the way indexing works also causes write amplification. the indices have pointers to the physical place where the row is stored (some other databases might instead record the primary key and do a lookup on the primary key to get the record). so if you update a row and it causes it to move to a different physical page (you need to keep the original row for MVCC so there needs to be space for the new row in the current page) then you need to update all the indices as well. PG has some optimisation around trying to write the update to the same physical page to reduce the number of writes.

Re:PostgreSQL 11 Released by drej on Thursday October 18, 2018 @09:57AM (#18248335)
Horizontal scaling and/or alternative storage systems (I know, pg can theoretically do both, but...).

That and perhaps global consistency aka "sort of but not really defeating the CAP theorem using atomic clocks and all that" in Spanner.

Re:PostgreSQL 11 Released by pgaddict on Thursday October 18, 2018 @11:12AM (#18248962)
Yeah, we're not particularly good at those out of the box.

1) Horizontal scaling: In some cases it's doable using streaming replication, but it depends if you need to scale reads or writes. Or if you need distributed queries. There are quite a few forks and/or projects built on PostgreSQL that address different use cases (CitusDB, Greenplum, Postgres-XL, BDR, ...). And the features slowly trickle back.

One reason why it's like this is extensibility/flexibility - the project is unlike to hard-code one particular approach to horizontal scaling, because that would not work for the other use cases. So we need something that does not have that effect, which takes longer. It's a bit annoying, of course.

2) Storage systems: We don't really have a way to do that now - there are extensions using FDW to do that, but I'd say that's really a misuse of the FDW interface, and it has plenty of annoying limitations (backups, MVCC, ...). But it's something we're currently working on so there's hope for PG12+: https://commitfest.postgresql.org/20/1283/

Re:PostgreSQL 11 Released by truth_seeker on Thursday October 18, 2018 @01:19PM (#18250202)
Citus extension can help you achieve horizontal scaling.

Here are some of the success stories. https://www.citusdata.com/customers/

Re:PostgreSQL 11 Released by GlennS on Friday October 19, 2018 @03:07AM (#18254712)
MS SQL Server still has a few things up its sleeve which can be valuable in specific cases:

1. Incrementally updated materialized views (in MS SQL Server, these are called 'indexed views').

2. SQL Server Management Studio is better than anything I've seen elsewhere.

3. Reporting and analytics (SSRS/SSAS) built in. These are actually pretty good, but not the approach I would recommend.

4. Very solid clustering (I haven't used PostgreSQL's clustering, so this point might be out of date).

The license fees are steep (not as steep as Oracle's...) though, so you've got to really want those features.

I think report builders tools miss the sweet spot. Instead, build the specific reports that your business needs. Or, do a regular export to flat files (tab delimited causes fewest problems) and let people build what they need in Excel/R/whatever. Or both.

In practice, I try SQLite first, and fall back to Postgres if I need concurrent writes.

Re:PostgreSQL 11 Released by majewsky on Thursday October 18, 2018 @09:56AM (#18248328)
Because the app you want to run does not support it.

OpenStack used to support both MySQL and Postgres, but they removed the Postgres support, which is a decision that completely baffles me.

Re:PostgreSQL 11 Released by grouseway on Thursday October 18, 2018 @12:51PM (#18249922)
I'm a fairly casual PG user but I have these issues:

Lack of case and accent insensitive collations is inexcusable at this point. Is there anyone that enjoys sprinkling every bit of SQL with upper() comparisons?

Non materialized CTEs. I like materialized CTEs sometimes and wish MSSQL had them as an option but I also need it to work the other way.

Native point-in-time recovery out of the box. This looks like it might be possible but the process doesn't fill me with a lot of confidence.

Better connection scaling.

Ability to load custom TS dictionaries in user space (for hosted postgres on google/aws/etc..)

Re:PostgreSQL 11 Released by nathan_long on Thursday October 18, 2018 @02:12PM (#18250669)
> Is there anyone that enjoys sprinkling every bit of SQL with upper() comparisons?

Does using a citext column not solve this?

Re:PostgreSQL 11 Released by Tostino on Thursday October 18, 2018 @01:20PM (#18250207)
Agree on PITR being something that seems less approachable than it really is.

Use a tool like pgbackrest, and everything just works really well.

Re:PostgreSQL 11 Released by collyw on Thursday October 18, 2018 @10:02AM (#18248364)
You have a sever with MySQL already.

We had Rackspace servers in the place I worked a couple of years ago and they didn't offer Postgress as far as I remember. (You could install and manage it on a virtual machine but then you had to do everything yourself, while they had managed MySQL servers available).

Also setting up master / slave replication seems easier with MySQL as I understand - I never tried with Postgress but did with MySQL.

Re:PostgreSQL 11 Released by jeltz on Thursday October 18, 2018 @10:31AM (#18248594)
Setting up master / slave replication with PostgreSQL used to be hard but that was fixed a few years ago.
Re:PostgreSQL 11 Released by sroussey on Thursday October 18, 2018 @10:30AM (#18248588)
I’ve found MySQL far better in replication arrangements, with postgresql wal being termpermental.
Re:PostgreSQL 11 Released by jeltz on Thursday October 18, 2018 @10:33AM (#18248612)
Temperamental in what way?
Re:PostgreSQL 11 Released by timc3 on Thursday October 18, 2018 @10:54AM (#18248801)
Multi-region replication like Cassandra? Sort of a question because the last time I really looked around the release of PostgreSQL 9 there wasn't a solution.
Re:PostgreSQL 11 Released by chucky_z on Thursday October 18, 2018 @02:55PM (#18251088)
Actually an interesting solution to this is using something like kafka-connect. Debezium specifically has libraries around pgsql -> pgsql replication using kafka + kafka-connect that work shockingly well. The lag is not much different than traditional replication but you can have a single primary that kafka-connect is pulling into kafka, and a gazillion replicas off that single stream.
Re:PostgreSQL 11 Released by tfehring on Thursday October 18, 2018 @12:04PM (#18249455)
One reason is the lack of native support for columnar storage (though an open source third-party extension exists: https://github.com/citusdata/cstore_fdw)

The need to manually update clustered indexes, and the fact that an exclusive lock is needed to do so, is also annoying.

Re:PostgreSQL 11 Released by captain_perl on Thursday October 18, 2018 @09:34PM (#18253721)
MySQL with Innodb is easier to manage in large replication clusters, doesn't require connection pooling, and doesn't have write amplification problems.

MySQL out of the box is more secure and easier to configure than Postgresql because of pg's public and the legacy config files.

It's also much easier to hire DBAs.

Re:PostgreSQL 11 Released by Thaxll on Thursday October 18, 2018 @12:17PM (#18249566)
Why would it be better than MySQL is you're already using MySQL for years and built knowledge with it and have no issues? Why would I change, why Postgres would be better?
Re:PostgreSQL 11 Released by astrodust on Thursday October 18, 2018 @12:24PM (#18249646)
The JSON/JSONB columns and the JSON navigator options are amazing. MySQL isn't even close yet, they have a JSON column that's basically opaque. Other column types like the INET, CIDR and MACADDR are often invaluable.

You can also index ARRAY columns, meaning if you need a "tags" feature it's ridiculously easy to implement, no need for additional tables.

There's also PostGIS, which has no MySQL analog, and makes doing actual real-world GIS work possible.

Re:PostgreSQL 11 Released by nobleach on Thursday October 18, 2018 @04:48PM (#18251972)
Having tried, and failed to use MySQL Spatial Extension (which some might argue is PostGIS' analog) and failing miserably at some pretty basic things, I agree totally. I'd take PostGIS over ESRI's SDE and Oracle Spatial as well.
Re:PostgreSQL 11 Released by nathan_long on Thursday October 18, 2018 @02:07PM (#18250624)
One "quality of life" thing - you can wrap changes to the schema in a transaction, so that a given set of changes is atomic. (Elixir's Ecto and Ruby's ActiveRecord both have migrations that do this by default.) As far as I know, that doesn't work in MySQL.

There's also neat stuff like exclusion constraints: http://nathanmlong.com/2016/01/protect-your-data-with-postgr...

And there's the ability to do all kinds of neat geospatial queries with PostGIS - eg "list all properties within X distance from the curvy coastline".

Re:PostgreSQL 11 Released by barrkel on Friday October 19, 2018 @04:34AM (#18255106)
Feature for feature, PG blows MySQL out of the water. PG gives you way more tools to use in your queries, indexes etc. to solve app problems.

The real knowledge gap would come into things like all the various tactics you need to learn to get MySQL to produce good plans for your queries. PG has a much smarter optimizer which is harder to control - if it does the wrong thing, it's harder to encourage it to do the right thing, and philosophically they don't support query hints. OTOH, worst case in PG is usually much better than worst case on MySQL.

Re:PostgreSQL 11 Released by twic on Thursday October 18, 2018 @02:28PM (#18250825)
If somebody else is paying for it, Oracle is still pretty good, and has some features that PostgreSQL doesn't.
Re:PostgreSQL 11 Released by Tepix on Thursday October 18, 2018 @11:01AM (#18248853)
SQLite fits the bill but of course fills a very different niche.
Re:PostgreSQL 11 Released by sroussey on Thursday October 18, 2018 @10:28AM (#18248578)
You might want clustered indexes.
Re:PostgreSQL 11 Released by knocte on Thursday October 18, 2018 @10:40AM (#18248669)
No, there aren't. In other words, I hope MSSQL dies in a dumpster fire.
Re:PostgreSQL 11 Released by paulie_a on Thursday October 18, 2018 @01:19PM (#18250200)
I agree, it should first beaten with a baseball bat.