Blog Post

Installing the Pagila Sample Database on PostgreSQL

The Pagila sample database is a popular PostgreSQL training database modeled after a movie rental store. It includes tables for films, actors, customers, rentals, staff, payments, and more. This makes it perfect for learning PostgreSQL! In this guide, I’ll walk through installing Pagila on a Debian-based GCP VM running PostgreSQL 18. If you don't have a GCP VM setup already, don't worry I got you! Follow this article to get PostgreSQL up and running on GCP Free Tier.

Prerequisites

Before we begin, make sure you have the following setup.

  • A GCP e2-micro VM running Debian
  • PostgreSQL 18 installed
  • SSH access to your VM

Verify PostgreSQL is installed:

psql --version


Download the Pagila SQL Files

Pagila consists of two files - schema and data.

  • pagila-schema.sql – creates tables, sequences, and constraints
  • pagila-data.sql – inserts sample data
cd /tmp
wget https://raw.githubusercontent.com/devrimgunduz/pagila/master/pagila-schema.sql
wget https://raw.githubusercontent.com/devrimgunduz/pagila/master/pagila-data.sql



Verify files downloaded correctly:

ls -l /tmp/pagila*


Create the Pagila Database

Switch to the postgres user:

sudo -i -u postgres

Create the database:

createdb pagila

Verify it was created:

psql -l | grep pagila

Load the Schema and Data

Next, load all tables and constraints:

psql -d pagila -f /tmp/pagila-schema.sql



Insert all sample data:

psql -d pagila -f /tmp/pagila-data.sql


Verify the Installation

Connect to the database:

psql pagila
            

Check the number of films:

SELECT COUNT(*) FROM film;
            

Query some movie titles:

SELECT title, release_year
FROM film
ORDER BY title
LIMIT 10;

Join categories:

SELECT f.title, c.name AS category
FROM film f
JOIN film_category fc ON f.film_id = fc.film_id
JOIN category c ON c.category_id = fc.category_id
ORDER BY f.title
LIMIT 10;


Optional Cleanup

If you want, remove the downloaded files:

rm /tmp/pagila-schema.sql /tmp/pagila-data.sql

Conclusion

You now have the Pagila sample database installed on your PostgreSQL 18 Debian server. With its rich schema and realistic data, Pagila is one of the best datasets for learning PostgreSQL. We'll be using it a lot in future tutorials!