psql --username=<db_user_name> databasename < data_base_dump

That's the command you are looking for.

Beware: databasename must be created before importing. Have a look at the PostgreSQL Docs Chapter 23. Backup and Restore.

Answer from Jacob on Stack Overflow
🌐
Neon
neon.com › postgresql › postgresql-getting-started › load-postgresql-sample-database
Load PostgreSQL Sample Database
First, connect to the PostgreSQL database server using psql or pgAdmin. Second, create a blank database called dvdrental. Third, load data from the sample database file into the dvdrental database using pg_restore.
🌐
Crunchy Data Blog
crunchydata.com › blog › data-loading-in-postgres-for-newbies
Data Loading in Postgres for Newbies | Crunchy Data Blog
November 1, 2022 - To import data into Postgres, you create a new server resource, connect your resource, create a database, and use the csv import tool and the table creations and columns are created for you.
🌐
TutorialsPoint
tutorialspoint.com › postgresql › postgresql_loading_database.htm
PostgreSQL - LOAD DATABASE
If you want to load the database with external sources, use the COPY command. COPY table_name FROM '/path/to/file.csv' DELIMITER ',' CSV HEADER; ... DELIMITER ',' specifies that values are comma-separated. CSV HEADER indicates that the first row contains column names. pgAdmin is a free opens−source tool that helps users to manage PostgreSQL and other relational databases.
🌐
GeeksforGeeks
geeksforgeeks.org › postgresql-loading-a-database
PostgreSQL - Loading a Database - GeeksforGeeks
September 20, 2021 - Step 2: Load the database file by creating a folder at your desired location(say, c:\users\sample_database\dvdrental.tar). Now open up command prompt and Navigate to the bin folder of the PostgreSQL installation folder as below:
🌐
EnterpriseDB
enterprisedb.com › postgres-tutorials › how-load-sample-database-schemas-and-data-postgresql
How to load a sample database with schemas and data in PostgreSQL | EDB
March 3, 2020 - The dumps taken by pg_dump are totally consistent, because the dump is a snapshot of your database and its data at the time when the pg_dump begins running. ... <PG_BIN>/pg_dump --help [postgres@localhost bin]$ pwd /usr/pgsql-12/bin [postgres@localhost bin]$ ./pg_dump --version pg_dump (PostgreSQL) 12.2
🌐
GeeksforGeeks
geeksforgeeks.org › postgresql › postgresql-loading-a-database
Loading a Database in PostgreSQL - GeeksforGeeks
1 month ago - Copy the dvdrental.tar file to your system, open Command Prompt and navigate to the PostgreSQL bin directory. Then use the pg_restore command to import the database into dvdrental. Use the pg_restore command to load the backup file into the dvdrental database:
Find elsewhere
🌐
PostgreSQL
postgresql.org › docs › current › sql-load.html
PostgreSQL: Documentation: 18: LOAD
May 14, 2026 - Non-superusers can only apply LOAD ... responsibility to ensure that only “safe” libraries are installed there.) LOAD is a PostgreSQL extension....
🌐
Topcoder
topcoder.com › thrive › articles › how-to-load-a-sample-database-in-postgresql
HOW TO LOAD A SAMPLE DATABASE IN POSTGRESQL
Fire up the Postgresql database on the computer and right-click on Servers then Databases in the Postgres interface like in the image above. This brings up an option to “Create” or “Refresh” the database.
🌐
PostgreSQL
postgresql.org › docs › current › populate.html
PostgreSQL: Documentation: 18: 14.4. Populating a Database
May 14, 2026 - If multiple CPUs are available in the database server, consider using pg_restore's --jobs option. This allows concurrent data loading and index creation.
🌐
Postgis
postgis.us › presentations › PGOpen2018_data_loading.pdf pdf
1 10 WAYS TO LOAD DATA INTO 10 WAYS TO LOAD DATA INTO POSTGRES POSTGRES
DB2ODBC -raster,vector- (rw+): IBM DB2 Spatial Database · ESRI Shapefile -vector- (rw+v): ESRI Shapefile · MapInfo File -vector- (rw+v): MapInfo File · UK .NTF -vector- (ro): UK .NTF · OGR_SDTS -vector- (ro): SDTS · S57 -vector- (rw+v): IHO S-57 (ENC) DGN -vector- (rw+): Microstation DGN · OGR_VRT -vector- (rov): VRT - Virtual Datasource · REC -vector- (ro): EPIInfo .REC · Memory -vector- (rw+): Memory · BNA -vector- (rw+v): Atlas BNA · 14 . 2 · OGR2OGR LOAD DATA INTO POSTGRESQL ·
🌐
Tutorials
onlinetutorialhub.com › home › postgresql › what are the loading database in postgresql
What Are The Loading Database In PostgreSQL
August 25, 2025 - PostgreSQL database loading involves restoring data from a backup or importing data into tables.
🌐
Reddit
reddit.com › r/postgresql › how to load a database file?
r/PostgreSQL on Reddit: How to load a database file?
July 6, 2024 -

