psql -U <username>
: login using console (Windows)
'CREATE DATABASE <db_name>;
: create database
SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name='<your_table_name>' ORDER BY column_name ASC;
: list all table columns in alphabetical(sorted) order
\c
: Connect to database
\l
: List database
\d+
: Show detailed list of all tables
\dt
: Show list of all tables in a selected database
\d
: List all tables in a database (almost similar output as \dt)
\du
: List all users
CREATE USER <user_name> WITH PASSWORD '<user_password>';
: Create user with password
GRANT ALL PRIVILEGES ON DATABASE <db_name> to <user_name>;
: Grant all privileges of a database to a user
createuser -s <user_name>
: Creates a superuser(shell command)
alter table <table_name> rename to <new_table_name>
: Rename table
alter database <db_name> rename to <new_db_name>
: Rename database
alter database <db_name> owner to <new_user_name>
: Change database owner
ALTER USER <user_name> WITH PASSWORD '<new_password>';
: Change password of a user. Ordinary users can only change their own password.
createdb <db_name> -U <username>
does not work. createdb -U <username> <db_name>
works!