Re: Data loss on logical replication, 12.12 to 14.5, ALTER SUBSCRIPTION

2022-12-28 Thread Michail Nikolaev
Hello. > None of these entries are from the point mentioned by you [1] > yesterday where you didn't find the corresponding data in the > subscriber. How did you identify that the entries corresponding to > that timing were missing? Some of the before the interval, some after... But the source

Re: BUG: Postgres 14 + vacuum_defer_cleanup_age + FOR UPDATE + UPDATE

2023-01-05 Thread Michail Nikolaev
Hello, Andres. I apologize for the direct ping, but I think your snapshot scalability work in PG14 could be related to the issue. The TransactionIdRetreatedBy implementation looks correct... But with txid_current=212195 I see errors like "could not access status of transaction 58643736"... So,

Re: BUG: Postgres 14 + vacuum_defer_cleanup_age + FOR UPDATE + UPDATE

2023-01-06 Thread Michail Nikolaev
Hello! Thanks for checking the issue! > FWIW, I find that the "Assert(ItemIdIsNormal(lp));" at the top of > heap_lock_tuple() is the first thing that fails on my assert-enabled > build. Yes, the same for me: TRAP: failed Assert("ItemIdIsNormal(lp)"), File: "heapam.c", Line: 4292, PID:

Re: Data loss on logical replication, 12.12 to 14.5, ALTER SUBSCRIPTION

2023-01-03 Thread Michail Nikolaev
Hello, Amid. > The point which is not completely clear from your description is the > timing of missing records. In one of your previous emails, you seem to > have indicated that the data missed from Table B is from the time when > the initial sync for Table B was in-progress, right? Also, from

Re: Data loss on logical replication, 12.12 to 14.5, ALTER SUBSCRIPTION

2023-01-03 Thread Michail Nikolaev
> Does that by any chance mean you are using a non-community version of > Postgres which has some other changes? It is a managed Postgres service in the general cloud. Usually, such providers apply some custom minor patches. The only one I know about - about forbidding of canceling queries while

Re: BUG: Postgres 14 + vacuum_defer_cleanup_age + FOR UPDATE + UPDATE

2023-01-07 Thread Michail Nikolaev
Hello. The few things I have got so far: 1) It is not required to order by random() to reproduce the issue - it could be done using queries like: BEGIN; SELECT omg.* FROM something_is_wrong_here AS omg ORDER BY value -- change is here LIMIT 1 FOR

Re: Data loss on logical replication, 12.12 to 14.5, ALTER SUBSCRIPTION

2022-12-27 Thread Michail Nikolaev
Hello, Amit! > IUC, this is the time when only table B's initial sync was > in-progress. Table A's initial sync was finished by that time and for > Table C, it is yet not started. Yes, it is correct. C was started too, but unsuccessfully (restarted after, see below). > During the time of > the

Re: Slow standby snapshot

2022-11-20 Thread Michail Nikolaev
t-only for pgbench). If such approach looks committable - I could do more careful performance testing to find the best value for WASTED_SNAPSHOT_WORK_LIMIT_TO_COMPRESS. [1]: https://gist.github.com/michail-nikolaev/e1dfc70bdd7cfd1b902523dbb3db2f28 -- Michail Nikolaev Index: src/backend/storage/ip

Re: Slow standby snapshot

2022-11-20 Thread Michail Nikolaev
Oops, wrong image, this is correct one. But is 1-run tests, so it shows only basic correlation,

Re: Slow standby snapshot

2022-11-20 Thread Michail Nikolaev
Oh, seems like it is not my day :) The image fixed again.

Re: Slow standby snapshot

2022-11-29 Thread Michail Nikolaev
Hello, Tom. > Since we're running out of time in the current commitfest, > I went ahead and changed that, and made the cosmetic fixes > I wanted, and pushed. Great, thanks! The small thing I was thinking to add in KnownAssignedXidsCompress is the assertion like Assert(MyBackendType ==

