Thread: pg_restore (fromuser -> touser)
Hi,
I had a general question about a feature that we depended on heavily when using other RDBMS providers which was the ability to take a schema dump and restore it to a different database and a different schema in that database (could be to the same database as well). Basically, there was an option on restore to specify a FROMUSER and a TOUSER directive so schema A could be restored elsewhere but as schema B.
I don’t see such an option in Postgres and the only workaround I am aware of is to do a plain-text (format=p) and then a crude find/replace to replace the old schema name with the new schema name. I’ve never actually tested this to be sure even this would work. Also, using this option will prevent us from parallelizing the import or export, so it’s really not something we want to do.
This would be a really useful feature in my opinion along with the ability to maintain parallelization options.
Are there any such features on the roadmap? Is my understanding correct about the available ways to accomplish this – again, in a practical and performant way?
Thanks,
Mayan
Hi,
I had a general question about a feature that we depended on heavily when using other RDBMS providers which was the ability to take a schema dump and restore it to a different database and a different schema in that database (could be to the same database as well). Basically, there was an option on restore to specify a FROMUSER and a TOUSER directive so schema A could be restored elsewhere but as schema B.
I don’t see such an option in Postgres and the only workaround I am aware of is to do a plain-text (format=p) and then a crude find/replace to replace the old schema name with the new schema name. I’ve never actually tested this to be sure even this would work. Also, using this option will prevent us from parallelizing the import or export, so it’s really not something we want to do.
This would be a really useful feature in my opinion along with the ability to maintain parallelization options.
Are there any such features on the roadmap? Is my understanding correct about the available ways to accomplish this – again, in a practical and performant way?
Thanks,
Mayan
This is true. Such a feature is not available in PostgreSQL.What you need to do is you have to take a structure dump, and change the schema name as per required. And, then, you may copy the data.Regards,Ninad ShahOn Fri, 23 Jul 2021 at 23:08, Mayan <popalzie@gmail.com> wrote:Hi,
I had a general question about a feature that we depended on heavily when using other RDBMS providers which was the ability to take a schema dump and restore it to a different database and a different schema in that database (could be to the same database as well). Basically, there was an option on restore to specify a FROMUSER and a TOUSER directive so schema A could be restored elsewhere but as schema B.
I don’t see such an option in Postgres and the only workaround I am aware of is to do a plain-text (format=p) and then a crude find/replace to replace the old schema name with the new schema name. I’ve never actually tested this to be sure even this would work. Also, using this option will prevent us from parallelizing the import or export, so it’s really not something we want to do.
This would be a really useful feature in my opinion along with the ability to maintain parallelization options.
Are there any such features on the roadmap? Is my understanding correct about the available ways to accomplish this – again, in a practical and performant way?
Thanks,
Mayan
Thanks for your reply. Is this something that I can request as a feature add? I don't think it should be too much of effort (based on my limited source code knowledge), but I'm not familiar with the process to request a feature.
Thanks for your reply. Is this something that I can request as a feature add? I don't think it should be too much of effort (based on my limited source code knowledge), but I'm not familiar with the process to request a feature.
On Sun, Jul 25, 2021 at 8:39 AM Mayan <popalzie@gmail.com> wrote:Thanks for your reply. Is this something that I can request as a feature add? I don't think it should be too much of effort (based on my limited source code knowledge), but I'm not familiar with the process to request a feature.You just did. But unless you are going to fund or help with actual development I don't see this going very far. This has been inquired about many times in the past yet the feature still does not exist.David J.
You just need to export dump without any privileges. And while restoring dump use the new role.
On Sun, Jul 25, 2021 at 8:02 PM Ganesh Korde <ganeshakorde@gmail.com> wrote:You just need to export dump without any privileges. And while restoring dump use the new role.You should read the body of the original email and not just the subject line. The actual question pertains to schemas - which IIUC are tightly linked to roles in other DBs (hence the observed behavior elsewhere) but aside from some default search_path stuff are unrelated in PostgreSQL.David J.
Hi,
I had a general question about a feature that we depended on heavily when using other RDBMS providers which was the ability to take a schema dump and restore it to a different database and a different schema in that database (could be to the same database as well). Basically, there was an option on restore to specify a FROMUSER and a TOUSER directive so schema A could be restored elsewhere but as schema B.
I don’t see such an option in Postgres and the only workaround I am aware of is to do a plain-text (format=p) and then a crude find/replace to replace the old schema name with the new schema name. I’ve never actually tested this to be sure even this would work. Also, using this option will prevent us from parallelizing the import or export, so it’s really not something we want to do.
This would be a really useful feature in my opinion along with the ability to maintain parallelization options.
Are there any such features on the roadmap? Is my understanding correct about the available ways to accomplish this – again, in a practical and performant way?
Thanks,
Mayan
On 2021-07-27 09:43:45 +0800, Ben Madin wrote: > Hi - we have had to do such operations quite commonly, if you want to automate > / stream such a change I would suggest that you look into sed. Off the top of > my head, consider something like this: > > pg_dump --format=p --schema=schema_a original_database | sed 's/ schema_a./ > schema_b./g' | psql new_database > > this is presuming a space before the schemaname, and a fullstop between schema > and other elements. Actually the "." in a regular expression matches any character, so this will also replace e.g. " schema_a5" with " schema_b.". This is easily fixed (just add a backslash), but more importantly, it will replace that string everywhere, regardless of context. This might lead to syntax errors or data corruption. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!"