Local Server
You'll install PostgreSQL on your own machine, make a database and a user, load data with COPY, and connect from a second program, which is the moment a database stops being a file.
About
SQLite is a single file on your disk, and PostgreSQL is a program that stays running and lets more than one person or program talk to it at once, with users, permissions and a log. It's what most websites and companies run on, it's free, it installs in ten minutes on a Mac, Linux or Windows laptop (Postgres.app, apt, or the official installer), and nothing about it needs a machine in a data center. This badge is your first weekend with it: a role and a database, a real table loaded with COPY, and two different clients connected, so you see that the database is a thing on the network rather than a window. MariaDB works for this too if you'd rather. Leave it listening on localhost only, because opening a database to the internet is a different skill and belongs further up. What counts is a server you installed and a table you loaded into it, with the connections shown.
At a glance
- Per requirement
- 25 XP
- Completion bonus
- 150 XP
- Requirements
- 6
- Takes
- A weekend
- Skill level
- Beginner (done it a few times)
- Cost
- Free
- Supplies
- Nothing special
- Where
- At home
- Other people
- On your own
Requirements
-
1
Install PostgreSQL, start it, and connect with psql as the admin user. On a Mac, Postgres.app is one download; on Ubuntu it's sudo apt install postgresql; on Windows it's the installer from postgresql.org. Then psql -U postgres (or just psql on a Mac) and SELECT version();. If psql says the server isn't running, it usually isn't, and the service command or the app's start button fixes it. Take a screenshot of the version query. Photo
-
2
Create a database and a user that owns it, then connect as that user. CREATE USER me WITH PASSWORD '...'; then CREATE DATABASE practice OWNER me; then \q and psql -U me -d practice. Working as the superuser all the time is the habit to break on day one, because the superuser can't be told no. Take a screenshot of the prompt showing the new user and database. Photo
-
3
Load a CSV of at least 10,000 rows with COPY and time it. Create the table with real types first (DATE, INTEGER, NUMERIC, TEXT), then \copy trips FROM 'trips.csv' WITH (FORMAT csv, HEADER). Turn on \timing to see the milliseconds. If one row is bad, Postgres refuses the whole file and tells you the line, which is stricter than SQLite and worth getting used to. Take a screenshot of the COPY result with the row count and the time. Photo
-
4
Connect from a second client and run the same query in both. DB Browser doesn't speak Postgres, so use DBeaver (free), pgAdmin, a ten-line Python script with psycopg, or a spreadsheet's database connector. Take a screenshot of the same query and result in psql and in the second client, side by side, or film switching between them. Photo or video
-
5
Make a read-only user and show it being refused a DELETE. CREATE USER reader WITH PASSWORD '...'; then GRANT CONNECT ON DATABASE practice TO reader; and GRANT SELECT ON ALL TABLES IN SCHEMA public TO reader; then connect as reader and try DELETE FROM trips. 'permission denied' is the result you want. Take a screenshot of the error. Photo
-
6
Find the server log and read the last twenty lines. SHOW data_directory; and SHOW log_directory; tell you where it lives, an apt install on Ubuntu writes it to /var/log/postgresql, and Postgres.app and pgAdmin both have a way to open it from a menu. Every connection, error and slow query from this weekend is in there, and knowing where the log is amounts to half of fixing anything later. Take a screenshot of the log with your own permission denied error from the previous step in it. Photo