Programming/PostgreSQL/Databases

From Dev Wiki
< Programming‎ | PostgreSQL
Revision as of 06:44, 20 November 2020 by Brodriguez (talk | contribs) (Organize page)
Jump to navigation Jump to search
Note: Unless otherwise specified, all commands from this page assume you're in the PostgreSQL shell.

General Commands

Show All Databases

\l

Create a New Database

CREATE DATABASE <database_name>;

Load a Database

\c <database_name>

Delete a Database

Warn: Note that this action cannot be undone.
DROP DATABASE <database_name>;

Set Database Privileges

GRANT ALL PRIVILEGES ON DATABASE <database_name> TO <user_name>;

Database Backups

Export Database to file

pg_dump -U <user_name> -d <database_name> <file_location>

Import Database from File

pg_restore -U <user_name> -d <database_name> <file_location>