Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backup of PostgreSQL database design - without data

I have tried to find a way to backup my database design without including the data stored in the database. Actually, one might say that I want to have a file that holds all "CREATE Scripts" in the database. Ideally, this file could be used to recreate the database (with no data of course).

How to avoid data in a database backup?

I am using pgAdmin 4.1.3 and PostgreSQL 9.6.

like image 560
Helge Avatar asked Apr 05 '17 10:04

Helge


People also ask

How do I backup a PostgreSQL database?

To back up, a PostgreSQL database, start by logging into your database server, then switch to the Postgres user account, and run pg_dump as follows (replace tecmintdb with the name of the database you want to backup). By default, the output format is a plain-text SQL script file.

What are different approaches to backing up PostgreSQL data?

There are three fundamentally different approaches to backing up PostgreSQL data: SQL dump. File system level backup. Continuous archiving.

How do I backup a schema?

Run the db_backup command to back up an entire database, or just a schema. In addition to restoring data by using the db_restore command, you can use the web console for data restore. Run the db_restore command to restore a database, a schema, or a table that was backed up using the db_backup command.

How do you backup a schema in PostgreSQL pgAdmin?

You can backup a single table, a schema, or a complete database. Select the name of the backup source in the pgAdmin tree control, right click to open the context menu, and select Backup… to open the Backup dialog. The name of the object selected will appear in the dialog title bar.


2 Answers

You can use this from psql(terminal):

pg_dump -s databasename > file.dump 

from pg_dump documentation the "-s" dump only the object definitions (schema), not data.

pg_dump documentation

like image 72
z44.nelther Avatar answered Oct 16 '22 07:10

z44.nelther


pg_dump --host localhost --port 5432 --username "userName" --schema-only --verbose --file "file path" "db_dev_local" 
like image 28
Md Ayub Ali Sarker Avatar answered Oct 16 '22 06:10

Md Ayub Ali Sarker