Notes of PostgreSQL operations and Shell commands

08 Mar 2021

Sometimes, commands will slip out the brain, and it is always good to have a place to look up these commands.

PostgreSql


Start postgresql server

$ pg_ctl start -l YOUR_INSTALL_DIRECTORY/log

Stop postgresql server

$ pg_ctl stop

Check current status of server (is there any server running?)

$ pg_ctl status

Create database

$ createdb DATABASE_NAME

Drop database

$ dropdb DATABASE_NAME

Show a list of your database

$ psql -l

Get inside YOUR_DATABASE

$ psql YOUR_DATABASE

Inside database YOUR_DATABASE

YOUR_DATABASE=# \d
# ...show a list of relations in YOUR_DATABASE

YOUR_DATABASE=# \d+
# ...show a list of relations in YOUR_DATABASE with more details

YOUR_DATABASE=# \df
# ...show a list of functions in YOUR_DATABASE ('+' syntax also applies)

YOUR_DATABASE=# \x
# ...show infomation with extended mode

YOUR_DATABASE=# \do
# ...show a list of operations in YOUR_DATABASE ('+' syntax also applies)

YOUR_DATABASE=# \q
# ...quit your YOUR_DATABASE

For more information about PostgreSql, check PostgreSQL’s Documentation.

Shell commands


definitions of commands come from “BSD General Commands Manual”

echo : write arguments to the standard output

$ echo "hello"
# hello

cat : concatenate and print files

$ echo "hello" > file
$ cat file
# hello

touch : change file access and modification times

$ touch file1
$ touch file2
$ touch file3
# or 
$ touch file1 file2 file3

ls : list directory contents

$ ls
# file1 file2 file3

If you want to learn more about shell commands, check out the following links.