Database Fundamentals with PostgreSQL / Chapter 1 — Getting PostgreSQL running (lessons 1–3) / Lesson 1
Connecting to PostgreSQL
Time needed: about 5 min (estimate)
Reading settings
These settings are remembered on this device only.
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
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.