Skip to content

Instantly share code, notes, and snippets.

@sepastian
Last active December 20, 2015 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sepastian/6061580 to your computer and use it in GitHub Desktop.
Save sepastian/6061580 to your computer and use it in GitHub Desktop.
Restore a binary dump in PostgreSQL.
# In /etc/postgresql/9.1/main/pg_hba.conf, change
#
# local all all peer
#
# to
#
# local all all md5
#
# and restart the Postgres server:
$ sudo service postgresql restart
# Become psql to create a user/database
$ sudo -i
$ su - postgres
# Create a database user and a database.
# The database user will be the owner of the database.
# createuser will ask for a password for the new user.
$ createuser -D -P DB_USER_NAME
$ createdb -O DB_USER_NAME DATABASE_NAME
# Try logging into the new database.
$ psql -U DB_USER_NAME -d DATABASE_NAME
# Logout.
# As a normal user, use pg_restore to import the datadump.
pg_restore -U DB_USER_NAME -d DATABASE_NAME PATH_TO_DUMP_FILE
# Login again and list the tables restored.
psql -U DB_USER_NAME -d DATABASE_NAME
DATABASE_NAME=> \d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment