Extract Database Postgres
    • 11 Apr 2023
    • 1 Minute to read
    • Contributors
    • Dark
      Light

    Extract Database Postgres

    • Dark
      Light

    Article summary

    Postgres

    How to export Postgres data to a SQL script

    pg_dump -U your_username -d your_database_name --schema-only --table=your_table_name --column-inserts --file=/path/to/output/file.sql
    
    

    Here's what each option does:

    • -U your_username: specifies the username to use when connecting to the database.
    • -d your_database_name: specifies the name of the database to connect to.
    • --schema-only: dumps only the schema (tables, views, sequences, indexes, etc.) and not the data.
    • --table=your_table_name: specifies the name of the table to dump. If you omit this option, all tables in the schema will be dumped.
    • --column-inserts: generates INSERT statements that include column names, which can be useful for debugging.
    • --file=/path/to/output/file.sql: specifies the name and path of the output file.

    When you run this command, it will generate a SQL script that creates the schema and tables, along with their columns, in the output file.

    Note that this command only extracts the schema and table structures, not the data. If you want to include the data as well, you can omit the --schema-only option. However, be careful when importing the data as it may overwrite existing data in the target database.


    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.