Re: Slow standby snapshot

2022-11-16 Thread Michail Nikolaev
xcept non-startup processes (approach with offsets to skip gaps while building snapshot). [1]: https://gist.github.com/michail-nikolaev/e1dfc70bdd7cfd1b902523dbb3db2f28 [2]: https://www.postgresql.org/message-id/flat/CANtu0ogzo4MsR7My9%2BNhu3to5%3Dy7G9zSzUbxfWYOn9W5FfHjTA%40mail.gmail.com#341a3c3b033f69b26

Re: Slow standby snapshot

2022-11-22 Thread Michail Nikolaev
b9805 [2]: https://www.postgresql.org/message-id/flat/CANtu0oiPoSdQsjRd6Red5WMHi1E83d2%2B-bM9J6dtWR3c5Tap9g%40mail.gmail.com#cc4827dee902978f93278732435e8521 -- Michail Nikolaev From 926403598e9506edfa32c9534be9a4e48f756002 Mon Sep 17 00:00:00 2001 From: Michail Nikolaev Date: Wed, 23 No

Re: BUG: Postgres 14 + vacuum_defer_cleanup_age + FOR UPDATE + UPDATE

2023-01-22 Thread Michail Nikolaev
Hello. I have registered it as patch in the commit fest: https://commitfest.postgresql.org/42/4138/ Best regards, Michail.

BUG: Postgres 14 + vacuum_defer_cleanup_age + FOR UPDATE + UPDATE

2023-01-05 Thread Michail Nikolaev
Hello, hackers. It seems like PG 14 works incorrectly with vacuum_defer_cleanup_age (or just not cleared rows, not sure) and SELECT FOR UPDATE + UPDATE. I am not certain, but hot_standby_feedback probably able to cause the same issues. Steps to reproduce: 1) Start Postgres like this:

Replace known_assigned_xids_lck by memory barrier

2023-03-19 Thread Michail Nikolaev
%40mail.gmail.com#cc4827dee902978f93278732435e8521 From d968645551412abdb3fac6b8514c3d6746e8ac3d Mon Sep 17 00:00:00 2001 From: Michail Nikolaev Date: Sat, 18 Mar 2023 21:28:00 +0300 Subject: [PATCH v2] Removes known_assigned_xids_lck, using the write memory barrier as suggested earlier. --- src

Re: BUG: Postgres 14 + vacuum_defer_cleanup_age + FOR UPDATE + UPDATE

2023-02-04 Thread Michail Nikolaev
Hello, Andres. > Not sure I like TransactionIdRetreatSafely() as a name. Maybe > TransactionIdRetreatClamped() is better? I think it is better to just replace TransactionIdRetreatedBy. It is not used anymore after `v3-0001-WIP-Fix-corruption-due-to-vacuum_defer_cleanup_ag.patch` - so, it is

Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements

2024-02-21 Thread Michail Nikolaev
One more idea - is just forbid HOT prune while the second phase is running. It is not possible anyway currently because of snapshot held. Possible enhancements: * we may apply restriction only to particular tables * we may apply restrictions only to part of the tables (not yet scanned by R/CICs).

Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements

2024-02-20 Thread Michail Nikolaev
Hello! > I think the best way for this to work would be an index method that > exclusively stores TIDs, and of which we can quickly determine new > tuples, too. I was thinking about something like GIN's format, but > using (generation number, tid) instead of ([colno, colvalue], tid) as > key data

Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements

2024-02-21 Thread Michail Nikolaev
Hi! > How do you suppose this would work differently from a long-lived > normal snapshot, which is how it works right now? Difference in the ability to take new visibility snapshot periodically during the second phase with rechecking visibility of tuple according to the "reference" snapshot

Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements

2023-12-20 Thread Michail Nikolaev
Hello! > Also, feels like we may apply this to both phases (first and the second > scans). > The original patch (1) was helping only to the second one (after call > to set_indexsafe_procflags). Oops, I was wrong here. The original version of the patch was also applied to both phases. > Note

Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements

