Database Fundamentals with PostgreSQL / Chapter 1 — Getting PostgreSQL running (lessons 1–3) / Lesson 1

Connecting to PostgreSQL

Time needed: about 5 min (estimate)

☆ Read later

You can try the opening of this lesson without an account.

PostgreSQL has four levels

Have you ever typed USE mydb; and had PostgreSQL refuse it?

PostgreSQL has no USE, and the word "database" does not mean what it means in MySQL.

The structure has four levels: cluster, database, schema, table.

The namespace divider that MySQL calls a database is a schema in PostgreSQL.

A PostgreSQL database is a much heavier unit, and you cannot query across one — SELECT * FROM otherdb.users is not something you can write.

So when you want separate namespaces inside one application, you create schemas rather than more databases.

The equivalent of USE db is \c db, which reconnects — and because it reconnects, any open transaction is lost.

The four levels

PostgreSQL cluster (one group of postgres processes, one port) └── database (school, postgres, template1 ...) ← no queries across these └── schema (public, sandbox ...) ← this is the closest thing to a MySQL database └── table

Connecting

Create a free account to keep reading

With an account you can read the rest of this lesson, take the quiz, and read every free lesson in this course. Lessons you answer correctly are recorded as complete.

Report a problem with this lesson

Log in to send a report.

Keyboard shortcuts

Keys available in a lesson
KeyAction
[ or Alt + ←Go to the previous lesson
] or Alt + →Go to the next lesson
?Open this list
EscClose this list

The keys do not work while the cursor is in a code editor or an input field.