PostgreSQL – Running out of memory when restoring database from large dump

I have a Postgres database dump in text format, which is roughly 20GB. I am trying to restore the database using the command

$   psql DatabaseName < path-to-dump 

But after I while I get the message out of memory and it stops. Is there something I can do to overcome this problem?

Note that I am running it in Ubuntu 20.04. My version of postgres is

$   /usr/lib/postgresql/12/bin/postgres -V output: postgres (PostgreSQL) 12.8 (Ubuntu 12.8-0ubuntu0.20.04.1) 

The dump has the following 2 lines in the beginning, regarding its version:

-- Dumped from database version 12.5 -- Dumped by pg_dump version 13.1 (Ubuntu 13.1-1.pgdg20.04+1)