- pgx_list_dbs: Lists the names of databases in an .sql file dumped using pg_dumpall.
- pgx_extract_db: Extracts a single database from a sql file dumped with pg_dumpall and outputs its content to stdout.
Download the (re)installer by doing:
sudo wget -O /usr/local/bin/pgx_installer \ https://gist.github.com/runekaagaard/7924963/raw/pgx_installer \ && sudo chmod +x /usr/local/bin/pgx_installer
Then run it with:
pgx_installer
Based on:
http://madssj.com/blog/2010/04/09/extracting-a-single-database-from-a-pg_dumpall-postgresql-dump/
I ran into a new problem: Since some time, pg_dumps may add a
-reuse-previous=on|off
and"dbname='my-database'"
to\connect
statements, e.g.:\connect -reuse-previous=on "dbname='my-database'"
.Notice the surrounding double quotations marks in parameter
"dbname=bla"
. They letpgx_extract_db
's end-of-line match"$db_name$"
indone < <(grep -b '^\\\connect' "$db_file" | grep -m 1 -A 1 "$db_name$")
fail.My woraround is to change line
done < <(grep -b '^\\\connect' "$db_file" | grep -m 1 -A 1 "$db_name$")
to
done < <(grep -b '^\\\connect' "$db_file" | grep -m 1 -A 1 "$db_name")
(notice the removed dollar sign at the end)
For
\connect
statements that use"dbname='my-database'"
, my previous comment becomes invalid. Instead, use the usual statementpgx_extract_db big-dump-file.sql my-database >my-database.sql
(ie., no double quote escapes).