2023-12-15 Thread Michail Nikolaev
Hello, hackers! I think about revisiting (1) ({CREATE INDEX, REINDEX} CONCURRENTLY improvements) in some lighter way. Yes, a serious bug was (2) caused by this optimization and now it reverted. But what about a more safe idea in that direction: 1) add new horizon which ignores PROC_IN_SAFE_IC

Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements

2023-12-20 Thread Michail Nikolaev
Hello! > How would this deal with tuples not visible to the old snapshot? > Presumably we can assume they're newer than that snapshot (the old > snapshot didn't have it, but the new one does, so it's committed after > the old snapshot, making them newer), so that backend must have > inserted it

Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements

2023-12-20 Thread Michail Nikolaev
> Yes, good catch. > Assuming we have somehow prevented vac_truncate_clog from occurring > during CIC, we can leave frozen and potentially frozen > (xmin

Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements

2024-01-09 Thread Michail Nikolaev
Hello, Melanie! Sorry to interrupt you, just a quick question. > Correct, but there are changes being discussed where we would freeze > tuples during pruning as well [0], which would invalidate that > implementation detail. And, if I had to choose between improved > opportunistic freezing and

Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements

2024-01-04 Thread Michail Nikolaev
Hello! > Correct, but there are changes being discussed where we would freeze > tuples during pruning as well [0], which would invalidate that > implementation detail. And, if I had to choose between improved > opportunistic freezing and improved R/CIC, I'd probably choose > improved freezing

Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements

2023-12-17 Thread Michail Nikolaev
Hello! > I've thought about alternative solutions, too: how about getting a new > snapshot every so often? > We don't really care about the liveness of the already-scanned data; the > snapshots used for RIC > are used only during the scan. C/RIC's relation's lock level means vacuum > can't run

Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements

2023-12-21 Thread Michail Nikolaev
Hello. Realized my last idea is invalid (because tuples are frozen by using dynamically calculated horizon) - so, don't waste your time on it :) Need to think a little bit more here. Thanks, Mikhail.

Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements

2023-12-25 Thread Michail Nikolaev
Hello! It seems like the idea of "old" snapshot is still a valid one. > Should this deal with any potential XID wraparound, too? As far as I understand in our case, we are not affected by this in any way. Vacuum in our table is not possible because of locking, so, nothing may be frozen (see

Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements

2024-02-01 Thread Michail Nikolaev
> > > I just realised there is one issue with this design: We can't cheaply > > > reset the snapshot during the second table scan: > > > It is critically important that the second scan of R/CIC uses an index > > > contents summary (made with index_bulk_delete) that was created while > > > the

Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements

2024-05-09 Thread Michail Nikolaev
Hello, Matthias and others! Realized new horizon was applied only during validation phase (once index is marked as ready). Now it applied if index is not marked as valid yet. Updated version in attach. -- > I think the best way for this to work

Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements

2024-05-04 Thread Michail Nikolaev
Hello, Matthias! > We can just release the current snapshot, and get a new one, right? I > mean, we don't actually use the transaction for much else than > visibility during the first scan, and I don't think there is a need > for an actual transaction ID until we're ready to mark the index entry

Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements

2024-05-07 Thread Michail Nikolaev
Hi again! Made an error in `GlobalVisHorizonKindForRel` logic, and it was caught by a new test. Fixed version in attach. > From 9a8ea366f6d2d144979e825c4ac0bdd2937bf7c1 Mon Sep 17 00:00:00 2001 From: nkey Date: Tue, 7 May 2024 22:10:56 +0200 Subject: [PATCH v3] WIP: fix d9d076222f5b "VACUUM:

Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements

2024-05-05 Thread Michail Nikolaev
Hello, Matthias! I just realized there is a much simpler and safe way to deal with the problem. So, d9d076222f5b94a85e0e318339cfc44b8f26022d(1) had a bug because the scan was not protected by a snapshot. At the same time, we want this snapshot to affect not all the relations, but only a subset

Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements

2024-05-07 Thread Michail Nikolaev
Hello, Matthias and others! Updated WIP in attach. Changes are: * Renaming, now it feels better for me * More reliable approach in `GlobalVisHorizonKindForRel` to make sure we have not missed `rd_safeindexconcurrentlybuilding` by calling `RelationGetIndexList` if required * Optimization to avoid

Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements

2024-03-07 Thread Michail Nikolaev
Hello! > I'm not a fan of this approach. Changing visibility and cleanup > semantics to only benefit R/CIC sounds like a pain to work with in > essentially all visibility-related code. I'd much rather have to deal > with another index AM, even if it takes more time: the changes in > semantics

Re: Issues with ON CONFLICT UPDATE and REINDEX CONCURRENTLY

2024-06-14 Thread Michail Nikolaev
Hello, Michael. > Isn't the issue that we may select as arbiter indexes stuff that's !indisvalid? As far as I can see (1) !indisvalid indexes are filtered out. But... It looks like this choice is not locked in any way (2), so index_concurrently_swap or index_concurrently_set_dead can change this

Re: Issues with ON CONFLICT UPDATE and REINDEX CONCURRENTLY

2024-06-14 Thread Michail Nikolaev
Hello. > But I was unable to reproduce that using some random usleep(), however - maybe it is a wrong assumption. It seems like the assumption is correct - we may use an invalid index as arbiter due to race condition. The attached patch adds a check for that case, and now the test fails like

Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements

2024-06-11 Thread Michail Nikolaev
Hello. I did the POC (1) of the method described in the previous email, and it looks promising. It doesn't block the VACUUM, indexes are built about 30% faster (22 mins vs 15 mins). Additional index is lightweight and does not produce any WAL. I'll continue the more stress testing for a while.

Issues with ON CONFLICT UPDATE and REINDEX CONCURRENTLY

2024-06-11 Thread Michail Nikolaev
63446 per second # going to start reindex, num tuples in table is 1566 In some moments, all CPUs all hot but 30 connections are unable to do any upsert. I think it may be somehow caused by two arbiter indexes (old and new reindexed one). Best regards, Mikhail. [1]: https://www.post

Re: Issues with ON CONFLICT UPDATE and REINDEX CONCURRENTLY

2024-06-17 Thread Michail Nikolaev
Hello, everyone. > I think It is even possible to see !alive index in the same situation (it is worse case), but I was unable to reproduce it so far. Fortunately, it is not possible. So, seems like I have found the source of the problem: 1) infer_arbiter_indexes calls RelationGetIndexList to

Re: race condition in pg_class

2024-06-12 Thread Michail Nikolaev
Hello, everyone. I am not sure, but I think that issue may be related to the issue described in https://www.postgresql.org/message-id/CANtu0ojXmqjmEzp-%3DaJSxjsdE76iAsRgHBoK0QtYHimb_mEfsg%40mail.gmail.com It looks like REINDEX CONCURRENTLY could interfere with ON CONFLICT UPDATE in some strange

Re: race condition in pg_class

2024-06-12 Thread Michail Nikolaev
Hello! > Can you say more about the connection you see between $SUBJECT and that? That > looks like a valid report of an important bug, but I'm not following the > potential relationship to $SUBJECT. I was guided by the following logic: * A pg_class race condition can cause table indexes to look

Re: Issues with ON CONFLICT UPDATE and REINDEX CONCURRENTLY

2024-06-21 Thread Michail Nikolaev
Hello, Michael! > This is a non-fresh Friday-afternoon idea, but it would make sure that > we don't have any transactions using the indexes switched to _ccold > with indisvalid that are waiting for a drop in phase 5. Your tests > seem to pass with that, and that keeps the operation intact >

<    1   2