PostgreSQL 9.4.1 Documentation | |||
---|---|---|---|
Prev | Up | Chapter 1. Getting Started | Next |
1.4. Accessing a Database
Once you have created a database, you can access it by:
Running thePostgreSQL interactive terminal program, calledpsql, which allows you to interactively enter, edit, and executeSQL commands.
Using an existing graphical frontend tool likepgAdmin or an office suite withODBC orJDBC support to create and manipulate a database. These possibilities are not covered in this tutorial.
Writing a custom application, using one of the several available language bindings. These possibilities are discussed further inPart IV.
You probably want to start uppsql to try the examples in this tutorial. It can be activated for themydb database by typing the command:
$psql mydb
If you do not supply the database name then it will default to your user account name. You already discovered this scheme in the previous section usingcreatedb.
Inpsql, you will be greeted with the following message:
psql (9.4.1)Type "help" for help.mydb=>
The last line could also be:
mydb=#
That would mean you are a database superuser, which is most likely the case if you installedPostgreSQL yourself. Being a superuser means that you are not subject to access controls. For the purposes of this tutorial that is not important.
If you encounter problems startingpsql then go back to the previous section. The diagnostics ofcreatedb andpsql are similar, and if the former worked the latter should work as well.
The last line printed out bypsql is the prompt, and it indicates thatpsql is listening to you and that you can typeSQL queries into a work space maintained bypsql. Try out these commands: Thepsql program has a number of internal commands that are not SQL commands. They begin with the backslash character,"\". For example, you can get help on the syntax of variousPostgreSQLSQL commands by typing: To get out ofpsql, type: andpsql will quit and return you to your command shell. (For more internal commands, type\? at thepsql prompt.) The full capabilities ofpsql are documented inpsql. In this tutorial we will not use these features explicitly, but you can use them yourself when it is helpful.mydb=>SELECT version(); version ----------------------------------------------------------------------- PostgreSQL 9.4.1 on i586-pc-linux-gnu, compiled by GCC 2.96, 32-bit(1 row)mydb=>SELECT current_date; date------------ 2002-08-31(1 row)mydb=>SELECT 2 + 2; ?column?---------- 4(1 row)
mydb=>\h
mydb=>\q
Prev | Home | Next |
Creating a Database | Up | TheSQL Language |