News for hackers. Stuff that matters.
Re:PostgreSQL 16 Beta 1 by klysm on Thursday May 25, 2023 @09:53AM (#36070729)
Glad to see the move off of autoconf to meson.
Re:PostgreSQL 16 Beta 1 by itsthecourier on Thursday May 25, 2023 @10:05AM (#36070882)
COPY from files up to 300% faster

Load Balancing from client libs

Support for CPU acceleration using SIMD for both x86 and ARM architectures, including optimizations for processing ASCII and JSON strings

new pg_stat_io view that provides information on I/O statistics

Re:PostgreSQL 16 Beta 1 by craigkerstiens on Thursday May 25, 2023 @10:13AM (#36070975)
For being "boring and stable" technology, Postgres 16 includes 200 features, which is on par with each of prior years releases. If you're looking for the full set of features it's available here - https://www.postgresql.org/docs/16/release-16.html.

Personal favorites on the list include:

- load_balance_hosts, which is an improvement to libpq so you can load balance across multiple Postgres instances.

- Logical replication on standbys

- pg_stat_io which is a new view that shows IO details.

Re:PostgreSQL 16 Beta 1 by Fgehono on Thursday May 25, 2023 @10:53AM (#36071475)
Could you elaborate on the load balancing?

Is this a replacement for PG bouncer and similar?

Re:PostgreSQL 16 Beta 1 by dalyons on Thursday May 25, 2023 @11:12AM (#36071751)
IMO the biggest reason folks use pgbouncer is not for load balancing (which it can do, -ish) but instead for connection pooling. Postgres connections are expensive for the db server (one process per connection not one thread) so if you have say thousands of web application pods you need to use pgbouncer or similar as a proxy to multiplex those thousands of connections down onto a more manageable number (~200). So no, not really.
Re:PostgreSQL 16 Beta 1 by Nextgrid on Thursday May 25, 2023 @11:35AM (#36072093)
Out of curiosity, if the problem of connections being expensive is solvable by PGBouncer-style connection multiplexing, why doesn't Postgres just do that by itself?
Re:PostgreSQL 16 Beta 1 by dingledork69 on Thursday May 25, 2023 @11:56AM (#36072387)
Because pgbouncer's transaction-based pooling, which is what the previous poster was referring to, breaks a few postgres features. This is fine for most applications, but not all. See the table on https://www.pgbouncer.org/features.html
Re:PostgreSQL 16 Beta 1 by dalyons on Thursday May 25, 2023 @12:51PM (#36073063)
yeah good callout. I'd would be totally fine with a server mode, or connection option, that opts you into pooling but then disables the incompatible features. You choose pooled mode if you need it, and the tradeoffs are documented.
Re:PostgreSQL 16 Beta 1 by Tostino on Tuesday May 30, 2023 @11:34AM (#36126071)
I really wish there was a way to handle transaction pooling without losing session pooling features.

Essentially, a "please serialize everything (temp tables, SET GUC values, etc) from this session to disk and load it back when necessary".

Re:PostgreSQL 16 Beta 1 by dalyons on Thursday May 25, 2023 @11:58AM (#36072409)
I believe there has been talk and perhaps progress towards building it into PG, but i cant find the dev thread right now, and i dont know what the status of that is.

interestingly enough this is what Oracle does AFAIK. They are also process-per-conn & have an optional sidecar proxy thingy that you can run on your oracle host to do the pooling. I would rather it be built more tightly into the rdbms but thats not a terrible solution.

Re:PostgreSQL 16 Beta 1 by anarazel on Thursday May 25, 2023 @01:01PM (#36073192)
If it were easy to do well in-core, I think we'd do it immediately. Unfortunately the interesting pooling modes in pgbouncer also break a few things - which would likely not be acceptable in core postgres. Avoiding such breakage requires non-trivial architectural adjustments.

Historically connection state and "process state" have been tightly coupled, for good server-side pooling they have to be divorced. While good pooling is doable with the current process model (passing the client file descriptor between processes using SCM_RIGHTS), it's much harder with processes than with threads - this is one of the reasons I think we will eventually need to migrate to threads.

Eventually I want to get to a point where we have a limited number of "query execution workers" that handle query execution, utilized by a much larger number of client connections (which do not have dedicated threads each). Obviously it's a long way to go to that. Ah, the fun working on an complicated application with a ~35 year history.

There also are use cases for pgbouncer that cannot be addressed on the server-side - one important one is to run pgbouncer on "application servers", to reduce the TCP+TLS connection establishment overhead and to share connections between application processes / threads. That can yield very substantial performance gains - completely independent of server side pooling support.

Re:PostgreSQL 16 Beta 1 by danmcs on Thursday May 25, 2023 @01:22PM (#36073485)
There were changes made to idle sessions in postgres 14.0 that were supposed to reduce the resource usage of open but idle connections.

Crunchydata mentioned it on their blog a while back (https://www.crunchydata.com/blog/five-tips-for-a-healthier-p...) and the pg 14 release notes mention a few changes to idle sessions (https://www.postgresql.org/docs/release/14.0/)

I don't know if they were sufficient that pgbouncer is no longer necessary, haven't had a need to try it.

Re:PostgreSQL 16 Beta 1 by jake_morrison on Thursday May 25, 2023 @02:19PM (#36074146)
Postgres forks an OS process for each connection, which is relatively heavy weight. Oracle has a similar architecture to Postgres, and they solved it with a "multi-threaded listener". MySQL, in contrast, uses threads, which makes connections lighter weight.

It's fundamentally a question of how the connection listener communicates with the rest of the database, e.g., using shared memory or some other IPC mechanism, work queues, etc. Having too many connections results in problems with concurrent access and lock contention independent of how heavyweight the actual listening process is.

Re:PostgreSQL 16 Beta 1 by tracker1 on Thursday May 25, 2023 @01:41PM (#36073704)
That's pretty much been my take as well. Been looking at CockroachLabs (CockroachDB hosted cloud), and been kind of hard to get any detail if pgbouncer is beneficial for this, since I'm planning to connect via node_compat via Cloudflare Workers, and have kind of decided to punt the issue and connect directly for now in development, and closer to prod release do some tests with/without pgbouncer at each cloud location for the larger prod cluster instances for release.

Not the same service(s) as PG even if it's the same protocol, so I know it's really beneficial for connection queueing WRT my scenario for PG, but no idea on the CDB side.

Re:PostgreSQL 16 Beta 1 by ttfkam on Friday May 26, 2023 @10:28AM (#36084622)
Postgres 14 already made huge improvements on this front.

https://techcommunity.microsoft.com/t5/azure-database-for-po...

Re:PostgreSQL 16 Beta 1 by garyclarke27 on Thursday May 25, 2023 @10:30AM (#36071198)
Postgresql is amazing but I must say the last few updates have been a bit disappointing.

Still waiting for automatic incremental updates for materialized views - been worked on for several years but still not released!

https://wiki.postgresql.org/wiki/Incremental_View_Maintenanc...

https://github.com/sraoss/pg_ivm

Re:PostgreSQL 16 Beta 1 by tensor on Thursday May 25, 2023 @10:59AM (#36071563)
To be fair view update is a very hard problem in computer science. It's not as though it's just a lack of time to implement it.
Re:PostgreSQL 16 Beta 1 by samwillis on Thursday May 25, 2023 @01:23PM (#36073495)
https://materialize.com/ are doing interesting things with this. Although not inside Postgres (they use a few bit of Postgres as components).
Re:PostgreSQL 16 Beta 1 by ksec on Thursday May 25, 2023 @11:56PM (#36079667)
I think PlanetScale implement something similar.

https://planetscale.com/blog/how-planetscale-boost-serves-yo...

Re:PostgreSQL 16 Beta 1 by cryptonector on Thursday May 25, 2023 @04:42PM (#36075932)
I've done some work in that space, which was mainly to build an alternative view materialization scheme[0] in PlPgSQL that reifies the internals of CREATE MATERIALIZED VIEW and REFRESH MATERIALIZED VIEW but with the following properties:

  - the materialized view is a plain table, so
     - you can write to it from triggers
     - you can have triggers on it
  - refreshing a view records the deltas in a
    history table (which is useful as a poor
    person's logical replication scheme)
  - you can mark a view as needing a refresh
Then in the application I have hand-coded triggers to either update the view's materialization directly or to mark the view as needing a refresh. A background job can asynchronously refresh views as needed.

I've also spent some time thinking about the AST form of view queries that PG stores and how one might automatically generate triggers on source tables that update the materialization or mark it as needing a refresh.

As you note, many queries can be very difficult to transform into queries that compute incremental deltas. Moreover, even where it's possible to do that, the time it takes to execute the delta computation might be unacceptably long. For example, if you have a recursively nested grouping schema and you want to maintain a view of the expanded transitive closure of that data, then removing a large from from another might require thousands of row deletions from the materialized view, and that might make the transaction take much too long in a UI -- the obvious thing to do here is to say "sorry, that kind of update takes a while to propagate, but your transaction will complete quickly", so just mark the view as needing a refresh and refresh it asynchronously.

[0] https://github.com/twosigma/postgresql-contrib/blob/master/m...

Re:PostgreSQL 16 Beta 1 by sophacles on Thursday May 25, 2023 @11:01AM (#36071591)
On the one hand, I totally understand.

On the other, it's pretty confidence-inspiring that they don't put stuff in until they're sure it's ready.

Re:PostgreSQL 16 Beta 1 by simonw on Thursday May 25, 2023 @12:58PM (#36073160)
Yeah, that's one of my favourite characteristics of PostgreSQL: if a feature makes it into a release, you can be VERY confident that it works well even across weird corner-cases.
Re:PostgreSQL 16 Beta 1 by pawelduda on Thursday May 25, 2023 @11:50AM (#36072305)
I have one use case where this functionality would be huge in terms of performance, patiently waiting for it
Re:PostgreSQL 16 Beta 1 by cryptonector on Thursday May 25, 2023 @04:53PM (#36076076)
You can use https://github.com/twosigma/postgresql-contrib/blob/master/m... and write triggers to update your views or mark them as needing asynchronous refreshes. It's not as automatic as what you'd like, but it's a lot better than having to keep waiting.
Re:PostgreSQL 16 Beta 1 by h1fra on Thursday May 25, 2023 @10:34AM (#36071243)
Postgres getting good updates at slow but steady pace over many decades is really impressive.
Re:PostgreSQL 16 Beta 1 by jasfi on Thursday May 25, 2023 @10:37AM (#36071280)
I look forward to seeing some benchmarks. Especially to see the effect of the SIMD optimizations.
Re:PostgreSQL 16 Beta 1 by dimmke on Thursday May 25, 2023 @10:46AM (#36071387)
I’m still learning 15 stop adding new features this was supposed to be the most stable thing in my whole fucked up tech stack
Re:PostgreSQL 16 Beta 1 by justinclift on Thursday May 25, 2023 @11:17AM (#36071836)
PG 15 has an EOL of Nov 2027, so you should be ok to stick with it for a while. ;)
Re:PostgreSQL 16 Beta 1 by Fgehono on Thursday May 25, 2023 @11:15AM (#36071792)
Whenever you do a one day full of updates and fix small issues but also gain new features and performance, just remember there is someone who uses some super old db no one wanna touch it again and the migration of that old thing will take weeks!
Re:PostgreSQL 16 Beta 1 by djbusby on Thursday May 25, 2023 @11:09AM (#36071699)
It can be. We still running PG11 and 13 in production. Not obligated to upgrade - especially when the software is rock solid.
Re:PostgreSQL 16 Beta 1 by gwen-shapira on Thursday May 25, 2023 @11:37AM (#36072121)
PG 11 is end-of-life, right? So you won't be getting new security updates. What's worse, libraries will stop supporting it over time, so you'll find it difficult to stay up to date in other places in your stack.

If I was running PG 11 in production, I'd be looking to upgrade sooner rather than later. Being on older-but-stable versions is good risk management, being on end-of-life version is not.

Re:PostgreSQL 16 Beta 1 by anarazel on Thursday May 25, 2023 @11:43AM (#36072194)
> PG 11 is end-of-life, right? So you won't be getting new security updates.

Not quite yet https://www.postgresql.org/support/versioning/ - the final release will be November 9, 2023.

Re:PostgreSQL 16 Beta 1 by djbusby on Thursday May 25, 2023 @11:47AM (#36072271)
We roll onto new stuff. So soon-ish the 11 will be replaced with a 14 or 15. And then later the 13 will roll up to whatever is good, stable and tested in our environment. And our roll-up plan has never seen an old PG lose client library access. PG has never ever, in 20+ years been the thing that holds us back. I also think risk-management has many more (important) factors than EOL.

Edit: quick check shows we also have PG9 and PG10 in some Live roles too.

Re:PostgreSQL 16 Beta 1 by tuetuopay on Thursday May 25, 2023 @10:50AM (#36071428)
This is an exciting release to be sure. Very happy to see that the CPU improvements include ARM, diversity is good!

Given the current release pace, I'd love to have another upgrade path than `pg_dump | psql`. That would remove a great deal of friction in prod.

Re:PostgreSQL 16 Beta 1 by hans_castorp on Thursday May 25, 2023 @10:56AM (#36071519)
> I'd love to have another upgrade path than `pg_dump | psql`

pg_upgrade

Re:PostgreSQL 16 Beta 1 by djbusby on Thursday May 25, 2023 @11:10AM (#36071722)
Or logical replication to the new box then migrate traffic.
Re:PostgreSQL 16 Beta 1 by ComputerGuru on Thursday May 25, 2023 @03:07PM (#36074731)
pg_upgrade is not an option on many systems if you are installing with the package manager as it requires both old and new binaries to be simultaneously present.
Re:PostgreSQL 16 Beta 1 by dawidpotocki on Friday May 26, 2023 @12:01AM (#36079711)
Arch Linux e.g. solved this by having a `postgresql-old-upgrade` package.
Re:PostgreSQL 16 Beta 1 by hans_castorp on Friday May 26, 2023 @03:46AM (#36081261)
Well, that's a problem of the package manager, not a Postgres problem.

At least with Ubuntu and RedHat/CentOS/Rocky/... installing two versions in parallel is absolutely no problem.

I think Ubuntu even wraps that into their upgrade scripts and you can pass an option to use pg_upgrade or pg_dump/pg_restore

Re:PostgreSQL 16 Beta 1 by jeltz on Thursday May 25, 2023 @04:36PM (#36075854)
There is pg_upgrade and logical replication. I have used both and they both work excellently. Logical replication can be a bit of a hassle to set up though, especially if the database is huge.
Re:PostgreSQL 16 Beta 1 by LunaSea on Thursday May 25, 2023 @10:54AM (#36071482)
Can't wait to have it available in RDS in 2030.
Re:PostgreSQL 16 Beta 1 by phamilton on Thursday May 25, 2023 @11:11AM (#36071733)
AWS has gotten much better in recent years. Pg15 is available on Aurora as of last month. That's about 6-7 months after it was released, a significant improvement over years past.
Re:PostgreSQL 16 Beta 1 by LunaSea on Thursday May 25, 2023 @01:45PM (#36073754)
Yup, but the lack of access to beta versions also means that we will basically get access to access to PostgreSQL 16 in RDS by next year around this time.
Re:PostgreSQL 16 Beta 1 by jkatz05 on Friday May 26, 2023 @04:58PM (#36089433)
Hey, I helped to write the original article, and I also work at AWS.

I'm happy to let you know that PostgreSQL 16 Beta 1 is available in the Amazon RDS Database Preview Environment (https://aws.amazon.com/about-aws/whats-new/2023/05/postgresq...). I hope you get a chance to test, I'm very eager to here any and all feedback about PostgreSQL 16.

Re:PostgreSQL 16 Beta 1 by LunaSea on Sunday May 28, 2023 @09:07AM (#36103663)
Thanks for the info!

Would you also know by any chance when RDS will get Graviton3 instances in non-Dublin EU regions?

Re:PostgreSQL 16 Beta 1 by pritambaral on Thursday May 25, 2023 @11:20AM (#36071873)
My list of unexpected but very welcome changes:

- pg_hba.conf and pg_ident.conf can include other files

- Logical replication apply can use non-PK btree indexes

- Integer literals in non-decimal bases

- Underscores in numeric literals

- Subqueries in the FROM clause can omit aliases

- Addition and subtraction of timestamptz values

- pg_upgrade can override new cluster's locale and encoding

Re:PostgreSQL 16 Beta 1 by MuffinFlavored on Thursday May 25, 2023 @11:48AM (#36072290)
Not a bad list!

https://commitfest.postgresql.org/19/1741/ (index skip scan/loose index scans) would be very welcomed... I think. Not sure how many people run into it in the wild.

It says "target version: 16" but "returned with feedback" and hasn't been bumped in 14 months. :( First opened in 2018.

https://wiki.postgresql.org/wiki/Loose_indexscan

Re:PostgreSQL 16 Beta 1 by seanhunter on Thursday May 25, 2023 @11:57AM (#36072393)
> - Subqueries in the FROM clause can omit aliases

This is great. It never made any sense to me that this was required. For people who are unaware, say you want to understand a table a natural way of doing it might be

    select * 
    from the_table
    order by some_metric desc 
    limit 10
so you'd think you can do the same for queries like

    select * 
    from (
      select blah blah blah the rest of the query
    ) a
    order by some_metric desc 
    limit 10
you need to put the alias 'a' to placate existing postgres even though it's never actually used, which never made any sense to me.
Re:PostgreSQL 16 Beta 1 by paulddraper on Thursday May 25, 2023 @01:30PM (#36073578)
It never made sense.

And FYI this comes from ANSI SQL.

Re:PostgreSQL 16 Beta 1 by Tostino on Tuesday May 30, 2023 @11:37AM (#36126117)
It does the second you want to join to the results of that subquery...this is an optimization that recognizes that the alias is never used and thus can be omitted. Nice QOL feature.
Re:PostgreSQL 16 Beta 1 by jimktrains2 on Thursday May 25, 2023 @01:54PM (#36073853)
It makes sense in that every table needs a name to reference, however if you only have the one table there isn't any ambiguity.
Re:PostgreSQL 16 Beta 1 by rektide on Thursday May 25, 2023 @11:56AM (#36072386)
Bunch of interesting loosenings ups on logical replication. Allowing standbys to also have subscribers; great for fan out! Bunch of perf improvements (honestly a bunch of it is removing rather onerous limitations I didn't know about!) At the end there seems to be a developer flag for allowing seeming bidirectional replication too.
Re:PostgreSQL 16 Beta 1 by simonw on Thursday May 25, 2023 @12:58PM (#36073145)
"parallel execution of the string_agg and array_agg aggregate functions" caught my eye - that feels like one of those minor improvements that might enable some pretty interesting new applications.

array_agg is particularly interesting, because it lets you implement patterns like this: https://til.simonwillison.net/sqlite/related-rows-single-que...

Re:PostgreSQL 16 Beta 1 by tracker1 on Thursday May 25, 2023 @02:01PM (#36073936)
Have to say, I find the SQL/JSON support in Postgres (jsonb) is probably the single biggest killer feature IMO. I can't believe MS (still) doesn't have an implementation (their SQL to JSON functions suck exponentially by comparison).

Nice to see the continued advancement and progression all around.

Re:PostgreSQL 16 Beta 1 by sureglymop on Thursday May 25, 2023 @02:33PM (#36074331)
Is MSSQL used often in production? And where are all the windows servers this would run on?
Re:PostgreSQL 16 Beta 1 by tracker1 on Thursday May 25, 2023 @02:55PM (#36074581)
Yes... many, many internal deployments are definitely using MS-SQL services. StackOverflow.com uses MS-SQL, for a prominent, public example. There are client libraries via ODBC or direct in many languages and platforms, including Node.js (mssql/tedious) and Rust.

As to where, AWS offers Windows as do many other cloud providers, including a significant portion of Azure VMs. Not to mention, that MS-SQL and SQL-Edge both run on Linux. IIRC, Azure Cloud SQL is also MS-SQL running a non-windows version. There's also Linux/x86_64 Docker images.

Aside: if you're willing to write a big check, MS-SQL replication configuration is far easier than pretty much anything else to setup and configure (UI based flows or scripted). While I personally advocate for PostgreSQL, I've used and mostly like MS-SQL fine.

Re:PostgreSQL 16 Beta 1 by sureglymop on Saturday May 27, 2023 @08:32AM (#36094202)
That's really interesting, a lot of that is new information to me! Thank you for the detailed response, I appreciate it.
Re:PostgreSQL 16 Beta 1 by cjblomqvist on Thursday May 25, 2023 @03:06PM (#36074718)
FYI: MS is releasing support for a native JSON data type in next release.

But yeah, obviously they're behind in that area!

Re:PostgreSQL 16 Beta 1 by jeltz on Thursday May 25, 2023 @04:39PM (#36075897)
I am personally very excited to see that work on direct IO has started. It is a huge undertaking so I do not expect any production ready thing any time soon but nice to see that some code landed.
Re:PostgreSQL 16 Beta 1 by anarazel on Thursday May 25, 2023 @04:47PM (#36075992)
Yeah- we've been working on that for quite a while, and it'll take a few more years to finish it. I hope we can get some important parts into 17 though.

FWIW, there have been smaller prerequisites merged into 15 already, and 16 has a number of improvements that are part of that work. E.g. the more scalable relation extension (making COPY scale much better), and the related buffer mapping changes, come from the AIO effort.

Personally I think the feature is using asynchronous IO and direct IO support is part of that :)

Re:PostgreSQL 16 Beta 1 by darksaints on Thursday May 25, 2023 @06:50PM (#36077441)
Meanwhile, PG15 is still in preview mode on Azure