I'm using postgresql in linux mint and trying to load an sql file to work with.

When I use

psql --set ON_ERROR_STOP=on demo < /home/masteruser/Downloads/demosmall.sql

I get the error

psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: role "masteruser" does not exist

When I create the role of 'masteruser' with psql and try to run the command again it gives me

SET

SET

SET

SET

SET

SET

SET

SET

ERROR: cannot drop the currently open database

I heard a suggestion that I need to alter the pg_hba.conf but when I try to the system won't allow me because I don't have permission since its in the postgres group.

🌐
PostgreSQL
postgresql.org › docs › 8.1 › backup.html
PostgreSQL: Documentation: 8.1: Backup and Restore
January 1, 2012 - This means that any languages, ... are using a customized template1, you must create the empty database from template0, as in the example above. For advice on how to load large amounts of data into PostgreSQL efficiently, refer to Section 13.4....
🌐
Estuary
estuary.dev › blog › loading-data-into-postgresql
How to Load Data into PostgreSQL: 3 Easy Methods + Best ETL Tools
April 22, 2026 - Learn how to load data into PostgreSQL using Estuary, COPY command, and pgAdmin. Compare the top PostgreSQL ETL tools, best practices, and real-time integration options. Jeffrey Richman Data Engineering & Growth Specialist ... PostgreSQL is a popular database management system because of its practical functionalities, advanced data querying capabilities, and easy integration into enterprise workflows.
🌐
Prisma
prisma.io › dataguide › postgresql › inserting-and-modifying-data › importing-and-exporting-data-in-postgresql
How to Import & Export Data with a PostgreSQL Database | Prisma
To create the database DB_NAME beforehand, you can use the template0 (which creates a plain user database that doesn't contain any site-local additions): ... Exporting data from PostgreSQL and ingesting it again to recreate your data structures and populate databases is a good way to migrate data, back up and recover, or prepare for replication.
🌐
Rockdata
rockdata.net › tutorial › load-sample-database
PostgreSQL Tutorial: Load PostgreSQL Sample Database - Redrock Postgres
The -U postgres specifies the postgresuser to login to the PostgreSQL database server. The -d dvdrental specifies the target database to load.
🌐
PostgreSQL
postgresql.org › docs › 17 › sql-load.html
PostgreSQL: Documentation: 17: LOAD
February 26, 2026 - February 26, 2026: PostgreSQL 18.3, 17.9, 16.13, 15.17, and 14.22 Released! ... Unsupported versions: 13 / 12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 / 8.2 / 8.1 / 8.0 / 7.4 / 7.3 / 7.2 / 7.1 ... This command loads a shared library file into the PostgreSQL server's address space.
🌐
RackNerd
blog.racknerd.com › home › how to import your database into a postgresql server
How to Import Your Database into a PostgreSQL Server — RackNerd
February 18, 2025 - First, access the PostgreSQL command line: ... To create a new database, use the CREATE DATABASE command.
🌐
PostgreSQL
postgresql.org › docs › 11 › sql-load.html
PostgreSQL: Documentation: 11: LOAD
November 9, 2023 - Non-superusers can only apply LOAD ... responsibility to ensure that only “safe” libraries are installed there.) LOAD is a PostgreSQL extension....