Chapter 2 — Quiz

13 questions. Answers and explanations at the bottom.


Multiple choice

Q1. PostgreSQL's architecture is best described as: - A) A single file you open and edit - B) A client/server system — a server owns the data, clients connect to it - C) A spreadsheet engine - D) A web browser plugin

Q2. What is psql? - A) The PostgreSQL server process - B) The official command-line client for PostgreSQL - C) A graphical database designer - D) A backup format

Q3. Which character ends a SQL statement and tells psql to run it? - A) A period . - B) A newline - C) A semicolon ; - D) A backslash \

Q4. Meta-commands in psql start with: - A) / - B) \ - C) # - D) --

Q5. Which meta-command lists the tables in the current database? - A) \l - B) \dt - C) \c - D) \du

Q6. The default TCP port PostgreSQL listens on is: - A) 80 - B) 3306 - C) 5432 - D) 8080

Q7. You want to load schema.sql from inside a psql session. You use: - A) \i schema.sql - B) RUN schema.sql - C) IMPORT schema.sql - D) \load schema.sql

Q8. Which file should you load to make the book's printed query results match your screen exactly? - A) generate_data.sql - B) schema.sql - C) seed-sample.sql - D) book.toml

Q9. Your prompt shows postgres=# and you run CREATE TABLE members (...). Where does the table go? - A) Into the mercado database - B) Into the postgres database - C) Into every database - D) Nowhere — it errors

Q10. \d customers shows you: - A) The data in the customers table - B) The structure of the customers table (columns, types, keys, constraints) - C) A backup of the table - D) A list of databases


True/False

Q11. Running generate_data.sql is required before you can do the exercises in Chapter 5. (True / False)

Q12. A graphical client like pgAdmin connects to the same server, using the same host/port/database/user as psql. (True / False)


Short answer

Q13. You type a SELECT statement, press Enter, and the prompt changes to mercado-# but no results appear. What happened, and how do you fix it?

---

Answer key

Q1 — B. Client/server: a server process owns the data and listens for connections; clients (psql, GUIs, your app) connect and exchange SQL for rows.

Q2 — B. psql is the official command-line client. The server is the separate postgres process.

Q3 — C. The semicolon. Forgetting it is the most common beginner stumble (see Q13).

Q4 — B. Backslash. \dt, \c, \q, etc. are client conveniences, not SQL.

Q5 — B. \dt (describe tables). \l lists databases; \c connects; \du lists roles.

Q6 — C. 5432. (3306 is MySQL; 80/8080 are web ports.)

Q7 — A. \i path/to/file.sql includes and runs a SQL file. Paths are relative to where you launched psql.

Q8 — C. seed-sample.sql is the small, deterministic dataset, so results are reproducible. generate_data.sql uses random().

Q9 — B. It goes into whatever database the prompt names — here postgres, not mercado. Always check the prompt before running DDL; \c mercado puts you in the right place.

Q10 — B. \d <table> describes structure (columns, types, nullability, keys, indexes, constraints). To see data, you SELECT.

Q11 — False. The exercises through Chapter 22 use the small seed-sample.sql. You load the large generate_data.sql only for the performance chapters (23–25).

Q12 — True. A GUI needs the same four connection facts (host, port, database, user/password) and talks to the identical server.

Q13. You forgot the closing semicolon, so psql is waiting for the rest of the statement (the -# prompt means "continuation"). Type ; and press Enter to run it, or press Ctrl+C to cancel the half-typed statement.

Scoring: 11–13 you're set up and fluent; 8–10 re-skim the psql meta-command table; below 8, re-run the chapter's hands-on steps before continuing.