Import PostgreSQL script files

This article explains how to move dump file contents to PostgreSQL server using the most popular tools.

PostgreSQL console client (psql)

Syntax of the command line depends on the structure of the dump file. If the dump file contains 'CREATE DATABASE' statement you should call the tool as follows:

psql -h hostname -U username -f {SQL script file name}

Otherwise:

psql -h hostname -d databasename -U username -f {SQL script file name}

Of course you need to replace parameters in figure brackets {...} by actual values.

phpPgAdmin

To import SQL script file into PostgreSQL database using this tool, take the following steps:

  1. Select the database
  2. Navigate to the "SQL" button
  3. Click the "Choose File" (or "Browse") button and select the SQL file from your computer
  4. Click "Execute" button