News for hackers. Stuff that matters.
Re:PostgreSQL 15 by morley on Thursday October 13, 2022 @10:50AM (#33191784)
I hate to ask a stupid question, but I'm new to administering a Postgres database.

Do admins usually upgrade their DBs with each major release? I'm guessing it's highly contextual and depends on how easy it is to do so, but I've heard about places that never upgrade until it's a huge problem for them to do so (in order to avoid an even worse problem.)

Re:PostgreSQL 15 by ianbutler on Thursday October 13, 2022 @10:56AM (#33191869)
I don't think I've worked in an environment where we've upgraded for every release. New projects may start on that newer version, but generally speaking for older projects there's a cost calculation done for the newer features versus the lift required to do the upgrade and ensure it doesn't introduce any regressions.

Someone already mentioned the view permissions shift here which looks at caller permissions versus the view creator permissions, that will be compelling in a lot of cases so like this is something that I'd probably raise internally for my team for a few of the apps we maintain and then have a back and forth with the principals, if we like it then go through our current list of work with a PM and our manager and see if it makes sense to do now with the current pipeline of work etc.

Re:PostgreSQL 15 by jeff-davis on Thursday October 13, 2022 @12:07PM (#33192921)
The version support is five years: https://www.postgresql.org/support/versioning/

As long as you stay well ahead of that, you are fine.

However, I'd strongly recommend testing your applications with new versions as they come out, or in beta (even better). You may learn about new features, find bugs in your application, find bugs in your migration processes, etc. If you bring any problems to the community right away, then by the time you actually want to upgrade, the problems may already be solved in the newer release.

Re:PostgreSQL 15 by Uninen on Thursday October 13, 2022 @12:58PM (#33193661)
According to https://www.postgresql.org/support/versioning/ the "Final Release" (whatever that means) for v14 is November 2026, and for v15 is November 2024. I wonder if it's a typo or some LTS thing.
Re:PostgreSQL 15 by cheald on Thursday October 13, 2022 @02:15PM (#33194518)
Almost certainly a typo. PG releases get 5 years of support.
Re:PostgreSQL 15 by jeltz on Thursday October 13, 2022 @11:11AM (#33192133)
No, but as a PostgreSQL fan I upgrade the databases every major release for my side projects. I always wait until .1 or .2 is released though.
Re:PostgreSQL 15 by bitwrangler on Thursday October 13, 2022 @11:38AM (#33192486)
I've heard a saying "just say no to dot oh" -- encouraging one to skip the .0 release and wait until .1 or .2 before doing the upgrade.
Re:PostgreSQL 15 by samus on Thursday October 13, 2022 @12:14PM (#33193029)
This will stop working when not enough people adopt .0 versions anymore, because errors from regular usage will not pop up. .0 will become the new beta release that nobody cares about.
Re:PostgreSQL 15 by Beltalowda on Thursday October 13, 2022 @12:46PM (#33193498)
I typically update to .0 on my dev machine ASAP, and if there are no problems after a bit I'll update the server to .0 (or usually .1, since that'll usually be out by then).

I think that's a nice compromise; although not a "real" test as the load is a lot less. Also things may work in dev but not production, but unless you explicitly use new features that's rare.

For larger setups you can us canary servers and whatnot, but I prefer to work at small companies and keep my sanity.

Re:PostgreSQL 15 by thewataccount on Thursday October 13, 2022 @02:19PM (#33194549)
For context my ideal setup has at least 3 environments - prod, qa/testing before release, and dev. With dev being the most likely to break, and the qa/testing for when we need to be absolutely certain that differences between prod and dev aren't masking any bugs.

I do like the idea of "canary versioning" some stuff. It's a bit of a game theory issue isn't it, since we all need prod to work at all times and can't risk a .0, and a major version difference between dev and prod can mask some nasty issues in my experience.

Re:PostgreSQL 15 by CoolCold on Thursday October 13, 2022 @03:29PM (#33195415)
Luckily nowdays we have enough brave persons who just take whatever is postgres:latest image from Docker hub.

Unluckily, chances they will report bugs not that high - at least I don't expect bugs related to any moderate size/loaded databases be found by this way.

Re:PostgreSQL 15 by jacooper on Thursday October 13, 2022 @11:18AM (#33192222)
If only they made the upgrade automatic.

I use it in a container mainly, and MariaDB has an option to enable auto upgrades, but postgres requires you to manually upgrade every time.

Re:PostgreSQL 15 by jeltz on Thursday October 13, 2022 @11:32AM (#33192399)
For small databases with lax uptime requirements I find it pretty easy to upgrade. Just stop the database, run pg_upgrade_cluster (a Debian tool) and create a new replica.

For large databases where you care about uptime upgrading is usually a huge project anyway, since you have to make sure that nothing breaks due to the new version (check query plans, check if the new version changed anything, etc). You also probably want to use logical replication for the upgrade. There are things that PostgreSQL can improve of course.

As an aside I recently was involved in an upgrade from 9.6 where we used logical replication and pg_dump (yes, we really used pg_dump on a 20+ TB database). The reason for using pg_dump was because we have some tables which bloated very fast meaning we could not hold a snapshot open on the master long enough to do the initial data copy so the initial copy was done with pg_dump from a paused replica. And to not lose any data during pg_dump/pg_restore we kept a logical replication slot alive (but unused until pg_restore was complete). That was an interesting project, especially since Googling did not turn up anyone who had done the same.

Re:PostgreSQL 15 by jtc331 on Thursday October 13, 2022 @12:12PM (#33192995)
Isn’t keeping a logical slot alive holding a snapshot?
Re:PostgreSQL 15 by anarazel on Thursday October 13, 2022 @12:33PM (#33193312)
Not normally, no. A real snapshot is held during the initial creation of the logical slot. After that the slot's "catalog xmin" prevents old catalog (but not user table!) row versions from being removed, but that's somewhat different from a snapshot.
Re:PostgreSQL 15 by jeltz on Thursday October 13, 2022 @03:09PM (#33195151)
Exactly. We had to disable some cron jobs which abuse temporary tables (and functions!) to avoid catalog bloat but there were no long lived snapshots on the master during the upgrade.
Re:PostgreSQL 15 by 86____ on Thursday October 13, 2022 @11:51AM (#33192675)
I'd genuinely love to read about that if you're able to share more?
Re:PostgreSQL 15 by stubish on Thursday October 13, 2022 @08:42PM (#33198360)
Major version upgrades by definition contain breaking changes. Automatic upgrades across major versions will break things. Still, some distributions do handle this somewhat sanely. For example, Debian and derivatives such as Ubuntu let you have multiple versions installed at the same time and provide a pg_upgradecluster tool to handle the upgrade automatically in most cases. It just won't do it while you are asleep (thankfully).
Re:PostgreSQL 15 by film42 on Thursday October 13, 2022 @11:15AM (#33192173)
Corruption of database storage is the biggest fear so most upgrades are done cautiously. Historically postgres versions were released much much slower so the upgrade cadence was slower too. That said, we've been upgrading more frequently, especially since a lot of performance features are being released. So far our upgrades have been executed flawlessly for our cluster of postgres servers (~30 postgres chains each made up of 4x large dedicated servers).
Re:PostgreSQL 15 by jeff-davis on Thursday October 13, 2022 @11:51AM (#33192677)
Postgres has released a new major version each year for a long time.

The only change is that versions used to be X.Y.Z, and now it just used X.Y. Now, X gets incremented for every major version, so it seems like it's moving faster.

Re:PostgreSQL 15 by jsmith99 on Friday October 14, 2022 @03:14AM (#33200496)
The difference is that in place upgrades aren't possible for major versions.
Re:PostgreSQL 15 by jeff-davis on Sunday October 16, 2022 @01:35PM (#33225463)
pg_upgrade is the way to do in-place upgrade between major versions:

https://www.postgresql.org/docs/current/pgupgrade.html

Re:PostgreSQL 15 by jeltz on Thursday October 13, 2022 @03:23PM (#33195349)
Jeff is right, PostgreSQL has released a new major yearly the last almost 25 years.
Re:PostgreSQL 15 by tinus_hn on Friday October 14, 2022 @07:58AM (#33202358)
That would only be possible if they started with version -10!
Re:PostgreSQL 15 by alvherre on Friday October 14, 2022 @11:32AM (#33204900)
Before version 10, the versioning scheme was different, and the first number was increased about once every five years: for example, 9.6 and 9.5 were consecutive yearly major releases. Version 7.0 was released around year 2000.
Re:PostgreSQL 15 by clepto on Thursday October 13, 2022 @11:44AM (#33192560)
As someone who maintains Postgres 9.2, 9.4, and 9.6 databases. No, they do not.

(It is not my will that these databases aren’t on newer versions, I would very much like them to be)

Re:PostgreSQL 15 by thewataccount on Thursday October 13, 2022 @02:13PM (#33194498)
Just curious, is the issue a time thing, or is it on a system that can't easily upgrade it - or is it a breaking changes thing that would require refactors?

Basically I'm just curious what broke for you

Re:PostgreSQL 15 by tcgv on Thursday October 13, 2022 @02:41PM (#33194808)
One main challenge is to upgrade a live large database smoothly, without downtime.

I believe minor version upgrades are easily enough since they maintain disk format compatibility and you can simply spin up a new replica server under the new postgres version and then when it's synched with the main database you can make the switch and kill the old version. I'm not so sure about migrating to a new major version (ex: 9.x to 15.x).

Re:PostgreSQL 15 by whartung on Thursday October 13, 2022 @04:10PM (#33195911)
Thing is, in this specific context, as I understand it, this is much easier to do post 9.x.

Notably, Postgres has more formal support for logical replication. Logical replication is distinct from the normal replication in that it forwards actual SQL to the replica rather than binary write ahead logs.

The SQL is portable across versions more than WALs are. So with logical replication you can copy a live db to a new version. Then you just need some (ideally) brief down time to swap out the servers.

There are solutions for 9.x, but it got much better later on.

Re:PostgreSQL 15 by ellisv on Thursday October 13, 2022 @11:18AM (#33192223)
Our current policy is to update to the N-1 release. So we're currently running v13 since v14 was the latest but will soon upgrade to v14 since v15 is now the latest.
Re:PostgreSQL 15 by briffle on Thursday October 13, 2022 @11:20AM (#33192247)
It takes us a few months to upgrade, with planning, testing, co-ordinating downtime, etc. We upgrade every other year, to keep us from falling too far back.

Very excited for this year, as we'll be using logical replication to migrate, which should make this much less risky. (since the old systems are untouched).

In the past, we used pg_upgrade for in place upgrades, and even though we took snapshots before, still seemed a bit stressfull when it happened.

Re:PostgreSQL 15 by wink on Thursday October 13, 2022 @11:00AM (#33191952)
My experience is mostly that you either upgrade because it has a feature you need (then you try it out fast), if it has some performance or other nice thing (then you go for the .1) or you don't really care then you upgrade when your current version goes EOL or if you upgrade your underlying server OS (if we assume something like Ubuntu LTS, and they'd go with 14 instead of 12 or something).
Re:PostgreSQL 15 by efxhoy on Thursday October 13, 2022 @07:01PM (#33197593)
When a new version reaches RDS we start planning for the upgrade. We like the new features so we try to stay as current as we can.
Re:PostgreSQL 15 by zhann_dc on Thursday October 13, 2022 @11:42AM (#33192533)
We do. Though we make sure to stay on the previous major. So we’ll only upgrade to PostgreSQL 15 when 16 is released.
Re:PostgreSQL 15 by tmountain on Thursday October 13, 2022 @11:00AM (#33191945)
In my experience, it’s always been a huge decision to upgrade based on lots of analysis and factors. I have never worked in a company where the team routinely upgrades when a major version comes out, as it generally doesn’t make business sense. Just my 2c…
Re:PostgreSQL 15 by dewey on Thursday October 13, 2022 @10:59AM (#33191925)
This probably depends on your database, but with Postgres we usually don't stay on the old version for too long as the updates are usually very smooth and painless.
Re:PostgreSQL 15 by aprdm on Thursday October 13, 2022 @11:06AM (#33192055)
How do you upgrade and how much data do you have ?
Re:PostgreSQL 15 by dewey on Thursday October 13, 2022 @11:16AM (#33192202)
Mostly in the 1TB range and usually by doing the replication / promotion dance. I know it gets more complicated if you have larger ones or with zero write downtime but in our case that's usually acceptable.
Re:PostgreSQL 15 by _jal on Thursday October 13, 2022 @11:13AM (#33192154)
We are heavy on-prem Postgres users. We currently run all major versions from 10-13, and are upgrading some clusters to 14 very soon. Old versions are mostly to support internal tools that we're not upgrading for various reasons, and will go away when the apps that use them do.

We generally stay one major version behind on the main production clusters. The major reason is usually just scheduling - PG upgrades are large projects that touch a lot of things, take a lot of prep and impact every part of our business, so scheduling it is always a fraught negotiation.

If you don't have a lot of complexity, I recommend finding a cadence that doesn't hurt, but sticking with it. Once you get far enough behind, it becomes harder to upgrade, mostly because you also weren't upgrading surrounding tooling, so you end up changing a lot of things at once.

As your environment grows in complexity and use, at some point I think you'll find that nontechnical concerns start to dominate these decisions.

Re:PostgreSQL 15 by wahnfrieden on Thursday October 13, 2022 @10:58AM (#33191901)
.1+ releases might be best with pg for quality assurance
Re:PostgreSQL 15 by fdr on Thursday October 13, 2022 @12:17PM (#33193067)
I don't unless I want to use something. The main consideration is hedging against an unusual problem in a new version vs. my software.

This may depend on your situation. For example, if you were running a large IT org with a few staff members with a lot of installed software, the cycle to process and check correct operation of each software under your management may be long enough that you'd start soon: by the time you are working on the last few systems under your responsibility, EOL for that Postgres version may be in sight.

You may also be working on a very new software project, where bugs are of lower consequence and you'd like to forestall the friction of an upgrade motivated by EOL. Or, you may find yourself in a lull in useful development and this is a good way to get ahead of maintenance, effectively reducing pressure in the future. In this case, I'd also consider upgrading...after a few months. Even Postgres has somewhat iffy .0 releases.

My own experience is in vertically integrated teams where we control all the software, so we typically upgrade every second or third version, leaving over a year to resolve issues before EOL of the version we're on.

Re:PostgreSQL 15 by phamilton on Thursday October 13, 2022 @12:53PM (#33193584)
We try to upgrade at least once a year, during our slow season (ed-tech, so summer time is < 1/10th peak traffic).

We use AWS Aurora with Postgres and we autoscale our cluster. Because most upgrades have a few perf improvements we have found that we save a bit of money every time we upgrade, either in reduced CPU (which translates to running fewer instances) or in better memory efficiency (which boosts buffer_cache_hit_ratio and therefore reduces IO).

Re:PostgreSQL 15 by thewataccount on Thursday October 13, 2022 @02:09PM (#33194451)
I manage two separate projects at my work, I would never upgrade to a .0 update, but we do every update it either when there's features we want, over every ~2~3 years for the general improvements.

We use django and some other stuff that has very decent support for postgres, and in my experience postgres updates rarely have breaking changes that require much if any changes for us. This also keeps us from being "trapped" on an old version.

I reiterate from all my systems management - do not update to a .0 release of anything unless there is a critical security update and you're forced to.

EDIT: Oh directly for the question - eh depends. Every 2 to 3 max, and usually after it's tested by others more.

And new projects generally use whatever is newest unless it's a .0 release.

Re:PostgreSQL 15 by frant-hartm on Thursday October 13, 2022 @03:02PM (#33195077)
Note that vendors know this and some release few patch versions quickly with only few patches to make people move to newest version (and get the community test it by using it). No idea if Postgres is one of these.
Re:PostgreSQL 15 by alvherre on Friday October 14, 2022 @11:29AM (#33204856)
Postgres has a strict schedule of quarterly bugfix releases, and only deviates from that when serious bugs occur (very rare). So, no.
Re:PostgreSQL 15 by tomputer on Friday October 14, 2022 @08:43AM (#33202772)
Where I work we've recently upgraded many PostgreSQL servers from 9.x/10.x/11.x to 14.x.

A very cool PostgreSQL feature is that, if you install a second instance on the same server, it will by default use a different path and port to run the second instance.

  root@example:~# pg_lsclusters
  Ver Cluster Port Status Owner    Data directory              Log file
  11  main    5432 online postgres /var/lib/postgresql/11/main /var/log/postgresql/postgresql-11-main.log
  14  main    5433 online postgres /var/lib/postgresql/14/main /var/log/postgresql/postgresql-14-main.log
Now you can dump and import databases on the second instance and test your applications with the new version. If it all works as expected, use pg_upgrade[1] to migrate everything to the new instance and switch the ports after the migration.

I have only done this migration process on Debian systems but in my experience it worked fantastic!

[1] https://www.postgresql.org/docs/current/pgupgrade.html

Re:PostgreSQL 15 by nijave on Friday October 14, 2022 @10:49AM (#33204277)
Depends on the app but usually don't major version upgrade unless the current version is losing support or there's a compelling new feature. I wouldn't run on the latest until a few point releases are out (say .3 or .4).

I haven't worked on anything recently with a good performance testing system so that weighs in a bit, too (there's not a high degree of confidence the app won't hit a weird perf regression or edge case)

If it's using a managed service, that weighs in, too. Something like AWS RDS Postgres usually has a 6 month lag + give it some additional time to work out any AWS control plane "surprises"