Skip to content

Instantly share code, notes, and snippets.

@fodra
Last active June 20, 2018 07:42
Show Gist options
  • Save fodra/56f1f85371a8cb3415ec200ca27d2429 to your computer and use it in GitHub Desktop.
Save fodra/56f1f85371a8cb3415ec200ca27d2429 to your computer and use it in GitHub Desktop.
Notes on postgres database
  1. Create a copy of a database

$ createdb -O <owner> -T database_to_copy new_database

  1. Create a database

$ createdb -O <owner> database_name

  1. Grant privileges to user on database

$ psql <db_name> -U <user>

# GRANT ALL PRIVILEGES ON DATABASE <db_name> TO <user>;

  1. Delete a database

dropdb <dbname>

  1. Load database from a backup. Just like the linux pipe

psql <dbname> < infile

  1. Create a backup of the database.

pg_dump <dbname> > outfile

Great Article

https://www.codementor.io/engineerapart/getting-started-with-postgresql-on-mac-osx-are8jcopb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment