Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Frequently Used PostgreSQL commands

Kaiyu edited this page Feb 13, 2017 · 1 revision

Several frequently used PostgreSQL command:

  1. Change user to postgres with
$ sudo su - postgres
  1. Start PostgreSQL client with
$ psql -d DB_NAME -U USER_NAME
  1. quit psql
postgres=# \q
  1. show database users
postgres=# \du
  1. show data_directory
postgres=# SHOW data_directory ;
  1. list all databases
postgres=# \l
  1. change user password
postgres=# ALTER USER username WITH password '123123' ;
  1. change user attributes (like SUPERUSER)
postgres=# ALTER USER username WITH SUPERUSER
postgres=# ALTER USER username WITH CREATEDB ;
  1. switch between databases
       postgres=# \connect DBNAME 
  1. describe table:
       postgres=# \d+ TABLENAME