Say I've created a database in pgAdmin, but I want to export a CREATE sql file.

How would I go about generating the dump?

up vote 44 down vote accepted

To generate a sql script that will create the tables as they exist in a given database do:

pg_dump --schema-only --no-owner the_database > create_the_tables.sql

This will give you a bunch of create table statements. Just to see how portable it was I tried the above as follows:

bvm$ pg_dump -s --no-owner devdb | sqlite3 so_ans.db

And then:

bvm$ sqlite3 so_ans.db .schema
CREATE TABLE courses (
    id integer NOT NULL,
    name text,
    created_by integer,
    jc text
);

Kind of cool.

  • 1
    Does this output all objects, triggers, procedures, etc? – raffian Jan 6 '14 at 20:15
  • 1
    "pg_dump -U postgres --schema-only --no-owner documents > create_the_tables.sql", if the user is postgres and you are using Windows OS. Otherwise, it would use your Windows user account name by default. – Peeter Kokk Nov 22 '15 at 10:44
  • 2
    The question was how to use pgAdmin not pg_dump. – Farrukh Najmi Sep 29 '16 at 13:02

Here's how to use pgAdmin to create a schema script that can be used with a PostgreSql database schema comparison tool such as apgdiff. These instructions are for pgAdmin3.

  1. In pgAdmin, right click on the database and click Backup.
  2. Enter an appropriate path and filename (i.e. /some/path/my_script.sql).
  3. Select Plain as the format in the format dropdown.
  4. Go to the Dump Options #1 tab and check "Only schema".
  5. Then click Backup. Then click Done.

Note: Yes, I realize that pgAdmin uses pg_dump behind the scenes to create the script, but the question was about pgAdmin, so this is the GUI method.

  • Is this up to date? There's no backup option in the context menu when right clicking on a database. There's a backup option in the tools menu, but it's always disabled no mater what I have selected (database, schema, individual tables, etc). This is with pgAdmin 1.18.1 on Linux. – Kat Feb 1 '15 at 22:35
  • It turns out I just had to specify the Postgres binary path (where pg_dump is). This is done in the options of pgAdmin (File > Options > Binary paths and set the PG bin path). This is likely because I did not have a standalone Postgres client installed at the time that I installed pgAdmin. – Kat Feb 1 '15 at 22:44
  • This should have been the accepted answer, Two years after the NON pgadmin given.. So you get my upvote as its the valid answer for the OP's question – Mayhem Nov 17 '15 at 0:32
  • 3
    Three years later, still helpful – Kesem David Sep 17 '16 at 17:22
  • 4 years and counting. – lucid_dreamer Aug 28 '17 at 13:22

pgAdmin however does have a facility to do what you want:

Right-click on the database you want to export

Select Backup from the pop-up menu

Choose "format" Plain.

Choose "plain option" Only schema

You can achieve this through phpPgAdmin just like phpMyAdmin for MySQL.

Login to phpPgAdmin select the database and then choose export.

At least in PgAdmin III 1.22.1 you can get CREATE script doing: 1) right-click on table name 2) "Scripts" -> "CREATE script" There are options to get SELECT, DELETE etc.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.