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

1

5

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?

Elemental answered 16/9, 2016 at 15:18 Comment(0)
C
13

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.

Cherlynchernow answered 17/9, 2016 at 12:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.