PostgreSQL
Introduction
PostgreSQL is a powerful, open source object-relational database system.
If you don’t know how an SQL database works, start with the activities in Sqlite.
Docker
Start a Linux virtual machine with Windows Subsystem for Linux (WSL).
Install docker as explained in Docker.
Create a new container running postgres:
psql
psql is a shell for PostgreSQL that lets you write queries interactively, send them to PostgreSQL, and view the results.
Create a new terminal session in the container:
Start a session with the user postgres:
A Postgres server can manage several databases at the same time.
Use the command \l (or \list) to see all databases defined on the server,
postgres=# \l
List of databases
Name | Owner | Encoding | Locale Provider | Collate | Ctype | Locale | ICU Rules | Access privileges
-----------+----------+----------+-----------------+---------+-------+--------+-----------+-----------------------
postgres | postgres | UTF8 | libc | C | en | | |
template0 | postgres | UTF8 | libc | C | en | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | libc | C | en | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
(3 rows)postgres is the default database you connect to.
Create a database named test:
;CREATE DATABASEConnect to the test database:
\c testYou are now connected to database "test" as user "postgres".
test=>With \dt you can see which tables the database has:
\dDid not find any relations.At any time you can “clear” the shell with \! cls:
postgres=# \! clsUse \q to end the session:
test=# \q
$Scott
Scott is a demo database Scott.
Import the database “Scott” to the container:
| In the activity Scott you have many example queries for the Scott database.
Datagrip
You can use DataGrip to manage the database.
pgAdmin
Install pgAdmin:
Open the pgAdmin web page at http://localhost.
If you haven’t changed the default settings, the user is postgres@mail.com and the password is password.