![](/img/trans.png)
[英]Create extension from postgres superuser to another database with it own owner?
[英]Move data from a postgres database to another database with a different owner
我有兩個具有相同結構和表的postgres數據庫,托管在同一台服務器上,數據庫由不同的用戶擁有:
database1 : owner1
database2 : owner2
我想知道的數據庫1的內容轉換成DATABASE2(覆蓋DATABASE2的原始內容)復制的最佳方式。
我嘗試了pg_dump和pg_restore,但轉儲將顯式指定owner1作為表的所有者,然后我嘗試使用owner2從database2獲取數據時遇到權限問題。 我不得不手動將database2上的所有權限重新授予owner2 ,並將所有表的所有者再次設置為owner2 。
我的方法:
pg_dump database1 > database1.psql
postgres=# drop database database2;
postgres=# create database database2;
psql --d database2 -f database1.psql
有沒有更簡單的方法將數據從database1復制到database2,而無需在還原后手動更新用戶權限。
是的,您可以使用pg_dump指定您不想導出所有權:
-O
(或--no-owner
)不導出所有權 -x
(或--no-privileges
)防止轉儲訪問權限(grant / revoke命令) pg_dump db_name -O -x > output_file
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.