PostGreSQL pg_dump psql and pg_restore errors with Azure Flexible SQL Server

I am trying to dump and then restore PostGreSQL databases using Azure PostGreSQL Flexible.

I am using pg_dump and psql previously for these purposes.

I have been succesfully using following commands to backup and restore my PostGreSQL instances on other providers and on premise for multiple years without any issues.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>pg_dump -U postgres -h localhost -p 5432 staging -n public --format=p > project-io-staging-4-Sep-2024.sql
psql -U postgres -h localhost -p 5432 production -c "drop schema public cascade;"
psql -U postgres -h localhost -p 5432 production -n public -1 -f ./project-io-production-4-Sep-2024.sql
</code>
<code>pg_dump -U postgres -h localhost -p 5432 staging -n public --format=p > project-io-staging-4-Sep-2024.sql psql -U postgres -h localhost -p 5432 production -c "drop schema public cascade;" psql -U postgres -h localhost -p 5432 production -n public -1 -f ./project-io-production-4-Sep-2024.sql </code>
pg_dump -U postgres -h localhost -p 5432 staging -n public --format=p > project-io-staging-4-Sep-2024.sql

psql -U postgres -h localhost -p 5432 production -c "drop schema public cascade;"
psql -U postgres -h localhost -p 5432 production -n public -1 -f ./project-io-production-4-Sep-2024.sql

However, when I try to do exact same thing with Azure Flexible Server, here below is what I get :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>% psql "host=project-development2.postgres.database.azure.com port=5432 user=myuser dbname=staging sslmode=require" -1 -f ./project-io-staging-4-Sep-2024.sql
Password for user myuser:
SET
SET
SET
SET
SET
set_config
------------
(1 row)
SET
SET
SET
SET
CREATE SCHEMA
ALTER SCHEMA
COMMENT
SET
SET
CREATE TABLE
psql:project-io-staging-4-Sep-2024.sql:60: ERROR: must be able to SET ROLE "postgres"
psql:project-io-staging-4-Sep-2024.sql:72: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:project-io-staging-4-Sep-2024.sql:75: ERROR: current transaction is aborted, commands ignored until end of transaction block
...
</code>
<code>% psql "host=project-development2.postgres.database.azure.com port=5432 user=myuser dbname=staging sslmode=require" -1 -f ./project-io-staging-4-Sep-2024.sql Password for user myuser: SET SET SET SET SET set_config ------------ (1 row) SET SET SET SET CREATE SCHEMA ALTER SCHEMA COMMENT SET SET CREATE TABLE psql:project-io-staging-4-Sep-2024.sql:60: ERROR: must be able to SET ROLE "postgres" psql:project-io-staging-4-Sep-2024.sql:72: ERROR: current transaction is aborted, commands ignored until end of transaction block psql:project-io-staging-4-Sep-2024.sql:75: ERROR: current transaction is aborted, commands ignored until end of transaction block ... </code>
% psql "host=project-development2.postgres.database.azure.com port=5432 user=myuser dbname=staging sslmode=require" -1 -f ./project-io-staging-4-Sep-2024.sql
Password for user myuser: 
SET
SET
SET
SET
SET
 set_config 
------------
 
(1 row)

SET
SET
SET
SET
CREATE SCHEMA
ALTER SCHEMA
COMMENT
SET
SET
CREATE TABLE
psql:project-io-staging-4-Sep-2024.sql:60: ERROR:  must be able to SET ROLE "postgres"
psql:project-io-staging-4-Sep-2024.sql:72: ERROR:  current transaction is aborted, commands ignored until end of transaction block
psql:project-io-staging-4-Sep-2024.sql:75: ERROR:  current transaction is aborted, commands ignored until end of transaction block
...

I also cannot set role as azuresu user is not available for login.

I have used the following command to create a dbase without UI, but still the roles are not available for the newly created dbase although the very same user has created the dbase.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>createdb staging -h project-development2.postgres.database.azure.com -p 5432 -U project
</code>
<code>createdb staging -h project-development2.postgres.database.azure.com -p 5432 -U project </code>
createdb staging -h project-development2.postgres.database.azure.com -p 5432 -U project

I am trying to use the following as well, but still no luck, I get same error messages :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>pg_dump -Fd -j 2 staging -h localhost -p 5432 -U postgres -N cron -f ./project-io-staging-5-Sep-2024.sql
pg_restore -j 2 -d staging -h project-development2.postgres.database.azure.com -p 5432 -U project project-io-staging-5-Sep-2024.sql
</code>
<code>pg_dump -Fd -j 2 staging -h localhost -p 5432 -U postgres -N cron -f ./project-io-staging-5-Sep-2024.sql pg_restore -j 2 -d staging -h project-development2.postgres.database.azure.com -p 5432 -U project project-io-staging-5-Sep-2024.sql </code>
pg_dump -Fd -j 2 staging -h localhost -p 5432 -U postgres -N cron -f ./project-io-staging-5-Sep-2024.sql

pg_restore -j 2 -d staging -h project-development2.postgres.database.azure.com -p 5432 -U project project-io-staging-5-Sep-2024.sql

There is mention of this flag for pg_restore “–no-owner”, however I cannot risk that as well.

How can I make this migration to succesfully happen, as it were happening for the last many years with other cloud providers ?

2

must be able to SET ROLE “postgres”

Role management in the dump file is cause of1 the above error. Excluding ownership and ACLs (privileges) from the dump process is the easiest method to handle this kind of errors.

  • --no-owner: This flag prevents commands from trying to modify who owns what in the database. It guarantees that you won’t run into ownership authorization problems when restoring.

  • --no-acl: This parameter prevents privilege mismatches between your local and Azure PostgreSQL environments throughout the dump by skipping instructions related to privileges.

Sample command:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>pg_dump -U postgres -h localhost -p 5432 staging -n public --format=p --no-owner --no-acl > project-io-staging-4-Sep-2024.sql
</code>
<code>pg_dump -U postgres -h localhost -p 5432 staging -n public --format=p --no-owner --no-acl > project-io-staging-4-Sep-2024.sql </code>
pg_dump -U postgres -h localhost -p 5432 staging -n public --format=p --no-owner --no-acl > project-io-staging-4-Sep-2024.sql

Recognized by Microsoft Azure Collective

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật