-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sequence in public schema cannot be restored creating table in non-public schema #390
Comments
Update: I did try these steps to tediously clone the sequence first into the target schema, and with these steps pgcopydb works and copies the table over and with the sequence https://stackoverflow.com/a/18620623 From that point we could rename the table and sequence back if desired.
|
Yeah the table-sequence dependency is recorded in the Postgres catalogs and followed by pgcopydb. In your first attempt, there is no dependency between the sequence and the new table that is recorded. I wonder if you tried an approach based on Row-Level Security, where you would assign the filter to a role and then use that role to do the pgcopydb copy. It might be the most “transparent” approach, but I can't remember its complexity compared to what you end up doing here. In terms of data, though, it works without an extra copy on the source, which is a non-trivial benefit. |
Re-reading what I wrote, I think I didn't clarify the pgcopydb aspect of this directly enough. Because of scoping only to "myschema" then pgcopydb (correctly?) doesn't copy the sequence fully over and my guess was because only the sequence is in a different schema (public) vs. the table.
I don't know if that violates the design or not but I'd love to say "copy this Regarding RLS I did appreciate your suggestion on that and did start going down that path. I made a policy and a role and a function to read that role to fetch the visible rows, as a WIP. We still might go that route but I read that RLS adds overhead to every read of those tables because the policy needs to be checked. I was worried about operational problems due to my inexperience with RLS. However, duplicating the rows is tedious so it's not like a big win either. Initially I was more comfortable with avoiding impacting reads to the source table by the application. Maybe it makes sense to apply the policy only temporarily as needed and then remove it. In fact, an RLS configuration that was applied and removed for the duration of the pgcopydb operation would be an amazing feature! 😁 😁 |
I believe that when you do the following then the new table has no dependencies at all with the sequence. Here is a copy of a test case I did quicky which proves me wrong and proves you right, with a dependency query as found in pgcopydb sources to track tables and sequences:
So yeah I now believe our SQL query is filtering on the schema of the sequences wrongly. It should filter on the schema of the table that the sequences are attached to.
I believe it should just work as per your gut feeling.
Well you need to choose between a transparent WHERE clause being added (after some RLS computations to pick which to apply) or data set duplication. If you're only going to use the RLS setup for the pgcopydb context, I would pick that problem over the other one.
If I understand correctly RLS, this only applies anyway when you're using a role for which RLS rules have been set.
Some of the amazing things like that are needed are still out-of-scope of the tool. The beauty of RLS is that pgcopydb doesn't need to know anything about it. You can loop over the same command 12 times with 12 different roles and have it just work! I will see how to fix the initial problem, re-opening the issue now. |
Thanks for all your hard work on this. This is a great tool and I'm starting to evangelize it within the company to more team members to help us with database copying. I'll keep you in the loop as well although maybe outside of your issue tracker on whether we get an RLS policy going and can use it for this purpose. You're correct that we could drop it on the target with a more privileged user, change user, select the rows, change back, remove it, and that could be scripted from a shell script. |
This was more work than anticipated, and quite confusing for a while, but I think I got there. The sequence catalog queries were somewhat wrong and I fixed them, and then the filtering needed to be adjusted to consider the pg_dump statements for SEQUENCE, SEQUENCE OWNED BY, and DEFAULT separately. Before the fix we would always process the first two the same way. |
Hello. This might not really be a bug, but I don't know how to proceed.
For our use case we want to make a copied table with a reduced set of rows, then use that table as the source table with pgcopydb. The original table is in the public schema, so a copy of the table is put into
myschema
but it has the same definition.Sort of like this:
Now the new copied table
myschema.accounts
primary keyid
column still has a sequencepublic.accounts_id_seq
in the public schema.We'd like to copy the
myschema.accounts
table including the public scoped sequence. It finds the right number of sequences in the initial Fetching stage, but then fails in the pg_restore stage.Filter file:
Failures finding the public schema sequence:
public.accounts_id_sequence
with and without into the.ini
filter file, but that was just a guess and that doesn't seem to change the behavior.Any advice on how to copy a schema-qualified table and get a sequence for the table from another schema with pgcopydb?
Thanks.
The text was updated successfully, but these errors were encountered: