Programming/PostgreSQL/Databases: Difference between revisions
< Programming | PostgreSQL
Jump to navigation
Jump to search
Brodriguez (talk | contribs) m (Correct typo) |
Brodriguez (talk | contribs) (Add a warning) |
||
Line 2: | Line 2: | ||
== General Commands == | == General Commands == | ||
=== | === Create a New Database === | ||
CREATE DATABASE <database_name>; | CREATE DATABASE <database_name>; | ||
=== | === Delete a Database === | ||
{{ warn | Note that this action cannot be undone. }} | |||
DROP DATABASE <database_name>; | DROP DATABASE <database_name>; | ||
Line 11: | Line 12: | ||
\l | \l | ||
=== Load Database === | === Load a Database === | ||
\c <database_name> | \c <database_name> | ||
Revision as of 06:41, 20 November 2020
Note: Unless otherwise specified, all commands from this page assume you're in the PostgreSQL shell.
General Commands
Create a New Database
CREATE DATABASE <database_name>;
Delete a Database
Warn: Note that this action cannot be undone.
DROP DATABASE <database_name>;
Show All Databases
\l
Load a Database
\c <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>