Sunday, November 14, 2021

How to backup database object definitions in PostgreSQL database?

 Sometimes, you want to backup only database object definitions, not the data This is helpful in the testing phase, which you do not want to move test data to the live system.


To back up objects in all databases, including roles, tablespaces, databases, schemas, tables, indexes, triggers, functions, constraints, views, ownerships, and privileges, you use the following command:


pg_dumpall --schema-only > c:\pgdump\definitiononly.sql

Code language: CSS (css)

If you want to back up role definition only, use the following command:


pg_dumpall --roles-only > c:\pgdump\allroles.sql

Code language: CSS (css)

If you want to backup tablespaces definition, use the following command:


pg_dumpall --tablespaces-only > c:\pgdump\allroles.sql

Code language: CSS (css)

Further Reading

No comments:

Post a Comment