DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • How to Build a Full-Stack App With Next.js, Prisma, Postgres, and Fastify
  • How to Store Text in PostgreSQL: Tips, Tricks, and Traps
  • 5 Key Postgres Advantages Over MySQL
  • FHIR Data Model With Couchbase N1QL

Trending

  • Automating Data Pipelines: Generating PySpark and SQL Jobs With LLMs in Cloudera
  • Measuring the Impact of AI on Software Engineering Productivity
  • How to Convert XLS to XLSX in Java
  • Mastering Advanced Traffic Management in Multi-Cloud Kubernetes: Scaling With Multiple Istio Ingress Gateways
  1. DZone
  2. Data Engineering
  3. Databases
  4. PostgreSQL How-To: Chinook Sample DB on a Distributed SQL Database

PostgreSQL How-To: Chinook Sample DB on a Distributed SQL Database

In this post, see how to download and install the PostgreSQL version of the Chinook sample DB on the YugaByte DB distributed SQL database with a replication factor of 3.

By 
Jimmy Guerrero user avatar
Jimmy Guerrero
·
Aug. 20, 19 · Tutorial
Likes (8)
Comment
Save
Tweet
Share
9.4K Views

Join the DZone community and get the full member experience.

Join For Free

In this post, we are going to walk you through how to download and install the PostgreSQL version of the Chinook sample DB on the YugaByte DB distributed SQL database with a replication factor of 3.

About the Chinook Sample DB

The Chinook data model represents a digital media store, including tables for artists, albums, media tracks, invoices, and customers. Media-related data was created using real data from an iTunes Library. Customer and employee information was created using fictitious names and addresses that can be located on Google maps and other well-formatted data (phone, fax, email, etc.). Sales information was auto-generated using random data for a four year period. The basic characteristics of Chinook include:

  • 11 tables

  • A variety of indexes, primary and foreign key constraints

  • Over 15,000 rows of data

Here’s an ER diagram of the Chinook data model:

Image title

Download and Extract YugaByte DB

$ wget https://downloads.yugabyte.com/yugabyte-1.3.1.0-darwin.tar.gz
$ tar xvfz yugabyte-1.3.1.0-darwin.tar.gz && cd yugabyte-1.3.1.0/

Note: The above instructions are for version 1.3.1. To find the latest version of YugaByte DB, visit the quickstart page.

Configure Loopback Addresses

Add a few loopback IP addresses for the various YugaByte DB nodes to use.

sudo ifconfig lo0 alias 127.0.0.2
sudo ifconfig lo0 alias 127.0.0.3
sudo ifconfig lo0 alias 127.0.0.4
sudo ifconfig lo0 alias 127.0.0.5
sudo ifconfig lo0 alias 127.0.0.6
sudo ifconfig lo0 alias 127.0.0.7

Create a 3 Node Cluster

With the command below, you’ll create a 3 node cluster with a replication factor of 3.

$ ./bin/yb-ctl --rf 3 create

Image title

Check the Status of the YugaByte DB Cluster

Now let’s take a look at the status of the cluster and all the nodes that comprise it.

$ ./bin/yb-ctl status

Image title

As you can see from the output, we have three nodes running locally with a replication factor of 3. This means that every piece of data is being replicated on all three nodes.

Enter the YSQL Shell

Next, run the ysqlsh command to enter the PostgreSQL shell.

$ ./bin/ysqlsh --echo-queries
ysqlsh (11.2)
Type "help" for help.
postgres=#

YSQL is YugaByte DB’s PostgreSQL-compatible, distributed SQL API.

We are now ready to build the Chinook database.

Download and Install the Chinook Database

Download the Chinook Scripts

You can download the Chinook database that is compatible with YugaByte DB from our GitHub repo. The three files are:

  • chinook_ddl.sql which creates tables and constraints

  • chinook_genres_artists_albums.sql which loads artist and album information

  • chinook_songs.sql which loads individual song information

Create the Chinook Database

CREATE DATABASE chinook;

Let’s confirm we have the exercises database by listing out the databases on our cluster.

postgres=# \l

Switch to the chinook database.

postgres=# \c chinook
You are now connected to database "chinook" as user "postgres".
chinook=#

Build the Chinook Tables and Objects

chinook=# \i /Users/yugabyte/chinook_ddl.sql

We can verify that all 11 of our tables have been created by executing:

chinook=# \d

Image title

Load Sample Data into Chinook

Next, let’s load our database with sample data.

chinook=# \i /Users/yugabyte/chinook_genres_artists_albums.sql

and

chinook=# \i /Users/yugabyte/chinook_songs.sql

Do a simple SELECT to pull data from the “Track” table to verify we now have some data to play with.

chinook=# SELECT "Name", "Composer" FROM "Track" LIMIT 10;

Image title

Explore the Chinook Sample DB

That’s it! You are ready to start exploring the Chinook sample database.

If you are looking for a new database administration and SQL development tool, you can check out DBeaver, which is compatible with YugaByte DB.

Image title

Thanks for reading.

Database sql PostgreSQL Data (computing) cluster Relational database Download Data model (GIS) Google Maps

Published at DZone with permission of Jimmy Guerrero. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How to Build a Full-Stack App With Next.js, Prisma, Postgres, and Fastify
  • How to Store Text in PostgreSQL: Tips, Tricks, and Traps
  • 5 Key Postgres Advantages Over MySQL
  • FHIR Data Model With Couchbase N1QL

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!