About the use of PostgreSQL
Platform: Ubuntu 12.04 & 14.04
Version: PostgreSQL 9.3.4
PostgreSQL installation
See website installation process
Add user
After initial installation, a database named Postgres and a database user named Postgres are generated by default. It is important to note that a Linux system user named Postgres is also generated.
Of course, other users can also be generated.
Start using
Switch to Postgres user login
$ sudo su-postgres
PostgreSQL built-in commands
PostgreSQL comes with two system commands: createuser
with createdb
, you can create users and databases with these two commands, respectively.
Using the Psql command
$ psql db_name
The PostgreSQL console can be accessed via the above command, as in MySQL.
Interface such as: db_name:#
Simple use of commands
- To list all databases:
\l
- List all the tables:
\d
- Exit:
\q
- Help:
\?
- Execute the SQL command, directly typing the command execution (note the last face plus
;
).
Miscellanies The PostgreSQL command line uses