If your PostgreSQL server is not started, start it with the following command.
sudo service postgresql start
To getting started with postgreSQL, open your Terminal, and type:
username$ sudo su - postgres
Now you are logged into your vm with the postgres user. Then connect to template1 database using the postgresql’s psql client:
postgres ~$ psql template1 postgres ~$ template1=#
Note the # symbol, declaring that you are logged to the database as a Super User.
Once you are done and want to disconnect from the database using
\q, and quit from postgres user using
Using Psql client
Let’s see some useful commands of the psql tool. First of all: you can get some help just typing
\?in your psql command line. To exit from the appearing screen, just press the
To load and execute SQL statemens from file, you can use this syntax:
Writing long lines of SQL code in the command line can be really hard to debug. Use the \i to run from file or use:
To edit the input buffer with an editor. If you usually don’t use editor from command line use nano – it’s the simplest. To check what relations your database contains, use
If you want more information about a particular relation, use