PostgreSQL Server

From Notepedia
Jump to: navigation, search
Logging into PostgreSQL server client
$ psql -U username -d database (-W to prompt password)
Password for user username:
psql (9.4.4)
Type "help" for help.

database=#
Basic show commands
\l - List databases
\d - List tables, views, and sequences. Same as describe.
\c - Connect {[DBNAME|- USER|- HOST|- PORT|-] | conninfo}
\? - List help
Create Database
database=# CREATE DATABASE jira WITH ENCODING 'UNICODE' LC_COLLATE 'C' LC_CTYPE 'C' TEMPLATE template0 OWNER user_name;

Create PostgreSQL dump

# pg_dump db_name > db_backup_file.bak
Restore PostgreSQL dump
# pg_dump db_name < db_backup_file.bak