Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restore postgres db from gzip file using psql? (arelle: XBRL SEC DB)

I downloaded the xbrldb_SEC_pg_2014-11-02.pg.gzip postgres pg_dump file from arelle.org. I then ran the schema ddl file in pgAdminIII and it recreated all of the databases, functions, etc.

When I try to restore the databases using the following:

desktop:~/Downloads$ sudo postgres zcat xbrldb_SEC_pg_2014-11-02.pg.gzip | psql -U postgres public

I get:

sudo: postgres: command not found psql: FATAL: Peer authentication failed for user "postgres"

I can zcat the file into a file to expand it. Looks like it is a pg_dump file.

postgres=> pg_restore -a /home/jeremy/Downloads/xbrldb_SEC_pg_2014-11-02.txt
postgres-> ;
ERROR:  syntax error at or near "pg_restore"
LINE 1: pg_restore -a /home/jeremy/Downloads/xbrldb_SEC_pg_2014-11-0...
    ^
postgres=> pg_restore -a postgres /home/jeremy/Downloads/xbrldb_SEC_pg_2014-11-02.txt;
ERROR:  syntax error at or near "pg_restore"
LINE 1: pg_restore -a postgres /home/jeremy/Downloads/xbrldb_SEC_pg_...

So then I tried to use PG Admin III, and my output:

/usr/bin/pg_restore --host localhost --port 5432 --username "postgres" --dbname "public" --role "postgres" --no-password  --section data --data-only --exit-on-error --table accession --schema public --verbose "/home/jeremy/Downloads/xbrldb_SEC_pg_2014-11-02.backup"
pg_restore: [archiver] input file appears to be a text format dump. Please use psql.

Process returned exit code 1.

May I please ask what I need to do to get the databases restored?

Does anyone know what I need to do to get the database updated from 2014-11-02 to the current date?

like image 719
Jeremy Avatar asked Feb 06 '23 03:02

Jeremy


1 Answers

You should run psql as postgres user, not zcat, so try to use following:

zcat xbrldb_SEC_pg_2014-11-02.pg.gzip | sudo -u postgres psql public

PS pg_restore is an utility, not a PostgreSQL command, that means you should run it from command line, not from psql.

like image 189
icuken Avatar answered Apr 27 '23 10:04

icuken